Unreal Snake Game 1.0.0
Types.h
1// Snake Game, Copyright LifeEXE. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "SnakeGame/Containers/List.h"
7
8namespace SnakeGame
9{
10
11struct SNAKEGAME_API Dim
12{
13 uint32 width;
14 uint32 height;
15};
16
17struct SNAKEGAME_API Position
18{
19 Position(uint32 inX, uint32 inY) : x(inX), y(inY) {}
20 Position() = default;
21
22 uint32 x{0};
23 uint32 y{0};
24
25 FORCEINLINE Position& operator+=(const Position& rhs)
26 {
27 x += rhs.x;
28 y += rhs.y;
29 return *this;
30 }
31
32 FORCEINLINE bool operator==(const Position& rhs) const { return x == rhs.x && y == rhs.y; }
33 FORCEINLINE bool IsEqual(const Position& rhs) const { return x == rhs.x && y == rhs.y; }
34
35 static const Position Zero;
36};
37
38struct SNAKEGAME_API Input
39{
40 int8 x; /* possible values: (-1, 0, 1) */
41 int8 y; /* possible values: (-1, 0, 1) */
42
43 FORCEINLINE bool opposite(const Input& rhs) const //
44 {
45 return (x == -rhs.x && x != 0) || (y == -rhs.y && y != 0);
46 }
47
48 static const Input Default;
49};
50
51enum class CellType
52{
53 Empty = 0,
54 Wall,
55 Snake,
56 Food
57};
58
59struct SNAKEGAME_API Settings
60{
61 Dim gridDims{40, 10};
62 struct Snake
63 {
64 uint32 defaultSize{4};
65 Position startPosition{0, 0};
66 } snake;
67 float gameSpeed{1.0f};
68};
69
70using TSnakeList = TDoubleLinkedList<Position>;
71using TPositionPtr = TSnakeList::TDoubleLinkedListNode;
72
73enum class GameplayEvent
74{
75 GameOver = 0,
76 GameCompleted,
77 FoodTaken
78};
79
80using GameplayEventCallback = TFunction<void(GameplayEvent)>;
81
82} // namespace SnakeGame
Definition: Food.h:12
Definition: Snake.h:11
Definition: SnakeGame.Build.cs:6
Definition: Types.h:12
Definition: Types.h:39
Definition: Types.h:18
Definition: Types.h:63
Definition: Types.h:60