-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.cpp
More file actions
71 lines (56 loc) · 1.87 KB
/
World.cpp
File metadata and controls
71 lines (56 loc) · 1.87 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
#include "World.h"
#include <Log/Log.h>
#include <PlayerLogic.h>
#include <UI/UI.h>
#include <WorldLogic.h>
#include <array>
World::World(WorldLogic& logic)
: state_init(logic),
state_game(logic),
state_caculate_scores(logic),
_logic{logic} {
state_init.Transition([](auto&) { return ui().IsIdle(); }, &state_game);
state_init.SetEnter(
[](WorldLogic& world) { INFO("**** BEGIN INIT GAME ****"); });
state_init.SetExit(
[](WorldLogic& world) { INFO("**** END INIT GAME ****"); });
state_game.SetEnter(
[](WorldLogic& world) { INFO("**** BEGIN PLAY GAME ****"); });
state_game.SetExit(
[](WorldLogic& world) { INFO("**** END PLAY GAME ****"); });
state_game.Transition(
[](const WorldLogic& world) {
return ui().IsIdle() &&
world.GetPlayers().All([](const PlayerLogic& player) {
return player.IsIdle();
});
},
&state_caculate_scores);
state_caculate_scores.SetEnter([this](WorldLogic& logic) {
INFO("**** CALCULATE SCORE POINTS ****");
logic.GetPlayers().ForEach(
[](PlayerLogic& player) { player.ExecuteEndGamePerks(); });
state_init.Reset();
state_game.Reset();
_started = false;
logic.EndGame();
});
state_caculate_scores.Transition(
[](const WorldLogic& world) {
return ui().IsIdle() &&
world.GetPlayers().All([](const PlayerLogic& player) {
return player.IsIdle();
});
},
&state_init);
current = &state_init;
}
void World::Update() {
if (!_started) {
_started = true;
current->Enter();
}
if (current) {
current = current->Update();
}
}