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
|
// Coin Toss Game.cpp : main project file.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <windows.h>
using namespace std;
void gotoXY(int x, int y);
void gotoXY(int x, int y, string text);
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
int main()
{
int guess, coinFace, playsLeft = 10, streak = 0, x;
char playAgain = 'y', cashIn = 'n';
string erase(80,' '); // To delete one complete line on screen
srand(static_cast<unsigned int>(time(0)));
gotoXY(23, 3,"Welcome to Packerstars Coin Toss!!");
gotoXY(10, 6,"Rules:");
gotoXY(10, 8,"Guess 10 coin tosses in a row to win the 1,000,000 pound Jackpot.");
gotoXY(10, 9,"Guess 7 in a row, and cash in to win 100 pounds.");
gotoXY(10,10,"Guess 5 in a row, and cash in to win 20 pounds.");
gotoXY(10,11,"Guess 3 in a row, and cash in for 1 pound.");
while (playAgain =='y')
{
do
{
coinFace = rand() % 2+1;
gotoXY(20,13,"Do you pick Heads or Tails? (1 or 2) : _\b"); // A '\b' is a backspace. Now it erases last input, and waits for next
cin >> guess;
--playsLeft;
if(guess == coinFace && coinFace == 1)
{
++streak;
gotoXY(28,16,"The coin landed Heads up!");
gotoXY(13,18);
cout << "You guessed correct! "<< playsLeft << " plays left, with a streak of " << streak << "!";
}
else if(guess == coinFace && coinFace == 2)
{
++streak;
gotoXY(28,16,"The coin landed Tails up!");
gotoXY(13,18);
cout << "You guessed correct! "<< playsLeft << " plays left, with a streak of " << streak << "!";
}
else if(guess != coinFace && coinFace == 1)
{
streak = 0;
gotoXY(28,16,"The coin landed Heads up!");
gotoXY(21,18, "Unlucky, you were wrong!");
if (playsLeft!=0)
{
cout << " " << playsLeft << " play";
if (playsLeft>1)
cout << "s";
cout << " left!";
}
else
cout << " Game OVER!!";
}
else if(guess != coinFace && coinFace == 2)
{
streak = 0;
gotoXY(28,16,"The coin landed Tails up!");
gotoXY(21,18, "Unlucky, you were wrong!");
if (playsLeft!=0)
{
cout << " " << playsLeft << " play";
if (playsLeft>1)
cout << "s";
cout << " left!";
}
else
cout << " Game OVER!!";
}
if(streak == 3)
{
gotoXY(13,20,"You have reached a streak of three!! Cash in?(y/n) : _\b");
cin >>cashIn;
}
else if(streak == 5)
{
gotoXY(14,20,"You have reached a streak of five!! Cash in?(y/n) : _\b");
cin >>cashIn;
}
else if(streak == 7)
{
gotoXY(13,20,"You have reached a streak of seven!! Cash in?(y/n) : _\b");
cin >>cashIn;
}
else if(streak == 10)
{
cashIn = 'y';
}
if(playsLeft == 0)
{
cashIn = 'y';
}
Sleep(1500);
if (playsLeft!=0)
{
for(x=16;x<23;x++)
gotoXY(0,x,erase);
}
}while (cashIn != 'y');
if(streak==10)
{
gotoXY(31,18,"CONGRATULATIONS!!");
gotoXY(10,20,"You win the Jackpot of 1,000,000 pounds with a streak of ten, YOU JAMMY BASTARD!");
}
else if(streak == 3 && cashIn == 'y')
{
gotoXY(31,18,"CONGRATULATIONS!!");
gotoXY(10,20,"You have cashed in for 1 pound with a streak of 3!");
}
else if(streak == 5 && cashIn == 'y')
{
gotoXY(31,18,"CONGRATULATIONS!!");
gotoXY(10,20,"You have cashed in for 20 pounds with a streak of 5!");
}
else if(streak == 7 && cashIn == 'y')
{
gotoXY(31,18,"CONGRATULATIONS!!");
gotoXY(10,20,"You have cashed in for 100 pounds with a streak of 7!");
}
else if(streak != 10 && cashIn == 'y')
{
gotoXY(10,20,"You have run out of plays! Better luck next time, LOSER!");
}
gotoXY(17,22,"Do you wish to try your luck again? (y/n) : _\b");
cin >> playAgain;
for(x=16;x<23;x++)
gotoXY(0,x,erase);
playsLeft = 10;
cashIn = 'n';
streak = 0;
}
gotoXY(37,18, "Ok, cya!!");
gotoXY(30,24);
return 0;
}
void gotoXY(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
void gotoXY(int x, int y, string text)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
cout << text;
}
|