-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDino.cpp
94 lines (93 loc) · 1.84 KB
/
Dino.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
#include<iostream>
#include<conio.h>
#include<windows.h>
using namespace std;
const int width=25;
const int height=8;
int dinox,x;
char dinoy[2];
int treey,score;
bool gameover;
void setup(){
cout<<"\n \t \t \t__________________________________________________________________"<<endl;
cout<<" \t \t \t|\t \t \t Chrome Dino Game \t \t \t |"<<endl;
cout<<" \t \t \t|\t \t \t Made by Wajahat Ali \t \t \t |"<<endl;
cout<<" \t \t \t|________________________________________________________________|"<<endl;
cout<<"\n \t \t \t \t > Press SpaceBar to jump \t \t \t \t"<<endl;
cout<<"\t \t \t \t Press enter to start"<<endl;
gameover=false;
dinox=6;
dinoy[0]=3;
dinoy[1]=3;
treey=25;
x=0,score=0;
cin.get();
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
bool showFlag=false;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = showFlag; // set the cursor visibility
SetConsoleCursorInfo(out, &cursorInfo);
}
void layout(){
system("cls");
cout<<"\n \n \n \n"<<endl;
for(int i=0;i<height;i++)
{ cout<<"\t \t \t \t";
for(int j=0;j<width;j++)
{
if((i==6 && j==treey) || (i==5 && j==treey)){
cout<<"$"<<" ";
}
else if(i==height-1)
{
cout<<"-"<<"-";
}else if(i==dinox && j==dinoy[0] || i==dinox-1 && j==dinoy[1])
{
cout<<"O"<<" ";
}else{
cout<<" ";
}
}
cout<<endl;
}
cout<<"\n \t \t \t \t Score: "<<score<<endl;
}
void logic(){
if(_kbhit())
{
if(dinox>2 && x<4)
{
dinox-=1;
x++;
}
}
if(x==4){
dinox+=1;
if(dinox==6)
{
x=0;
while(kbhit()) getch();
}
}
treey-=1.5;
if((dinoy[0]==treey && (dinox==6 || dinox==5)) || (dinoy[1]==treey && (dinox==6 || dinox==5)))
{
layout();
gameover=true;
}
if(treey<2)
{
treey=25;
score+=10;
}
}
int main(){
setup();
while(!gameover)
{
layout();
logic();
Sleep(28);
}
}