Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
184 lines (169 loc) · 4.88 KB
/
Copy pathmain.cpp
File metadata and controls
184 lines (169 loc) · 4.88 KB
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<windows.h>
#define H 21
#define W 51
using namespace std;
int collection=0;
bool game_end=false;
int py=1,px=1;
int e1y=1,e1x=W-3;
int e2y=H-2,e2x=1;
void draw_playfield(char playfield[][W])
{
cout<<"\n";
for(int i=0;i<H;i++)
{
cout<<"\t";
for(int j=0;j<W;j++)
{
cout<<playfield[i][j];
}
cout<<"\n";
}
cout<<"\t ebratul and limon your score is "<<collection<<endl;
}
void setup(char playfield[][W])
{
for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++)
{
if(playfield[i][j]=='#')
{
playfield[i][j]=' ';
}
if(playfield[i][j]=='@')
{
playfield[i][j]='.';
}
}
}
if(playfield[py][px]=='.')
{
collection++;
}
if(playfield[py][px]=='*')
{
py=1;
px=1;
}
playfield[py][px]='#';
playfield[e1y][e1x]='@';
playfield[e2y][e2x]='@';
if(playfield[py][px]=='@')
{
game_end= true;
}
}
void result()
{
system("cls");
if(collection ==670)
{
cout<<"\n\n\n\n";
cout<<"\t\t\t congratulation! EBRATUL AND LIMON\n";
cout<<"\t\t\t you won the game!\n";
cout<<"\t\t\t your total score is:"<<collection<<endl;
}
else {
cout<<"\n\n\n\n\n";
cout<<"\t\t\t hello ,Ebratul and Limon ,you lost the game!\n";
cout<<"\t\t\t your total score is :"<<collection<<endl;
}
}
void enemymove()
{
if(e1y==1&&e1x>1)
{
e1x--;
}
else if(e1x==1&& e1y<10)
{
e1y++;
}
else if(e1y==10 && e1x<W-3)
{
e1x++;
}
else if(e1x==W-3 && e1y>1)
{
e1y--;
}
if(e2y==H-2&& e2x<W-3)
{
e2x++;
}
else if(e2x==W-3&&e2y>10)
{
e2y--;
}
else if(e2y==10&&e2x>1)
{
e2x--;
}
else if(e2x==1&& e2y<H-2)
{
e2y++;
}
}
void playermove()
{
char ch;
if(kbhit())
{
ch=getch();
switch(ch)
{
case 72:
py--;
break;
case 80:
py++;
break;
case 75:
px--;
break;
case 77:
px++;
break;
}
}
}
int main()
{
char playfield[H][W]={
"**************************************************",
"*................................................*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*................................................*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*.....*.....*.....*.....*.....*.....*.....*......*",
"*................................................*",
"**************************************************",
};
while(!game_end)
{
system("cls");
setup(playfield);
playermove();
enemymove();
draw_playfield(playfield);
Sleep(20);
}
result();
return 0;
}