Unreal Snake Game 1.0.0
Game.h
1// Snake Game, Copyright LifeEXE. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Types.h"
7#include "Utils.h"
8
9namespace SnakeGame
10{
11
12class Grid;
13class Snake;
14class Food;
15
16class SNAKEGAME_API Game
17{
18public:
19 Game(const Settings& settings, const IPositionRandomizerPtr& randomizer = MakeShared<PositionRandomizer>());
20
25 TSharedPtr<Grid> grid() const { return m_grid; }
26
31 TSharedPtr<Snake> snake() const { return m_snake; }
32
37 TSharedPtr<Food> food() const { return m_food; }
38
44 void update(float deltaSeconds, const Input& input);
45
46 uint32 score() const { return m_score; }
47
48 float gameTime() const { return m_gameTime; }
49
50 void subscribeOnGameplayEvent(GameplayEventCallback callback);
51
52private:
53 const Settings c_settings;
54 TSharedPtr<Grid> m_grid;
55 TSharedPtr<Snake> m_snake;
56 TSharedPtr<Food> m_food;
57
58 float m_moveSeconds{0.0f};
59 bool m_gameOver{false};
60 uint32 m_score{0};
61 float m_gameTime{0.0f};
62
63 TArray<GameplayEventCallback> m_gameplayEventCallbacks;
64
65 void updateGrid();
66 bool updateTime(float deltaSeconds);
67 bool died(const Position& prevTailPosition) const;
68
69 void generateFood();
70 bool foodTaken() const;
71
72 FORCEINLINE void dispatchEvent(GameplayEvent Event);
73};
74} // namespace SnakeGame
Definition: Game.h:17
TSharedPtr< Snake > snake() const
Definition: Game.h:31
TSharedPtr< Food > food() const
Definition: Game.h:37
TSharedPtr< Grid > grid() const
Definition: Game.h:25
Definition: SnakeGame.Build.cs:6
Definition: Types.h:39
Definition: Types.h:60