forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.h
101 lines (72 loc) · 2.05 KB
/
Game.h
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
95
96
97
98
99
100
//--------------------------------------------------------------------------------------
// Game.h
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include "FrontPanel\FrontPanelDisplay.h"
enum DotState
{
Empty,
Food,
Filled,
};
struct Dot
{
Dot(int x, int y)
: State(DotState::Empty)
, X(x)
, Y(y)
{};
DotState State;
int X;
int Y;
};
class GameBoard
{
public:
GameBoard(ATG::FrontPanelDisplay &display);
void Render() const;
void SpawnFood();
void SetDotState(std::shared_ptr<Dot> dot, DotState state);
std::shared_ptr<Dot> GetDot(int x, int y);
private:
static const int GAME_BOARD_LEFT = 256 / 4 + 2;
static const int GAME_BOARD_TOP = 2;
static const int GAME_BOARD_DOT_SIZE = 4;
static const int GAME_BOARD_WIDTH = (254 - GAME_BOARD_LEFT) / GAME_BOARD_DOT_SIZE;
static const int GAME_BOARD_HEIGHT = (62 - GAME_BOARD_TOP) / GAME_BOARD_DOT_SIZE;
static const int GAME_BOARD_OUTLINE_LEFT = GAME_BOARD_LEFT - 1;
static const int GAME_BOARD_OUTLINE_TOP = GAME_BOARD_TOP - 1;
static const int GAME_BOARD_OUTLINE_WIDTH = GAME_BOARD_WIDTH * GAME_BOARD_DOT_SIZE + 2;
static const int GAME_BOARD_OUTLINE_HEIGHT = GAME_BOARD_HEIGHT * GAME_BOARD_DOT_SIZE + 2;
ATG::FrontPanelDisplay &frontPanelDisplay;
std::vector<std::shared_ptr<Dot>> blankDots;
std::shared_ptr<Dot> gameBoard[GAME_BOARD_WIDTH][GAME_BOARD_HEIGHT];
};
enum SnakeMoveResult
{
Move,
Fail,
Eat,
};
class Snake
{
public:
Snake(
std::shared_ptr<GameBoard> board,
int directionX,
int directionY,
int startX,
int startY);
void SetDirection(int x, int y);
SnakeMoveResult Move();
private:
std::shared_ptr<GameBoard> gameBoard;
std::list<std::shared_ptr<Dot>> Body;
int DirectionX;
int DirectionY;
int BackwardsDirectionX;
int BackwardsDirectionY;
};