1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
//*****MENU*****
void menuOptions (int x){
cout << "****Welcome to Game Menu****"<<endl;
cout << "Your starting money is " << x << endl;
cout << "Select Game:"<<endl;
cout << "Game 1 Slot Machine - Press 1"<<endl;
cout << "Game 2 - Press 2"<<endl;
cout << "Game 3 - Press 3"<<endl;
cout << "View Game Stats - Press 4"<<endl;
cout << "Exit - Press 5" <<endl;
}
//*****MENU*****
int main()
{
int userInput;
menuOptions(100);// recall Game Menu from void
cin >> userInput;
if (userInput ==1){ //User decides to play Playing slots game
cout<< "Playing Slots"<<endl;
//*****************functioning Slot machine code********************
enum Options {TOMATO, ORANGE, APPLE, PINEAPPLE, STRAWBERRY, GRAPES};
const int MILIDELAY = 1; //defines the delay in miliseconds as a constant
const int NUMSPINS = 50; //defines the number of time to spin the slot machine as a constant
string outputOptions(Options x); //Returns the string equivalent of the enum type Options value
void getPos(Options& x); //This function cycles through the Options values
void delay(); //delays the output by the number of miliseconds as defined by the constant MILIDELAY
void spinMachine(Options& one, Options& two, Options& three); //Simulates the spinning of the slot machine for a specifed number of spins as defined by NUMSPINS
void getStopOrder(int& first, int& second, int& last);
int main()
{
//defines three spinning position each starting with a different value
Options posOne = TOMATO;
Options posTwo = APPLE;
Options posThree = GRAPES;
char userChoice = 'z';
while(userChoice != 'n')
{
spinMachine(posOne, posTwo, posThree); //spins the slotmachines positions
cout<<"\nWould you like to spin again? (y/n): ";
cin>>userChoice;
//FORCE a WIN!
if (posOne==APPLE && posTwo==APPLE && posThree==APPLE){
cout<< "\nYou Win!";
}
//FORCE A WIN
}
return 0;
}
string outputOptions(Options x)
{
//Returns the string equivalent of the enum type Options value
switch (x)
{
case TOMATO:
return "TOMATO";
break;
case ORANGE:
return "ORANGE";
break;
case APPLE:
return "APPLE";
break;
case PINEAPPLE:
return "PINEAPPLE";
break;
case STRAWBERRY:
return "STRAWBERRY";
break;
case GRAPES:
return "GRAPES";
break;
}
}
void getPos(Options& x)
{
//This function cycles through the Options values
//each time it is called it increments to the next Options value and
//starts from the beginning of the list when it reaches the end of the list
if (x == GRAPES)
x = TOMATO;
else
x = static_cast<Options>(x+1);
}
void delay()
{
//delays the output by the number of miliseconds passed
clock_t endWait = clock () + MILIDELAY;
while (clock() < endWait) {} //do nothing
}
void spinMachine(Options& posOne, Options& posTwo, Options& posThree)
{
int first, second, last;
int count = 0;
//determines how many spins to stop the first and second position to stop before the last.
//numStopFirst must be greater than numStopSecond
int numStopFirst = 20, numStopSecond = 10;
while (count <= NUMSPINS)
{
//randomly determine which position to stop first, second, and last
getStopOrder(first, second, last);
//determines how long to spin each position based on their stop order
if (first == 1)
{
if (count <= NUMSPINS-numStopFirst)
{
getPos(posOne);
}
if (second == 2)
{
if (count <= NUMSPINS-numStopSecond)
getPos(posTwo);
getPos(posThree);
} else
{
if (count <= NUMSPINS-numStopSecond)
getPos(posThree);
getPos(posTwo);
}
} else if (first == 2)
{
if (count <= NUMSPINS-numStopFirst)
{
getPos(posTwo);
}
if (second == 3)
{
if (count <= NUMSPINS-numStopSecond)
getPos(posThree);
getPos(posOne);
} else
{
if (count <= NUMSPINS-numStopSecond)
getPos(posOne);
getPos(posThree);
}
} else
{
if (count <= NUMSPINS-numStopFirst)
{
getPos(posThree);
}
if (second == 2)
{
if (count <= NUMSPINS-numStopSecond)
getPos(posTwo);
getPos(posOne);
} else
{
if (count <= NUMSPINS-numStopSecond)
getPos(posOne);
getPos(posTwo);
}
}
//increments the value of Options each time the loop is execute
//getPos(posOne);
//getPos(posTwo);
//getPos(posThree);
delay(); //delay the execution of the cout statement by the number of miliseconds as defined by the constant MILIDELAY
//displays the value of each position on the same line in the conole
cout<<"Spinning: "<<setw(15)<<outputOptions(posOne)<<setw(15)<<outputOptions(posTwo)<<setw(15)<<outputOptions(posThree)<<"\r";
count++; //increments count so that the loop can terminate
}
}
void getStopOrder(int& first, int& second, int& last)
{
//randomly determines the order in which to stop spinning each position
srand(time(0));
first = rand()%3+1;
last = rand()%3+1;
if (first == last)
{
if(last == 3)
{
last = 1;
second = 2;
} else
{
last = last +1;
if (last == 3)
second = 1;
else
second = last + 1;
}
} else if ( first == 1)
{
if (last == 2)
second = 3;
else
second = 2;
} else if ( first == 2 )
{
if (last == 3)
second = 1;
else
second = 2;
} else
{
if (last == 1)
second = 2;
else
second = 1;
}
}
}
if (userInput ==4)// user decides to View Game stats
{
// execute part 2 of project objective; view game 1,2,3 stats menu with option to delete
char selection;
cout<<"\n Game Menu";
cout<<"\n========";
cout<<"\n A - Game 1 Slot Machine Stats";
cout<<"\n M - Game 2 Stats";
cout<<"\n D - Game 3 Stats";
cout<<"\n X - Delete User";
cout<<"\n F - Return to Main Menu";
cout<<"\n P - Exit";
cout<<"\n Enter selection: ";
// read the input
cin>>selection;
switch(selection)
{
case 'A' :
case 'a' :
cout<< "\n*****Game 1 Stats******";
cout<< "Name" <<" Highest Score "<< "Rank"<<endl;
cout<< "Cool Man" <<" 230 "<< " 1 "<<endl;
cout<< "Best Name" <<" 200 "<< " 2 "<<endl;
cout<< "Bang Bang" <<" 150 "<< " 3 "<<endl;
cout<< "Press D to Delete Player"<<endl;
break;
case 'M' :
case 'm' :
cout<< "\n*****Game 2 Stats******";
cout<< "Name" <<" Highest Score "<< "Rank"<<endl;
cout<< "Cool Man" <<" 60 "<< " 1 "<<endl;
cout<< "Best Name" <<" 30 "<< " 2 "<<endl;
cout<< "Bang Bang" <<" 20 "<< " 3 "<<endl;
cout<< "Press D to Delete Player"<<endl;
break;
case 'D' :
case 'd' :
cout<< "\n*****Game 3 Stats******";
cout<< "Name" <<" Highest Score "<< "Rank"<<endl;
cout<< "Cool Man" <<" 100 "<< " 1 "<<endl;
cout<< "Best Name" <<" 90 "<< " 2 "<<endl;
cout<< "Bang Bang" <<" 50 "<< " 3 "<<endl;
cout<< "Press D to Delete Player"<<endl;
break;
case 'X' :
case 'x' :
cout<< "\n*****Deleting Game Stats******";
// I need help on this.
break;
// other than A, M, D and X...
default : cout<<"\n Invalid selection, Program Crashed";
// no break in the default case
}
cout<<"\n";
if (userInput==2){
cout << "Playing Game 2"<<endl;
}
if (userInput==3)
{
cout << "Playing Game 3"<<endl;
}
return 0;
}
}
|