-
Notifications
You must be signed in to change notification settings - Fork 0
/
THE BORING GAME.cpp
184 lines (148 loc) · 5.13 KB
/
THE BORING GAME.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include<iostream>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
#include<ctime>
using namespace std;
int main()
{
using std::cout;
using std::cin;
using std::endl;
system("CLS"); //clears the screen
int a,red; // variable a takes the difficulty choice and red defines number of moves
char name;
// Instructions
cout<<"\t\t\t THE BORING GAME \n\n"<<"\n Instructions :\n1. You are Assigned with a * as your movable charachter ,Your goal is to make contact with percentage sign \n";
cout<<"2. You have Limited Number of Moves, if you Succeed in reaching % within the moves you WIN \n";
cout<<"3. Use W,A,S,D keys to move your character \n"<<"4.Dont touch the -- or || bars you will loose the game"<<"\n5. BEWARE OF THE @ SIGNS THAT POP UP RANDOMLY IF YOU TOUCH THEM YOU LOOSE"<<endl;
cout<<"\n Ok ";
cout<<" Select your Difficulty Level \n"<<"\n1.EASY \n"<<"2.MEDIUM \n"<<"3.HARD \n"<<"4.IMPOSSIBLE \n\nENTER YOUR CHOICE : ";
cin>>a;
if( a==1)
red = 5; //if easy is chosen reduces total moves by 5
else if(a==2)
red = 10; //if hard is chosen reduces total moves by 10
else if(a==3)
{
red = 30; //if impossible is chosen reduces total moves by 30
cout<<"Are you sure "<<name<<" you can do this, dont chicken out at the end";
}
else if(a==4)
{
red = 40;
cout<<name<<"Its Impossible to solve then why even care";
}
else
cout<<name<<"YOU HAVE MADE A WRONG CHOICE";
cout<<endl<<"\n THE GAME BEGINS ";
int x = 1,y =1,m,n,count=50 - red,j=0;
char input; //variable to read moves from keyboard
system("CLS");
char brdr [14][52] = {"--------------------------------------------------",
"|* |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"---------------------------------------------------"};
// the border of the game looks like the above array
brdr[7][35] = '%'; //target location where the charater to be reached
for(int t =0; t>=0;t++)
{
for(int i =0; i<=14;i++) //prints the borders and the location characher and target
cout<<brdr[i]<<endl;
cout<<" \n \n MOVES LEFT ="<<count; //print the number of moves left
m = rand() % 10;
n = rand() % 50; //randomises position for obstacles
if(brdr[m][n] != brdr[7][35] && m >0 && n> 0)
brdr[m][n] = '@'; //obstacle placing at different positions
input =tolower(getche()); //gets input from keyboard
if(input == 'd') //if input is d the charachter moves left
{
brdr[x][y] = ' ';
if(brdr[x][y+1] == '|'||brdr[x][y+1] == '@') // if that shifted positition = @ then exit
exit(0);
else
{
if(brdr[x][y-1] ==brdr[7][35]) //if the postion of * is at target location then user wins the match
{
system("CLS");
goto lose;
}
brdr[x][y+1] ='*'; //basically puts a space before and shifts the * to y+1 postion
y=y+1;
}
}
else if(input =='a')//if input is a the charachter moves left
{
brdr[x][y] =' ';
if(brdr[x][y-1] == '|'||brdr[x][y-1] == '@')
exit(0);
else
{
if(brdr[x][y-1] ==brdr[7][35])//if the postion of * is at target location then user wins the match
{
system("CLS");
goto lose;
exit(0);
}
brdr[x][y-1] ='*';//basically puts a space before and shifts the * to y-1 postion
y=y-1;
}
}
else if(input =='s')//if input is a the charachter moves down
{
brdr[x][y] =' ';
if(brdr[x+1][y] =='-'|| brdr[x+1][y] =='@')//if the postion of * is at target location then user wins the match
exit(0);
else
{
if(brdr[x+1][y] ==brdr[7][35]) //if the postion of * is at target location then user wins the match
{
system("CLS");
goto lose;
}
brdr[x+1][y] ='*';//basically puts a space before and shifts the * to x+1 postion
x=x+1;
}
}
else if(input =='w')//if input is w the charachter moves up
{
brdr[x][y] =' ';
if(brdr[x-1][y] =='-'||brdr[x-1][y] =='@')//if the postion of * is at target location then user wins the match
exit(0);
else
{
if(brdr[x-1][y] ==brdr[7][35]) //if the postion of * is at target location then user wins the match
{
system("CLS");
goto lose;
}
}
brdr[x-1][y] ='*';//basically puts a space before and shifts the * to x-1 postion
x=x-1;
}
count = count - 1;
if(input=='b')
exit(0);
if(count == -1)
{
system("CLS");
exit(0);
}
system("CLS");
}
lose:
{
system("CLS");
cout<<"WINNER";
}
return 0;
getch();
}