#include <bits/stdc++.h>
#include <conio.h>
#include <windows.h>
const int WIDTH = 50;
const int HEIGHT = 10;
const char DINO = 'T';
const char CACTUS = '|';
const char BIRD = '^';
const char EMPTY = ' ';
const char HART='*';
bool gameOver;
int dinoPos;
int cactusPos;
int birdPos;
int hartPos;
int score;
int hart;
void Setup() {
gameOver = false;
dinoPos = HEIGHT - 2;
cactusPos = WIDTH - rand()%10;
birdPos = WIDTH - rand()%50;
hartPos=rand()%1000;
score = 0;
hart=1;
}
void Draw() {
system("cls");
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
if (i == dinoPos && j == 1) {
std::cout << DINO;
}
else if (i == HEIGHT - 1 && j == cactusPos) {
std::cout << CACTUS;
}
else if (i == HEIGHT - 3 && j == birdPos) {
std::cout << BIRD;
}
else if (i == HEIGHT-2 && j == hartPos) {
std::cout << HART;
hartPos+=rand()%1000;
}
else {
std::cout << EMPTY;
}
}
std::cout << std::endl;
}
std::cout << "*Score: " << score << std::endl;
std::cout<<"*Hart: "<<hart<<std::endl;
std::cout<<std::endl;
std::cout<<" //Press 'w' to jump"<<std::endl;
std::cout<<" //Press 'a' to high jump"<<std::endl;
std::cout<<" //Press 'd' to run"<<std::endl;
std::cout<<" //Press 's' to go down"<<std::endl;
score++;
}
void Input() {
if (_kbhit()) {
char key = _getch();
if (key == 'w' && dinoPos == HEIGHT - 2) {
dinoPos = HEIGHT - 8;
}
else if(key=='a'&&dinoPos == HEIGHT - 2){
dinoPos = HEIGHT - 16;
}
else if(key=='d'){
cactusPos -= 20;
birdPos -= 20;
}
else if(key=='s'){
dinoPos=HEIGHT-2;
}
}
}
void Logic() {
if (dinoPos < HEIGHT - 2) {
dinoPos++;
}
cactusPos--;
birdPos-=2;
hartPos--;
if (cactusPos < 0) {
cactusPos = WIDTH - 1;
}
if (birdPos < 0) {
birdPos = WIDTH - 1;
}
if(hartPos<0){
hartPos=WIDTH-1;
}
if ((cactusPos == 1 && dinoPos == HEIGHT - 2) || (birdPos == 1 && dinoPos == HEIGHT - 4)) {
hart--;
if(hart<=0){
gameOver=true;
}
}
if(hartPos == 1 && dinoPos == HEIGHT - 2){
hart++;
}
}
int main() {
int cnt=0;
int s=100;
srand(time(0));
Setup();
while (!gameOver) {
Draw();
Input();
Logic();
Sleep(s);
if(cnt%50==0){
cnt=0;
birdPos = WIDTH - rand()%50;
}
cnt++;
if(score%100==0){
s+=50;
}
if(s>=225){
s=225;
}
}
std::cout << "Game Over! Final Score: " << score << std::endl;
return 0;
}