qt: Change enum sound_t to enum class GameSound

This commit is contained in:
Calcitem 2020-12-29 15:35:11 +08:00
parent 8831c0b607
commit 0915ed57af
2 changed files with 67 additions and 67 deletions

View File

@ -430,7 +430,7 @@ void Game::setSound(bool arg)
#endif // TRAINING_MODE #endif // TRAINING_MODE
} }
void Game::playSound(sound_t soundType, Color c) void Game::playSound(GameSound soundType, Color c)
{ {
string soundDir = ":/sound/resources/sound/"; string soundDir = ":/sound/resources/sound/";
string sideStr = c == BLACK ? "B" : "W"; string sideStr = c == BLACK ? "B" : "W";
@ -438,80 +438,80 @@ void Game::playSound(sound_t soundType, Color c)
string filename; string filename;
switch (soundType) { switch (soundType) {
case GAME_SOUND_BLOCK_MILL: case GameSound::blockMill:
filename = "BlockMill_" + sideStr + ".wav"; filename = "BlockMill_" + sideStr + ".wav";
break; break;
case GAME_SOUND_REMOVE: case GameSound::remove:
filename = "Remove_" + oppenentStr + ".wav"; filename = "Remove_" + oppenentStr + ".wav";
break; break;
case GAME_SOUND_SELECT: case GameSound::select:
filename = "Select.wav"; filename = "Select.wav";
break; break;
case GAME_SOUND_DRAW: case GameSound::draw:
filename = "Draw.wav"; filename = "Draw.wav";
break; break;
case GAME_SOUND_DROG: case GameSound::drog:
filename = "drog.wav"; filename = "drog.wav";
break; break;
case GAME_SOUND_BANNED: case GameSound::banned:
filename = "forbidden.wav"; filename = "forbidden.wav";
break; break;
case GAME_SOUND_GAME_START: case GameSound::gameStart:
filename = "GameStart.wav"; filename = "GameStart.wav";
break; break;
case GAME_SOUND_RESIGN: case GameSound::resign:
filename = "Resign_" + sideStr + ".wav"; filename = "Resign_" + sideStr + ".wav";
break; break;
case GAME_SOUND_LOSS: case GameSound::loss:
filename = "loss.wav"; filename = "loss.wav";
break; break;
case GAME_SOUND_MILL: case GameSound::mill:
filename = "Mill_" + sideStr + ".wav"; filename = "Mill_" + sideStr + ".wav";
break; break;
case GAME_SOUND_MILL_REPEATLY: case GameSound::millRepeatly:
filename = "MillRepeatly_" + sideStr + ".wav"; filename = "MillRepeatly_" + sideStr + ".wav";
break; break;
case GAME_SOUND_MOVE: case GameSound::move:
filename = "move.wav"; filename = "move.wav";
break; break;
case GAME_SOUND_NEW_GAME: case GameSound::newGame:
filename = "newgame.wav"; filename = "newgame.wav";
break; break;
case GAME_SOUND_NEXT_MILL: case GameSound::nextMill:
filename = "NextMill_" + sideStr + ".wav"; filename = "NextMill_" + sideStr + ".wav";
break; break;
case GAME_SOUND_OBVIOUS: case GameSound::obvious:
filename = "Obvious.wav"; filename = "Obvious.wav";
break; break;
case GAME_SOUND_REPEAT_THREE_DRAW: case GameSound::repeatThreeDraw:
filename = "RepeatThreeDraw.wav"; filename = "RepeatThreeDraw.wav";
break; break;
case GAME_SOUND_SIDE: case GameSound::side:
filename = "Side_" + sideStr + ".wav"; filename = "Side_" + sideStr + ".wav";
break; break;
case GAME_SOUND_STAR: case GameSound::star:
filename = "Star_" + sideStr + ".wav"; filename = "Star_" + sideStr + ".wav";
break; break;
case GAME_SOUND_SUFFOCATED: case GameSound::suffocated:
filename = "Suffocated_" + sideStr + ".wav"; filename = "Suffocated_" + sideStr + ".wav";
break; break;
case GAME_SOUND_VANTAGE: case GameSound::vantage:
filename = "Vantage.wav"; filename = "Vantage.wav";
break; break;
case GAME_SOUND_VERY: case GameSound::very:
filename = "Very.wav"; filename = "Very.wav";
break; break;
case GAME_SOUND_WARNING: case GameSound::warning:
filename = "warning.wav"; filename = "warning.wav";
break; break;
case GAME_SOUND_WIN: case GameSound::win:
if (c == DRAW) { if (c == DRAW) {
filename = "Draw.wav"; filename = "Draw.wav";
} else { } else {
filename = "Win_" + sideStr + ".wav"; filename = "Win_" + sideStr + ".wav";
} }
break; break;
case GAME_SOUND_WIN_AND_LOSSES_ARE_OBVIOUS: case GameSound::winAndLossesAreObvious:
filename = "WinsAndLossesAreObvious.wav"; filename = "WinsAndLossesAreObvious.wav";
break; break;
default: default:
@ -747,7 +747,7 @@ void Game::timerEvent(QTimerEvent *event)
// 播放音效 // 播放音效
#ifndef DONOT_PLAY_WIN_SOUND #ifndef DONOT_PLAY_WIN_SOUND
playSound(GAME_SOUND_WIN, winner); playSound(GameSound::win, winner);
#endif #endif
#endif // TRAINING_MODE #endif // TRAINING_MODE
} }
@ -855,10 +855,10 @@ bool Game::actionPiece(QPointF pos)
if (position.put_piece(file, rank)) { if (position.put_piece(file, rank)) {
if (position.get_action() == Act::remove) { if (position.get_action() == Act::remove) {
// 播放成三音效 // 播放成三音效
playSound(GAME_SOUND_MILL, position.side_to_move()); playSound(GameSound::mill, position.side_to_move());
} else { } else {
// 播放移动棋子音效 // 播放移动棋子音效
playSound(GAME_SOUND_DROG, position.side_to_move()); playSound(GameSound::drog, position.side_to_move());
} }
result = true; result = true;
break; break;
@ -873,22 +873,22 @@ bool Game::actionPiece(QPointF pos)
break; break;
if (position.select_piece(file, rank)) { if (position.select_piece(file, rank)) {
// 播放选子音效 // 播放选子音效
playSound(GAME_SOUND_SELECT, position.side_to_move()); playSound(GameSound::select, position.side_to_move());
result = true; result = true;
} else { } else {
// 播放禁止音效 // 播放禁止音效
playSound(GAME_SOUND_BANNED, position.side_to_move()); playSound(GameSound::banned, position.side_to_move());
} }
break; break;
case Act::remove: case Act::remove:
if (position.remove_piece(file, rank)) { if (position.remove_piece(file, rank)) {
// 播放音效 // 播放音效
playSound(GAME_SOUND_REMOVE, position.side_to_move()); playSound(GameSound::remove, position.side_to_move());
result = true; result = true;
} else { } else {
// 播放禁止音效 // 播放禁止音效
playSound(GAME_SOUND_BANNED, position.side_to_move()); playSound(GameSound::banned, position.side_to_move());
} }
break; break;
@ -923,7 +923,7 @@ bool Game::actionPiece(QPointF pos)
Color winner = position.get_winner(); Color winner = position.get_winner();
if (winner != NOBODY && if (winner != NOBODY &&
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) (manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
playSound(GAME_SOUND_WIN, winner); playSound(GameSound::win, winner);
#endif #endif
// AI设置 // AI设置
@ -970,7 +970,7 @@ bool Game::resign()
} }
if (position.get_winner() != NOBODY) { if (position.get_winner() != NOBODY) {
playSound(GAME_SOUND_RESIGN, position.side_to_move()); playSound(GameSound::resign, position.side_to_move());
} }
#endif // TRAINING_MODE #endif // TRAINING_MODE
@ -998,15 +998,15 @@ bool Game::command(const string &cmd, bool update /* = true */)
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
// 声音 // 声音
sound_t soundType = GAME_SOUND_NONE; GameSound soundType = GameSound::none;
switch (position.get_action()) { switch (position.get_action()) {
case Act::select: case Act::select:
case Act::place: case Act::place:
soundType = GAME_SOUND_DROG; soundType = GameSound::drog;
break; break;
case Act::remove: case Act::remove:
soundType = GAME_SOUND_REMOVE; soundType = GameSound::remove;
break; break;
default: default:
break; break;
@ -1028,8 +1028,8 @@ bool Game::command(const string &cmd, bool update /* = true */)
sideToMove = position.side_to_move(); sideToMove = position.side_to_move();
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
if (soundType == GAME_SOUND_DROG && position.get_action() == Act::remove) { if (soundType == GameSound::drog && position.get_action() == Act::remove) {
soundType = GAME_SOUND_MILL; soundType = GameSound::mill;
} }
if (update) { if (update) {
@ -1070,7 +1070,7 @@ bool Game::command(const string &cmd, bool update /* = true */)
Color winner = position.get_winner(); Color winner = position.get_winner();
if (winner != NOBODY && if (winner != NOBODY &&
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) { (manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) {
playSound(GAME_SOUND_WIN, winner); playSound(GameSound::win, winner);
} }
#endif #endif
#endif // TRAINING_MODE #endif // TRAINING_MODE

View File

@ -46,33 +46,33 @@
using namespace std; using namespace std;
enum sound_t enum class GameSound
{ {
GAME_SOUND_NONE, none,
GAME_SOUND_BLOCK_MILL, blockMill,
GAME_SOUND_REMOVE, remove,
GAME_SOUND_SELECT, select,
GAME_SOUND_DRAW, draw,
GAME_SOUND_DROG, drog,
GAME_SOUND_BANNED, banned,
GAME_SOUND_GAME_START, gameStart,
GAME_SOUND_RESIGN, resign,
GAME_SOUND_LOSS, loss,
GAME_SOUND_MILL, mill,
GAME_SOUND_MILL_REPEATLY, millRepeatly,
GAME_SOUND_MOVE, move,
GAME_SOUND_NEW_GAME, newGame,
GAME_SOUND_NEXT_MILL, nextMill,
GAME_SOUND_OBVIOUS, obvious,
GAME_SOUND_REPEAT_THREE_DRAW, repeatThreeDraw,
GAME_SOUND_SIDE, side,
GAME_SOUND_STAR, star,
GAME_SOUND_SUFFOCATED, suffocated,
GAME_SOUND_VANTAGE, vantage,
GAME_SOUND_VERY, very,
GAME_SOUND_WARNING, warning,
GAME_SOUND_WIN, win,
GAME_SOUND_WIN_AND_LOSSES_ARE_OBVIOUS winAndLossesAreObvious
}; };
class Game : public QObject class Game : public QObject
@ -227,7 +227,7 @@ public slots:
void setSound(bool arg = true); void setSound(bool arg = true);
// 播放声音 // 播放声音
static void playSound(sound_t soundType, Color c); static void playSound(GameSound soundType, Color c);
// 是否必败时认输 // 是否必败时认输
void setResignIfMostLose(bool enabled); void setResignIfMostLose(bool enabled);