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
|
#include <iostream>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <ctime>
using namespace std;
void drop_chips(int val, int &chips, bool &ans, int &money, vector<int> mon);
void menu(int &chips, bool &ans);
void quit(bool &replay_answer)
{
cout << "Game Over."<<endl;
system("pause");
replay_answer = false;
exit(0); //This ends the program
}
double stay_on_board(double &slot_num, double &location_change)
{
if (slot_num<0)
{
location_change = 1.0;
slot_num = slot_num + location_change;
cout<<slot_num<<endl;
}
else if(slot_num>8)
{
location_change = -1.0;
slot_num = slot_num + location_change;
cout<<slot_num<<endl;
}
return slot_num;
}
int win_money(double slot_num, int &num_chips, bool &replay_answer, int decision, vector<int>& money)
{
int money_won = 0;
if(slot_num == 0)
{
money_won = money_won + 100;
}
else if(slot_num == 1)
{
money_won = money_won + 500;
}
else if(slot_num == 2)
{
money_won = money_won + 1000;
}
else if(slot_num == 3)
{
money_won = money_won + 0;
}
else if(slot_num == 4)
{
money_won = money_won + 10000;
}
else if(slot_num == 5)
{
money_won = money_won + 0;
}
else if(slot_num == 6)
{
money_won = money_won + 1000;
}
else if(slot_num == 7)
{
money_won = money_won + 500;
}
else if(slot_num == 8)
{
money_won = money_won + 100;
}
//system("pause");
money.push_back(money_won);
return money_won;
}
void repeat_drop(int decision, int &num_chips, bool &replay_answer, int &money_now, vector<int>& money)
{
string repeat;
//this asks if the user wants to replay, and gain more money;
cout << "Would you like to drop more chips? y or n. If you say no, you will lose all your money."<<endl;
cin >> repeat;
if(repeat=="y")
{
drop_chips(decision, num_chips, replay_answer, money_now, money);
}
else if (repeat == "n")
{
menu(num_chips, replay_answer);
}
else //this ends the program after the user inputs a non-usable string
{
quit(replay_answer);
}
}
void count_money(double slot_num, int &num_chips, bool &replay_answer, int decision, int &money_now, vector<int>& money)
{
int money_won = win_money(slot_num, num_chips, replay_answer, decision, money);
money_now = money_won + money_now;
cout<<"You won $"<<money_won<<" with this chip. You now have $"<<money_now<<"."<<endl;
system("pause");
}
double slot_change()
{
double direction = 0.5-(rand()*1.0/RAND_MAX); //random number between -0.5 and 0.5
double location_change;
if (direction > 0)
{
location_change = 0.5;
}
else if (direction < 0)
{
location_change = -0.5;
}
return location_change;
}
void money_analysis()
{
}
void track_chips(double slot_num, int &num_chips, bool &replay_answer, int decision, int &money_now, vector<int>& money)
{
for(int chips_used=0; chips_used<num_chips; chips_used++) //this does the loop until the chips are used up (if num_chips==1, only does it once)
{
cout<<"This is chip "<<chips_used+1<<"."<<endl;
for(int num_pegs=0; num_pegs<12; num_pegs++) //redoes for twelve pegs
{
double location_change = slot_change();
slot_num = slot_num + location_change; //changes location
if(slot_num>=0 && slot_num <=8)
{
cout<<slot_num<<endl; //continues
}
else
{
slot_num = stay_on_board(slot_num, location_change);
}
}
count_money(slot_num, num_chips, replay_answer, decision, money_now, money);
}
}
void drop_all_slots(int &num_chips, bool &replay_answer, int &money_now, int &decision, vector<int>& money)
{
for(int slot_drop=0; slot_drop<9; slot_drop++)
{
double slot_num = slot_drop;
cout<<"Dropping "<<num_chips<<" chips into Slot #"<<slot_num+1<<endl;
system("pause");
track_chips(slot_num, num_chips, replay_answer, decision, money_now, money);
money_analysis();
}
}
void drop_chips(int decision, int &num_chips, bool &replay_answer, int &money_now, vector<int>& money)
{
if(decision==2 || decision==3) //multiple chips
{
cout<<"How many chips do you want to drop?"<<endl;
cin >> num_chips; //chooses how many chips the user wants to drop in a spot
if(num_chips<=0 || cin.fail())
{
//returns to menu
menu(num_chips, replay_answer);
}
}
if(decision==1 || decision==2)
{
double slot_num;
cout << "Where do you want to drop the chips? Please type a number between 0 and 8."<<endl;
cin >> slot_num;
if(slot_num<0 || slot_num>8 || cin.fail())
{
menu(num_chips, replay_answer);
}
track_chips(slot_num, num_chips, replay_answer, decision, money_now, money);
}
if(decision==3)
{
drop_all_slots(num_chips, replay_answer, money_now, decision, money);
}
repeat_drop(decision, num_chips, replay_answer, money_now, money);
}
void menu_analysis(string menu_choice, int &num_chips, bool &replay_answer, int &money_now, vector<int>& money)
{
int decision;
if(menu_choice == "chip")
{
decision = 1;
}
else if(menu_choice == "chips")
{
decision = 2;
}
else if(menu_choice == "slots")
{
decision = 3;
}
else if(menu_choice == "q")
{
quit(replay_answer); //This ends the program
}
else
{
quit(replay_answer);
}
drop_chips(decision, num_chips, replay_answer, money_now, money);
}
void menu(int &num_chips, bool &replay_answer)
{
vector<int> money(0);
int money_now = 0;
string menu_choice;
cout << "Welcome to Plinko. This is a game that will test your luck. Please pick one of four options:"<<endl;
cout << "Drop one chip."<<" To pick this option, type 'chip'."<<endl;
cout << "Drop multiple chips."<<" To pick this option, type 'chips'."<<endl;
cout << "Drop one or more chips in all nine slots."<<" To pick this option, type 'slots'."<<endl;
cout << "To quit, press q."<<endl;
cin >> menu_choice;
menu_analysis(menu_choice, num_chips, replay_answer, money_now, money);
}
int main()
{
bool replay_answer = true;
int num_chips = 1;
while(replay_answer==true)
{
menu(num_chips, replay_answer);
system("pause");
}
return(0);
}
|