CurvedSpace Forums: Wheel_Of_Fortune.cpp - CurvedSpace Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • {lang:pm_locked} This topic is locked

Wheel_Of_Fortune.cpp (much pwnage)

#1 {lang:macro__useroffline}   Neraphym {lang:icon}

  • Do not want!
  • Icon
  • {lang:view_blog}
  • Group: Super Moderator
  • Posts: 10,332
  • Joined: 29-October 03

Posted 14 March 2006 - 03:38 PM

// Chris Ray & Matt Smith
// Wheel Of Fortune

#include<iostream.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>

void setphrase();
void setvphrase();
void guessletter();
void guessphrase();
int testphrase(char);
void display();
int spin();
void getp1name();
void getp2name();
void reveal();
int end();

// Input Phrase
char tempphrase[46] = " ";

// Phrase
char phrase[3][15] = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '} };

// Shown Phrase
char vphrase[3][15] = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '} };

// Letter Guess
char guess = ' ';

// Names
char p1name[20];
char p2name[20];

// Scores
int pscore[3] = {0,0,0};

// Passes
int passes = 0;
int playnum = 0;

// Action Selection Variable
int valid = 0;
int actionselect;

// End of Game Checkers
int stars = 0;
int endgame = 0;

// Letters
int letters[2][26] = { {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} };

void main()
{
setphrase();
setvphrase();
getp1name();
getp2name();

do
{
do
{
display();

playnum = (passes % 2) + 1;
cout << "Player " << playnum << ", Choose Action:" << endl;
cout << "1: Guess Letter" << endl;
cout << "2: Guess Phrase" << endl;
cin >> actionselect;

if(actionselect == 1)
{
valid = 1;
}
else if(actionselect == 2)
{
valid = 1;
}
else
{
valid = 0;
}

}while(valid != 1);

display();

if(actionselect == 1)
{
guessletter();
}
else if (actionselect == 2)
{
guessphrase();
}

endgame = end();

passes = passes + 1;

}while(endgame == 0);

display();

if(pscore[1] > pscore[2])
{
cout << "Congrats, " << p1name << "! You Win!!!" << endl;
}
else if(pscore[2] > pscore[1])
{
cout << "Congrats, " << p2name << "! You Win!!!" << endl;
}
else
{
cout << "It's a tie!" << endl;
}

}



// Function to set phrase

void setphrase()
{
int wlength[10] = {0,0,0,0,0,0,0,0,0,0};
int words = -1;
int start = 0;
int stop = 0;
int counter = 0;
int letter = 0;
int remainder[3] = {0,0,0};
int wpl[3] = {0,0,0};
int line = 0;
int tp = 0;
int current = 1;
int previous = 0;
int total = 0;

system("cls");

cout << "Enter a phrase:" << endl;
cin.getline(tempphrase, 46);
cout << endl;

do
{
if(tempphrase[letter] == ' ' || tempphrase[letter] == '\0')
{
stop = letter - 1;
wlength[counter] = (stop - start + 1);
start = start + wlength[counter] + 1;
counter = counter + 1;
}

letter = letter + 1;

}while(counter < 10);

do
{
words = words + 1;
} while (wlength[words] != 0);

//First Word

for(int w1 = 0; w1 < wlength[0]; w1++)
{
phrase[line][w1] = tempphrase[tp];
tp = tp + 1;
}
words = words - 1;
wpl[line] = wpl[line] + 1;
tp = tp + 1;

//Remaining Words
do
{
for(int a = 1; a <= wpl[line]; a++)
{
total = total + wlength[(current - a)];
}

total = total + wpl[line];

remainder[line] = 15 - total;

//If it fits on line
if(remainder[line] >= wlength[current])
{
for(int w2 = total; w2 < (total + wlength[current]); w2++)
{
phrase[line][w2] = tempphrase[tp];
tp = tp + 1;
}
words = words - 1;
wpl[line] = wpl[line] + 1;
tp = tp + 1;
}
//If it doesn't fit on line
else
{
line = line + 1;

for(int w2 = 0; w2 < wlength[current]; w2++)
{
phrase[line][w2] = tempphrase[tp];
tp = tp + 1;
}
words = words - 1;
wpl[line] = wpl[line] + 1;
tp = tp + 1;
}

previous = current;
current = current + 1;

total = 0;
}while(words > 0);

system("cls");
}



//Sets Visible Phrase

void setvphrase()
{
for(int vline = 0; vline < 3; vline++)
{
for(int vcol = 0; vcol < 15; vcol ++)
{
if(phrase[vline][vcol] != ' ')
{
vphrase[vline][vcol] = '*';
stars = stars + 1;
}
else
{
vphrase[vline][vcol] = '_';
}
}
}
}



// Function to guess letter

void guessletter()
{
system("cls");
display();

int score = 0;
int spinvalue = 0;
int match = 0;
int guesscheck = 0;

spinvalue = spin();

cout << "You spun " << spinvalue << endl;

do
{
guesscheck = 1;

cout << "Enter a letter to be guessed:\t";
cin >> guess;


}while(guesscheck == 0);

system("cls");

match = testphrase(guess);
score = spinvalue * match;

if(match > 0)
{
cout << "There were " << match << " " << guess << "'s." << endl;
cout << "You made: $" << score << endl;
cout << "You get to go again" << endl;
cout << endl;
passes = passes + 1;
stars = stars - match;
}
else
{
cout << "There were no " << guess << "'s." << endl;
cout << endl;
}

pscore[playnum] = pscore[playnum] + score;
}



// Function to guess phrase

void guessphrase()
{
char guessphrase[46] = " ";

system("cls");
display();

cout << "Enter a phrase (non-case sensitive):" << endl;
cin.ignore(100, '\n');
cin.getline(guessphrase, 45);

system("cls");

if(stricmp(guessphrase, tempphrase) == 0)
{
reveal();
stars = 0;
cout << "Correct! You get 2000 dollars!" << endl;
pscore[playnum] = pscore[playnum] + 2000;
cout << endl;
}
else
{
cout << "Inorrect." << endl;
}
}

//Gets Player 1's Name

void getp1name()
{
system("cls");
cout << "Player 1" << endl;
cout << "Enter your name:\t";
cin.getline(p1name, 20, '\n');
}



//Gets Player 1's Name

void getp2name()
{
system("cls");
cout << "Player 2" << endl;
cout << "Enter your name:\t";
cin.getline(p2name, 20, '\n');
}



// Finds Matching Letters, Shows Them, Returns # Of Matches

int testphrase(char guessletter)
{
int matches = 0;

for(int gline = 0; gline < 3; gline++)
{
for(int gcol = 0; gcol < 15; gcol ++)
{
if(phrase[gline][gcol] == guessletter)
{
vphrase[gline][gcol] = phrase[gline][gcol];
matches = matches + 1;
}
}
}

return matches;
}



//Function to display phrase

void display()
{
for(int dline = 0; dline < 3; dline++)
{
for(int dcol = 0; dcol < 15; dcol ++)
{
cout << vphrase[dline][dcol];
}
cout << endl;
}
cout << endl;

cout << "Player 1 Score:\t" << pscore[1] << endl;
cout << "Player 2 Score:\t" << pscore[2] << endl;
cout << endl;
}



//Spin Function

int spin()
{
int wheel = 0;
int money = 0;

wheel = rand() % 55 + 1;

if(wheel <= 10)
{
money = 100;
}
else if(wheel <= 19)
{
money = 200;
}
else if(wheel <= 27)
{
money = 300;
}
else if(wheel <= 34)
{
money = 400;
}
else if(wheel <= 40)
{
money = 500;
}
else if(wheel <= 45)
{
money = 600;
}
else if(wheel <= 49)
{
money = 700;
}
else if(wheel <= 52)
{
money = 800;
}
else if(wheel <= 54)
{
money = 900;
}
else if(wheel <= 55)
{
money = 1000;
}

return money;
}



//Phrase Revealer

void reveal()
{
for(int rline = 0; rline < 3; rline++)
{
for(int rcol = 0; rcol < 15; rcol ++)
{
vphrase[rline][rcol] = phrase[rline][rcol];
}
}
}



//End Game Check

int end()
{
int ender = 0;

if(stars == 0)
{
ender = 1;
reveal();
}
else
{
ender = 0;
}

return ender;
}
Neraphym Archaeon
Posted Image
GWAMM
0

#2 {lang:macro__useroffline}   Neraphym {lang:icon}

  • Do not want!
  • Icon
  • {lang:view_blog}
  • Group: Super Moderator
  • Posts: 10,332
  • Joined: 29-October 03

Posted 14 March 2006 - 03:39 PM

I wish it retained the tabs...
Neraphym Archaeon
Posted Image
GWAMM
0

Page 1 of 1
  • You cannot start a new topic
  • {lang:pm_locked} This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users