-
Notifications
You must be signed in to change notification settings - Fork 0
/
snack (2).cpp
137 lines (114 loc) · 3.2 KB
/
snack (2).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
#include<iostream>
#include<conio.h>
#include<windows.h>
#include<time.h>
using namespace std;
void set(int x,int y);
void fruit();
void border();
int a,b,c,d=0,s=0,k=20,l=10,score=0,tail=0,i;
int *p=&a;
void input()
{
if(kbhit())
{
switch(getch())
{
case 'd':
p=&a;
d=0;
break;
case 's':
p=&b;
d=0;
break;
case 'w':
p=&b;
d=1;
break;
case 'a':
p=&a;
d=1;
break;
case 'x':
s=1;
break;
}
}
}
void snack()
{ Sleep(60);
if(d!=1)
{ *p=*p+1;
system("cls");
}
else
{
*p=*p-1;
system("cls");
}
set(10+a,10+b);
cout<<"0 ";
if(10+a>=24 || 10+a<=0 )
{ Sleep(20);
s=1;
}
else if(10+b>=14 || 10+b<=0)
{ Sleep(20);
s=1;
}
if(10+a==k && 10+b==l)
{ score=score+1;
srand(time(0));
k=rand()%20+1;
l=rand()%10+1;
}
}
void set(int x,int y)
{ HANDLE handle;
COORD coor;
handle=GetStdHandle(STD_OUTPUT_HANDLE);
coor.X=x;
coor.Y=y;
SetConsoleCursorPosition(handle,coor);
}
void fruit()
{
set(k,l);
cout<<"$";
} //114 14//
void border()
{ set(0,0);
cout<<"#########################\n"
<<"#\t\t\t# Score:"<<score<<"\n"
<<"#\t\t\t# \n"
<<"#\t\t\t#\n"
<<"#\t\t\t# Rwtgaming (;\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t#\n"
<<"#\t\t\t# Ankit Rawat :) \n"
<<"#########################################";
}
int main()
{
while(s!=1)
{ border();
input();
snack();
fruit();
}
system("cls");
cout<<"Game Over :("<<endl<<"wait..";
getch();
Sleep(2000);
cout<<"Your score is:"<<score<<endl<<"see you again! subscribe RWT gaming "<<endl<<endl<<"press any button to exit :)";
getch();
return 0;
}