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
|
#include <iostream>
#include "graph1.h"
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
int main()
{
//declaring variables
unsigned int seed; //declaring seed
int price = 0; //declaring win
char repeat = 'y'; //repeat program
int num = 0; //declaring random number
int num1 = 0; //declaring random number
int start_time = time(0); int current_time = time(0); int remain_time = 0;
//displaying graphics
displayGraphics();
do
{
//get the system time and seed the random number generator
seed = (unsigned int)clock();
//picking random number
num = rand() % 10 + 1; num1 = rand() % 500 + 500;
if (num == 1)
{
displayBMP("chair.bmp", 155, 90); gout << setPos(155, 345) << "Chair" << endg;
}
else if (num == 2)[code]
{
displayBMP("couch.bmp", 155, 90);
gout << setPos(155, 345) << "Couch" << endg;
}
else if (num == 3)
{
displayBMP("dodgers.bmp", 155, 90); gout << setPos(155, 345) << "Dodger’s Tickets for 1 week" << endg;
}
else if (num == 4)
{
displayBMP("freezer.bmp", 155, 90); gout << setPos(155, 345) << "Freezer" << endg;
}
else if (num == 5)
{
displayBMP("jukebox.bmp", 155, 90); gout << setPos(155, 345) << "Juke Box full of LPs" << endg;
}
else if (num == 6)
{
displayBMP("lawnmowers.bmp", 155, 90); gout << setPos(155, 345) << "Lawn Mowers" << endg;
}
else if (num == 7)
{
displayBMP("piano.bmp", 155, 90); gout << setPos(155, 345) << "Piano" << endg;
}
else if (num == 8)
{
displayBMP("pooltable.bmp", 155, 90); gout << setPos(155, 345) << "Pool Table" << endg;
}
else if (num == 9)
{
displayBMP("powerTools.bmp", 155, 90); gout << setPos(155, 345) << "Power Tools" << endg;
}
else if (num == 10)
{
displayBMP("recliner.bmp", 155, 90); gout << setPos(155, 345) << "Recliner" << endg;
}
do
{
//user input
cout << "Enter value for prize: "; cin >> price; start_time = time(0);
do
{
if ((price < 500) || (price>1000))
{
cout << "Enter a Valid Number between 500 and 1000"; cin >> price;
}
}while ((price<500) || (price>1000));
if (price<num1)
{
gout << setPos (155, 360) << "HIGHER" << endg;
}
else if (price>num1)
{
gout << setPos (155,360) << "LOWER" << endg;
}
else if (price==num1)
{
gout << setPos (155, 360) << "!!!!!!YOU WIN!!!!!!" << endg;
}
current_time = time(0); remain_time = 30 - (current_time - start_time);
gout << setPos(155, 380) << "Time Remaining " << remain_time << " secs" << endg;
}while ((price!=num1) || (remain_time>0));
gout << setPos (155, 360) << "GAME OVER" << endg; gout << setPos (155, 400) << "correct price" << num1 << endg;
//Ask user to run program again
cout << "Run program again? (y/n): "; cin >> repeat;
clearGraphics();
}while ( (repeat == 'y') || (repeat == 'Y') );
return 0;
}
|