-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chaosfreak93
committed
Mar 11, 2021
0 parents
commit d0c5070
Showing
53 changed files
with
2,925 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Project exclude paths | ||
/cmake-build-release/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.17) | ||
project(Game) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
add_executable(Game main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#include <iostream> | ||
#include <conio.h> | ||
#include <windows.h> | ||
|
||
using namespace std; | ||
|
||
bool walls = false; | ||
bool gameOver; | ||
const int width = 20; | ||
const int height = 20; | ||
int x, y, fruitX, fruitY, score; | ||
int tailX[100], tailY[100]; | ||
int nTail; | ||
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN }; | ||
eDirection dir; | ||
|
||
void Setup() { | ||
srand((unsigned int) time(0)); | ||
gameOver = false; | ||
dir = STOP; | ||
x = width / 2; | ||
y = height / 2; | ||
fruitX = rand() % width; | ||
fruitY = rand() % height; | ||
score = 0; | ||
} | ||
|
||
void GameOver() { | ||
gameOver = true; | ||
Sleep(50); | ||
system("cls"); | ||
cout << "Game Over!" << endl; | ||
cout << "Score: " << score << endl; | ||
} | ||
|
||
void Draw() { | ||
while (!gameOver) { | ||
system("cls"); | ||
for (int i = 0; i < width + 2; i++) | ||
cout << "#"; | ||
cout << endl; | ||
|
||
for (int i = 0; i < height; i++) { | ||
for (int j = 0; j < width; j++) { | ||
if (j == 0) | ||
cout << "#"; | ||
|
||
if (i == y && j == x) | ||
cout << "O"; | ||
else if (i == fruitY && j == fruitX) | ||
cout << "F"; | ||
else { | ||
bool print = false; | ||
for (int k = 0; k < nTail; k++) { | ||
if (tailX[k] == j && tailY[k] == i) { | ||
cout << "o"; | ||
print = true; | ||
} | ||
} | ||
if (!print) | ||
cout << " "; | ||
} | ||
|
||
if (j == width - 1) | ||
cout << "#"; | ||
} | ||
cout << endl; | ||
} | ||
|
||
for (int i = 0; i < width + 2; i++) | ||
cout << "#"; | ||
cout << endl; | ||
cout << "Score: " << score << endl; | ||
cout << "Copyright Yan-Luca L." << endl; | ||
} | ||
} | ||
|
||
void Input() { | ||
while (!gameOver) { | ||
if (_kbhit()) { | ||
switch (_getch()) { | ||
case 'a': | ||
dir = LEFT; | ||
break; | ||
case 'd': | ||
dir = RIGHT; | ||
break; | ||
case 'w': | ||
dir = UP; | ||
break; | ||
case 's': | ||
dir = DOWN; | ||
break; | ||
case 'x': | ||
GameOver(); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void Logic() { | ||
while (!gameOver) { | ||
int prevX = tailX[0]; | ||
int prevY = tailY[0]; | ||
int prev2X, prev2Y; | ||
tailX[0] = x; | ||
tailY[0] = y; | ||
for (int i = 1; i < nTail; i++) { | ||
prev2X = tailX[i]; | ||
prev2Y = tailY[i]; | ||
tailX[i] = prevX; | ||
tailY[i] = prevY; | ||
prevX = prev2X; | ||
prevY = prev2Y; | ||
} | ||
switch (dir) { | ||
case LEFT: | ||
x--; | ||
Sleep(150); | ||
break; | ||
case RIGHT: | ||
x++; | ||
Sleep(150); | ||
break; | ||
case UP: | ||
y--; | ||
Sleep(150); | ||
break; | ||
case DOWN: | ||
y++; | ||
Sleep(150); | ||
break; | ||
default: | ||
break; | ||
} | ||
if (x > width || x < 0 || y > height || y < 0) { | ||
if (walls) { | ||
GameOver(); | ||
} else { | ||
if (x >= width) | ||
x = 0; | ||
else if (x < 0) | ||
x = width - 1; | ||
|
||
if (y >= height) | ||
y = 0; | ||
else if (y < 0) | ||
y = height - 1; | ||
} | ||
} | ||
|
||
for (int i = 0; i < nTail; i++) | ||
if(tailX[i] == x && tailY[i] == y) | ||
GameOver(); | ||
|
||
if (x == fruitX && y == fruitY) { | ||
srand((unsigned int) time(0)); | ||
score += 10; | ||
fruitX = rand() % width; | ||
fruitY = rand() % height; | ||
nTail++; | ||
} | ||
} | ||
} |
Oops, something went wrong.