Making a wheel of fortune type of game in c#. Your wheel of fortune program must
ID: 3760729 • Letter: M
Question
Making a wheel of fortune type of game in c#.
Your wheel of fortune program must contain all of the following: The program will display a lopping splash screen; The screen must contain some form of animation or motion and the program will then ask for the user's name.
The program will randomly pick a secret word from a word list. The word list will be: constructor, delegate, inheritance, and object. The program will display a "_" for each letter in the secret word. (Example: object = _____).
The program will allow the user to spin to see how many points a letter is worth. Users will be limited to 7 incorrect spins per game. The wheel contains: 200, 200, 250, 250, 300, 300, 400, 500, 500, 700, 800, 800, 1000, Lose Turn, Free Spin, Bankrupt. This amount will be added to the total for each matching letter in the word.
Explanation / Answer
#include<ctime>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include<cstring>
using namespace std;
//Function Prototypes
private void initialize_arrays(string phrase, string puzzle)
{
int count;
ifstream inFile = new ifstream();
string userInput;
//Error test loop
Console.Write("Please enter a file name you wish to open ->");
userInput = ConsoleInput.ReadToWhiteSpace(true);
inFile.open(userInput);
while (inFile == null)
{
inFile.clear();
Console.Write("Please enter a valid file name->");
userInput = ConsoleInput.ReadToWhiteSpace(true);
inFile.open(userInput);
}
Console.Write("Here is your phrase: ");
Console.Write(" ");
//Loop to store phrase into array
getline(inFile, phrase);
for (count = 0; phrase.Length > count; count++)
{
puzzle = puzzle.Insert(count, STAR);
}
Console.Write(puzzle);
Console.Write(" ");
Console.Write(" ");
inFile.clear();
inFile.close();
}
//Global Constants
private const string STAR = "*";
private const int MAX = 14;
private const int PHRASE_SIZE = 81;
private const int NUM_PLAYERS = 3;
private const int VOWEL_COST = 250;
private const int BANKRUPT = 0;
private const int LOSE_TURN = -1;
private const int WHEEL_SIZE = 15;
private readonly int[] WHEEL = {50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 1000, 1500, 2500, BANKRUPT, LOSE_TURN};
static int Main()
{
//Declaring variables
bool notSolved = false;
string puzzle;
string phrase;
int player = 0;
int currentPlayer = 0;
int[] score = {0, 0, 0};
//Function call to open a data file that contains the phrase
initialize_arrays(phrase, puzzle);
//Function call to initialize the player's turn
do
{
player = currentPlayer + 1;
player = currentPlayer % 3;
} while (notSolved);
{
player_turn(player, score, phrase, puzzle);
}
return 0;
}
internal static class ConsoleInput
{
private static bool goodLastRead = false;
internal static bool LastReadWasGood
{
get
{
return goodLastRead;
}
}
internal static string ReadToWhiteSpace(bool skipLeadingWhiteSpace)
{
string input = "";
char nextChar;
while (char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
//accumulate leading white space if skipLeadingWhiteSpace is false:
if (!skipLeadingWhiteSpace)
input += nextChar;
}
//the first non white space character:
input += nextChar;
//accumulate characters until white space is reached:
while (!char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
input += nextChar;
}
goodLastRead = input.Length > 0;
return input;
}
internal static string ScanfRead(string unwantedSequence = null, int maxFieldLength = -1)
{
string input = "";
char nextChar;
if (unwantedSequence != null)
{
nextChar = '';
for (int charIndex = 0; charIndex < unwantedSequence.Length; charIndex++)
{
if (char.IsWhiteSpace(unwantedSequence[charIndex]))
{
//ignore all subsequent white space:
while (char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
}
}
else
{
nextChar = (char)System.Console.Read();
if (nextChar != unwantedSequence[charIndex])
return null;
}
}
input = nextChar.ToString();
if (maxFieldLength == 1)
return input;
}
while (!char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
input += nextChar;
if (maxFieldLength == input.Length)
return input;
}
return input;
}
}//Function to print the file's heading
private void printHeading()
{
Console.Write("Welcome to Wheel of Fortune!");
Console.Write(" ");
}
//Function that generates what the wheel spin's value will be
private int spin_wheel()
{
int spin;
int luckyNumbers;
uint seed = time(0);
RandomNumbers.Seed(seed);
spin = RandomNumbers.NextNumber() % 14;
Console.Write(WHEEL[spin]);
Console.Write(" ");
Console.Write(" ");
luckyNumbers = WHEEL[spin];
return (luckyNumbers);
}
//Function that prints the phrase array after the puzzle has been solved
private void print_puzzle(string phrase)
{
Console.Write("CONGRATULATIONS! You've solved the puzzle:");
Console.Write(phrase);
Console.Write(" ");
}
//Function that directs the players turn
private bool player_turn(int player, int[] score, string phrase, string puzzle)
{
//Declaring local variables
sbyte choice;
bool validChoice = false;
Console.Write("It is player ");
Console.Write(player + 1);
Console.Write("'s turn");
Console.Write(" ");
Console.Write("What would you like to do with your turn?");
Console.Write(" ");
Console.Write("Here are your options:");
Console.Write(" ");
Console.Write("(s)pin the wheel, s(o)lve he puzzle, or (b)uy a vowel");
Console.Write(" ");
Console.Write("Type the corresponding lower case letter in () to move on ->");
choice = sbyte.Parse(ConsoleInput.ReadToWhiteSpace(true));
//Loop to make sure the player entered a valid character to execute
//a function
while (!validChoice)
{
validChoice = false;
switch (choice)
{
case 's':
spin(player, score, phrase, puzzle);
Console.Write(" ");
validChoice = true;
break;
case 'o':
solve(player, score, phrase, puzzle);
Console.Write(" ");
validChoice = true;
break;
case 'b':
buy_vowel(player, score, phrase, puzzle);
Console.Write(" ");
validChoice = true;
break;
default :
Console.Write("Please make sure you typed a lower case letter");
Console.Write(" ");
break;
}
}
return (player_turn);
}
internal static class RandomNumbers
{
private static System.Random r;
internal static int NextNumber()
{
if (r == null)
Seed();
return r.Next();
}
internal static int NextNumber(int ceiling)
{
if (r == null)
Seed();
return r.Next(ceiling);
}
internal static void Seed()
{
r = new System.Random();
}
internal static void Seed(int seed)
{
r = new System.Random(seed);
}
}
internal static class ConsoleInput
{
private static bool goodLastRead = false;
internal static bool LastReadWasGood
{
get
{
return goodLastRead;
}
}
internal static string ReadToWhiteSpace(bool skipLeadingWhiteSpace)
{
string input = "";
char nextChar;
while (char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
//accumulate leading white space if skipLeadingWhiteSpace is false:
if (!skipLeadingWhiteSpace)
input += nextChar;
}
//the first non white space character:
input += nextChar;
//accumulate characters until white space is reached:
while (!char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
input += nextChar;
}
goodLastRead = input.Length > 0;
return input;
}
internal static string ScanfRead(string unwantedSequence = null, int maxFieldLength = -1)
{
string input = "";
char nextChar;
if (unwantedSequence != null)
{
nextChar = '';
for (int charIndex = 0; charIndex < unwantedSequence.Length; charIndex++)
{
if (char.IsWhiteSpace(unwantedSequence[charIndex]))
{
//ignore all subsequent white space:
while (char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
}
}
else
{
//ensure each character matches the expected character in the sequence:
nextChar = (char)System.Console.Read();
if (nextChar != unwantedSequence[charIndex])
return null;
}
}
input = nextChar.ToString();
if (maxFieldLength == 1)
return input;
}
while (!char.IsWhiteSpace(nextChar = (char)System.Console.Read()))
{
input += nextChar;
if (maxFieldLength == input.Length)
return input;
}
return input;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.