public SimpleMaze(WorldState state, MazePlayer firstPlayer, MazePlayer secondPlayer) { mazeField = mazeGenerator.Generate(31, 21); this.state = state; GameId = Guid.NewGuid(); this.firstPlayer = firstPlayer; this.secondPlayer = secondPlayer; secondPlayer.SetStart(mazeField.Field.GetLength(1) - 1, mazeField.Field.GetLength(0) - 1); timer = new Timer(x => state.InputQueue.Post(new GameUpdate(GameId)), new object(), 100, 100); }
private static void SendPosition(MazePlayer player, MazePlayer enemyPlayer) { if (player.IsLeft) { return; } player.Output.Post(new PlayerPosCommand { myPos = player.GetPos(), enemyPos = enemyPlayer.GetPos() }); }
public void SendState(MazePlayer player) { if (player.IsLeft) { return; } if (IsFinished == false) { var enemy = GetEnemy(player); var command = new MazeFieldCommand { field = mazeField.Field, me = new MazeFieldCommandPlayer { name = player.Name, rating = player.Rating.RoundValue }, enemy = new MazeFieldCommandPlayer { name = enemy.Name, rating = enemy.Rating.RoundValue } }; player.Output.Post(command); } else { var enemy = GetEnemy(player); player.Output.Post(new GameOverCommand { status = player.IsWin ? GameOverCommand.Statuses.Win : GameOverCommand.Statuses.Lose, ratings = state.Players.Select(x => new GameOverCommandRating { name = x.Value.Name, rating = x.Value.Rating.RoundValue, isMe = x.Key == player.Id, isEnemy = x.Key == enemy.Id }) .OrderByDescending(x => x.rating) .ThenBy(x => x.name) .ToArray() }); } }
private MazePlayer GetEnemy(MazePlayer player) { if (player == firstPlayer) { return(secondPlayer); } if (player == secondPlayer) { return(firstPlayer); } throw new Exception("Это не наш игрок!"); }