-
Notifications
You must be signed in to change notification settings - Fork 71
/
7upGame.cpp
168 lines (156 loc) · 4.72 KB
/
7upGame.cpp
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
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <ctype.h>
using namespace std;
int life, score, Rand_No = 7,row=0;
char input = '\0', player[15];
void frame();
void checkAndUpdate();
void Intro();
void conclude();
int main()
{
srand(time(0));
life = 3;
score = 0;
Intro();
while (life)
{
frame();
}
conclude();
return 0;
}
void frame()
{
system("clear");
cout << "\n\n\tLife:\t" << life << "\t\t\t\t Score: " << setw(4) << score << "\n\n";
cout << "\t\t\t Scoring and Rules\n";
cout << "\t\t\t Output Number \n";
cout << "\t\t\t +-------+ \n";
cout << "\t\t\t | | \n";
cout << "\t\t\t | " << setw(2) << Rand_No << " |\n";
cout << "\t\t\t | | \n";
cout << "\t\t\t +-------+ \n";
CHECK:
cout << "\n\n(H->High, L->Low and 7->for exect 7\n";
cout << "\n\nEnter the move\n";
cin>>input;
input = toupper(input);
switch (input)
{
case 'H':
case '7':
case 'L':
break;
default:
cout << "\nInvalid Move!!";
goto CHECK;
}
checkAndUpdate();
}
void checkAndUpdate()
{
Rand_No = rand()%11 + 2;
switch (input)
{
case 'H':
if(Rand_No>7)
{
row++;
cout<<"\n\nCorrrect Guess You get "<<row<<" in a row\n";
cout<<"The Random genrated number is "<<Rand_No<<endl;
score+=10;
if(row%5==0 && row)
{
score+=5;
life++;
cout<<"\nYou won a extra 5 points and 1 life\n";
}
system("pause");
}
else
{
row=0;
life--;
cout<<"\n\nIncorrrect Guess \n";
cout<<"The Random genrated number is "<<Rand_No<<endl;
system("pause");
}
break;
case '7':
if(Rand_No==7)
{
row++;
cout<<"\n\nCorrrect Guess You get "<<row<<" in a row\n";
cout<<"The Random genrated number is "<<Rand_No<<endl;
score+=25;
life++;
if(row%5==0 && row)
{
score+=5;
life++;
cout<<"\nYou won a extra 5 points and 1 life\n";
}
system("pause");
}
else
{
row=0;
life--;
cout<<"\n\nIncorrrect Guess \n";
cout<<"The Random genrated number is "<<Rand_No<<endl;
system("pause");
}
break;
case 'L':
if(Rand_No<7)
{
row++;
cout<<"\n\nCorrrect Guess You get "<<row<<" in a row\n";
cout<<"The Random genrated number is "<<Rand_No<<endl;
score+=10;
if(row%5==0 && row)
{
score+=5;
life++;
cout<<"\nYou won a extra 5 points and 1 life\n";
}
system("pause");
}
else
{
row=0;
life--;
cout<<"\n\nIncorrrect Guess \n";
cout<<"The Random genrated number is "<<Rand_No<<endl;
system("pause");
}
break;
}
}
void Intro()
{
system("clear");
cout << "\t\t\t 7 UP AND DOWN\n";
cout << "\n\n\tLife:\t" << life << "\t\t\t\t Score: " << setw(4) << score << "\n\n";
cout << "\t\t\t Scoring and Rules\n";
cout << "1. The numbers genrated by the systems will between 2-12\n";
cout << "2. Correct guessing the side High/Low -> +10 points\n";
cout << "3. Correct guessing the side High/Low 5 in a row -> +5 points extra + 1 life \n";
cout << "4. Guessing the Exect 7 -> +25 points + 1 life\n";
cout << "5. Guessing wrong -> -1 life\n";
cout << "\n\nEnter the name of Player\n";
cin.getline(player,20);
cout << endl<< player << " Lesgooooo.....\n";
system("pause");
}
void conclude()
{
system("clear");
cout << "\t\t\t\t 7 UP AND DOWN\n";
cout<<"\n\n\t\t\tThanks "<<player<<" for Playing the game\n";
cout<<"\n\t\t\t\tYour Score is: " << setw(4) << score << "\n\n";
system("pause");
}