forked from rtpHarry/Sokoban
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SokobanLevelManager.cpp
149 lines (118 loc) · 3.2 KB
/
SokobanLevelManager.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <Windows.h>
#include ".\sokobanlevelmanager.h"
SokobanLevelManager::SokobanLevelManager(void)
{
}
SokobanLevelManager::~SokobanLevelManager(void)
{
}
// Setup the level manager
void SokobanLevelManager::Setup(void)
{
LevelSet NewSet;
NewSet.LoadSLCFile(".\\levels\\original.slc");
m_Episodes.push_back(NewSet);
NewSet.LoadSLCFile(".\\levels\\Dimitri-Yorick.slc");
m_Episodes.push_back(NewSet);
NewSet.LoadSLCFile(".\\levels\\MicroCosmos.slc");
m_Episodes.push_back(NewSet);
m_CurrentEpisode = 0;
m_CurrentLevel = 0;
}
// Get the first level in the game
EncodedLevel SokobanLevelManager::GetNewGameLevel(void)
{
// reset iterators to first level / first episode
// this is done by the menu system (URGH!)
//m_CurrentEpisode = 0;
//m_CurrentLevel = 0;
// return the level
return m_Episodes[m_CurrentEpisode].m_Levels[m_CurrentLevel];
}
// Get the next available level in this episode
EncodedLevel SokobanLevelManager::GetNextLevel(void)
{
if (m_CurrentLevel < (m_Episodes[m_CurrentEpisode].m_Levels.size() - 1))
{
m_CurrentLevel++;
}
return m_Episodes[m_CurrentEpisode].m_Levels[m_CurrentLevel];
}
// Get the previous level in this episode
EncodedLevel SokobanLevelManager::GetPrevLevel(void)
{
if (m_CurrentLevel != 0)
{
m_CurrentLevel--;
}
return m_Episodes[m_CurrentEpisode].m_Levels[m_CurrentLevel];
}
// Get the current level
EncodedLevel SokobanLevelManager::GetCurrentLevel(void)
{
return m_Episodes[m_CurrentEpisode].m_Levels[m_CurrentLevel];
}
// Get the first level in the next available episode
EncodedLevel SokobanLevelManager::GetNextEpisode(void)
{
if (m_CurrentEpisode < (m_Episodes.size() - 1))
{
m_CurrentEpisode++;
}
m_CurrentLevel = 0;
return m_Episodes[m_CurrentEpisode].m_Levels[m_CurrentLevel];
}
// Get the first level in the previous episode
EncodedLevel SokobanLevelManager::GetPrevEpisode(void)
{
// change episode
if (m_CurrentEpisode != 0)
{
m_CurrentEpisode--;
}
// reset level
m_CurrentLevel = 0;
return m_Episodes[m_CurrentEpisode].m_Levels[m_CurrentLevel];
}
// Get a unique string that will identify the level
string SokobanLevelManager::GetLevelIDString(void)
{
string LevelID;
LevelID = m_Episodes[m_CurrentEpisode].m_EpisodeName;
LevelID += "\\";
LevelID += m_Episodes[m_CurrentEpisode].m_Levels[m_CurrentLevel].m_LevelName;
return LevelID;
}
// Get a list of all the names of the episodes
vector<EpisodeInfo> SokobanLevelManager::GetEpisodeInfo(void)
{
vector<EpisodeInfo> ActiveEpisodes;
// build the list
vector<LevelSet>::iterator ii;
for(ii=m_Episodes.begin(); ii!=m_Episodes.end(); ii++)
{
EpisodeInfo ThisEpisode;
ThisEpisode.EpisodeName = (*ii).m_EpisodeName;
ThisEpisode.NumberOfLevels = (*ii).m_Levels.size();
ActiveEpisodes.push_back(ThisEpisode);
}
return ActiveEpisodes;
}
// Get the total number of active episodes
int SokobanLevelManager::GetActiveEpisodeTotal(void)
{
return m_Episodes.size() - 1;
}
// Set the current active episode
void SokobanLevelManager::SetActiveEpisode(int NewActiveEpisode)
{
// new episode within valid range
if((NewActiveEpisode > m_Episodes.size()) || (NewActiveEpisode < 0))
{
// just abort
return;
}
// set the episode
m_CurrentEpisode = NewActiveEpisode;
m_CurrentLevel = 0;
}