public override void HandleOrder(IOrderHandler sender, Order handledOrder) { lock (stateMutex) { switch (handledOrder) { case RegisterSuccessfulOrder order: player1.SearchOpponent(player2.PlayerType); orderHandler.HandleOrder(sender, order); break; case OpponentFoundOrder order: OpponentFoundOrder opponentFoundOrder = order; player2.Name = opponentFoundOrder.OpponentName; orderHandler.HandleOrder(sender, order); break; case GameReadyOrder order: orderHandler.HandleOrder(sender, order); break; case GameStartedOrder order: orderHandler.HandleOrder(sender, order); break; case OpponentAvatarChangedOrder order: player2.AvatarId = order.AvatarID; orderHandler.HandleOrder(sender, order); break; case UpdateGameStateOrder order: orderHandler.HandleOrder(sender, order); break; case GameEndedOrder order: orderHandler.HandleOrder(sender, order); break; } } }
public override void HandleOrder(IOrderHandler sender, Order handledOrder) { lock (stateMutex) { switch (handledOrder) { case RegisterSuccessfulOrder order: if (!load) { if (player1.PlayerState == player2.PlayerState && player2.PlayerState == PlayerState.REGISTERED) { player1.SearchOpponent(player2.PlayerType); player2.SearchOpponent(player1.PlayerType); } } else { if (player1.PlayerState == PlayerState.REGISTERED) { player1.Load(); } else if (player2.PlayerState == PlayerState.REGISTERED) { player2.JoinGame(loadedGameID); } else { Console.Error.WriteLine("[LocalGameHandler] - Can't load a game"); } } orderHandler.HandleOrder(sender, order); break; case OpponentFoundOrder order: if (player1.PlayerState == player2.PlayerState && player1.PlayerState == PlayerState.BINDED) { orderHandler.HandleOrder(sender, order); } break; case GameReadyOrder order: readyToNextState++; if (player1.PlayerState == player2.PlayerState && player1.PlayerState == PlayerState.LOBBY_CHOICE && readyToNextState == 2) { readyToNextState = 0; orderHandler.HandleOrder(sender, order); } break; case GameStartedOrder order: if (player1.PlayerState == PlayerState.MY_TURN && player2.PlayerState == PlayerState.OPPONENT_TURN || player1.PlayerState == PlayerState.OPPONENT_TURN && player2.PlayerState == PlayerState.MY_TURN) { orderHandler.HandleOrder(sender, order); } break; case UpdateGameStateOrder order: orderHandler.HandleOrder(sender, order); break; case GameEndedOrder order: if (duplicatedGameEnded) { orderHandler.HandleOrder(sender, order); } duplicatedGameEnded = !duplicatedGameEnded; break; case SaveResponseOrder order: orderHandler.HandleOrder(sender, order); break; case LoadResponseOrder order: loadedGameID = order.GameID; orderHandler.HandleOrder(sender, order); break; case OpponentAvatarChangedOrder order: // Nothing -> no need to update imagePlayer in local game break; } } }