我正在制作一款游戏,允许你选择要对抗的玩家数量;我们使用玩家数量来创建一个玩家轮次枚举,然后我们会继续进行。
enum MetaGamePhase{
ChoosePlayerCount,
ConfirmLibrary,
ChooseFirstTurn,
InitialDraw,
MulliganChoice,
ActiveGame,
EndGame,
DeclareWinner,
None
}
// need to set the contents of this based on the players choosing the player count
enum Turn{
Player1,
Player2,
Player3,
}
enum Action {
ProgressPlayerTurn
}
fn reducer(mut state: GameState, action: Action) -> GameState {
match action{
Action::ProgressPlayerTurn => GameState{
turn: {
use Turn::*;
// will also need to set this dynamically based on the enum
match state.turn {
Player1 => Player2,
Player2 => Player3,
Player3 => Player1,
}
},
..state
}
}
}
struct GameState{
turn: Turn,
meta_game_phase: MetaGamePhase
}
我该如何在 Rust 中做到这一点?
答案是你不能这样做,你应该使用不同的语言功能。