Skip to content

Commit 9de5e71

Browse files
committed
Using enum class for player types instead of MACRO.
This might eliminate some future problems.
1 parent 392068a commit 9de5e71

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

source/game.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void Game::Paint()
217217
case GAME_SCREEN:
218218
GameScreen(true);
219219
// AI
220-
if(RoundFinished == false && WTTPlayer[CurrentPlayer].GetType() == PLAYER_CPU)
220+
if(RoundFinished == false && WTTPlayer[CurrentPlayer].GetType() == playerType::CPU)
221221
{ // AI
222222
if(AIThinkLoop > (rand() % 10 + 20))
223223
{
@@ -592,17 +592,17 @@ bool Game::ControllerManager()
592592
switch(SelectedButton)
593593
{
594594
case 0:
595-
WTTPlayer[1].SetType(PLAYER_HUMAN);
595+
WTTPlayer[1].SetType(playerType::Human);
596596
GameMode = gameMode::VsHuman1;
597597
ChangeScreen(GAME_SCREEN);
598598
break;
599599
case 1:
600-
WTTPlayer[1].SetType(PLAYER_CPU);
600+
WTTPlayer[1].SetType(playerType::CPU);
601601
GameMode = gameMode::VsAI;
602602
ChangeScreen(GAME_SCREEN);
603603
break;
604604
case 2:
605-
WTTPlayer[1].SetType(PLAYER_HUMAN);
605+
WTTPlayer[1].SetType(playerType::Human);
606606
GameMode = gameMode::VsHuman2;
607607
ChangeScreen(GAME_SCREEN);
608608
break;
@@ -827,10 +827,9 @@ void Game::PrintWrapText(u16 x, u16 y, u16 maxLineWidth,
827827
u32 ShadowColor, s8 OffsetX, s8 OffsetY)
828828
{
829829
std::string tmp = input + " "; // Make local copy
830-
std::string tmp2;
831-
std::string::iterator startIndex = tmp.begin(),
832-
lastSpace = tmp.begin(),
833-
i = tmp.begin();
830+
std::string::iterator startIndex = tmp.begin();
831+
std::string::iterator lastSpace = tmp.begin();
832+
std::string::iterator i = tmp.begin();
834833
int ypos = y;
835834
int z = 0;
836835
int textLeft;
@@ -840,6 +839,7 @@ void Game::PrintWrapText(u16 x, u16 y, u16 maxLineWidth,
840839
{
841840
if(*i == L' ')
842841
{
842+
std::string tmp2;
843843
z = GRRLIB_WidthTTF(DefaultFont, tmp2.assign(startIndex, i).c_str(), fontSize);
844844

845845
if(z >= maxLineWidth)

source/player.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
Player::Player() :
77
Score(0),
8-
Type(PLAYER_HUMAN)
8+
Type(playerType::Human)
99
{
1010
}
1111

@@ -74,7 +74,7 @@ void Player::ResetScore()
7474
* Set the player type.
7575
* @param[in] AType Give the type of player.
7676
*/
77-
void Player::SetType(u8 AType)
77+
void Player::SetType(playerType AType)
7878
{
7979
Type = AType;
8080
}
@@ -83,7 +83,7 @@ void Player::SetType(u8 AType)
8383
* Get the player type.
8484
* @return Player type.
8585
*/
86-
u8 Player::GetType()
86+
playerType Player::GetType()
8787
{
8888
return Type;
8989
}

source/player.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
#include <gctypes.h>
1111
#include <string>
1212

13-
#define PLAYER_HUMAN 0 /**< Identify a human player. */
14-
#define PLAYER_CPU 1 /**< Identify a computer player. */
13+
/**
14+
* Types of player.
15+
*/
16+
enum class playerType : u8 {
17+
Human, /**< Identify a human player. */
18+
CPU /**< Identify a computer player. */
19+
};
1520

1621
/**
1722
* This class is used managed players.
@@ -29,13 +34,13 @@ class Player
2934
unsigned int GetScore();
3035
void IncScore();
3136
void ResetScore();
32-
void SetType(u8);
33-
u8 GetType();
37+
void SetType(playerType);
38+
playerType GetType();
3439
private:
3540
unsigned int Score;
3641
std::string Name;
3742
u8 Sign;
38-
u8 Type;
43+
playerType Type;
3944
};
4045
//---------------------------------------------------------------------------
4146
#endif

0 commit comments

Comments
 (0)