-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (73 loc) · 1.7 KB
/
Copy pathmain.cpp
File metadata and controls
88 lines (73 loc) · 1.7 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
#include <iostream>
#include "SimpleDraw.h"
#include "Fruit.h"
#include "Snake.h"
#include <string>
#include <Windows.h>
#define IDI_ICON1 //i added an icon to this app because it makes me happy
void HideConsole()
{
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
void ShowConsole()
{
::ShowWindow(::GetConsoleWindow(), SW_SHOW);
}
using namespace std;
int main()
{
HideConsole();
setWindowSize(510, 535); //i changed these values because the window overlaps with the background
bool screenFailFlag = false;
bool selfFailFlag = false;
Fruit fruit;
Snake snake;
fruit.spawn(snake.getX(), snake.getY());
cout << "Score: " << snake.getScore(); //initialization of some things
while (getMouseButton() != '1')
{
useBrush(1, RGB(0, 0, 0));
drawRectangle(0, 0, 500, 500); //clear screen
fruit.draw();
snake.draw();
if (snake.eat(fruit))
{
system("cls");
cout << "Score: " << snake.getScore() << endl;
fruit.spawn(snake.getX(), snake.getY());
}
if (snake.screenFail(500, 500))
{
screenFailFlag = true;
break;
}
if (snake.selfFail())
{
selfFailFlag = true;
break;
}
snake.move();
Sleep(75);
if (getKey() == 'P')
{
while (getKey() == 'P')
{
}
}//yes, you can pause the game now
}
if (screenFailFlag)
{
drawText(150, 200, "Fail! You have touched a wall");
drawText(150, 215, "Press Left Mouse Button To Quit");
while (getMouseButton() != 1);
return 0;
}
else if (selfFailFlag)
{
drawText(150, 200, "Fail! You have touched yourself");
drawText(150, 215, "Press Left Mouse Button To Quit");
while (getMouseButton() != 1);
return 0;
}
return 0;
}