-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
68 lines (60 loc) · 1.13 KB
/
main.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
#include<iostream>
#include<sstream>
#include<string>
#include "olcConsoleGameEngine.h"
#include "Field.h"
class SnakeApp : public olcConsoleGameEngine
{
private:
Field field;
int mapSize;
public:
SnakeApp(int mapSize);
~SnakeApp();
// Óíàñëåäîâàíî ÷åðåç olcConsoleGameEngine
virtual bool OnUserCreate() override;
virtual bool OnUserUpdate(float fElapsedTime) override;
};
using namespace std;
SnakeApp::SnakeApp(int mapSize) : field(mapSize)
{
this->mapSize = mapSize;
}
SnakeApp::~SnakeApp()
{
}
bool SnakeApp::OnUserCreate()
{
return true;
}
bool SnakeApp::OnUserUpdate(float fElapsedTime)
{
short currentKey = -1;
for (int i = 0;i < 256;i++)
{
if (m_keys[i].bPressed)
{
currentKey = i;
break;
}
}
char** map = field.UpdateMap(currentKey, fElapsedTime);
for (int x = 0; x < mapSize; x++)
{
for (int y = 0; y < mapSize; y++)
{
Draw(x, y, map[x][y]);
}
}
return true;
}
int main()
{
const int mapSize = 20;
SnakeApp game(mapSize);
// Create a console with resolution 160x100 characters
// Each character occupies 8x8 pixels
game.ConstructConsole(mapSize, mapSize, 16, 16);
game.Start();
return 0;
}