/// <summary> /// Player removes follower from tile. /// </summary> /// <param name="player">Color of player making the move.</param> /// <param name="coords">Coordinates of tile where follower is placed.</param> /// <exception cref="GameException">Exeption describing the error.</exception> public void RemoveFollower(PlayerColor player, Coords coords) { // Check if correct player is making the request if (CurrentGameState.Params.PlayerOrder[CurrentGameState.CurrentPlayerIndex] != player) { throw new NotOnMoveException(); } // Check if it is correct time to place a tile if (CurrentGameState.CurrentPhase != GamePhase.TILE_PLACED) { throw new WrongMovePhaseException(); } // Retrieve the follower placement var correctFollowers = CurrentGameState.PlacedFollowers.Where(f => f.Color == player && f.TileCoords == coords).ToList(); // Check if exactly one place is found if (correctFollowers.Count() != 1) { throw new IncorrectFollowerCoordsException(); } // Retrieve the score var score = GridExplorer.GetPointsForFollower(CurrentGameState.Grid, coords, correctFollowers[0].RegionId, forceOpen: false); // Remove the follower CurrentGameState.PlacedFollowers.Remove(correctFollowers[0]); CurrentGameState.Grid[coords].PlacedFollower = null; CurrentGameState.Scores[player] += score; FollowerRemovedEvent.Invoke(player, coords, score); // Also finish the move FinishMove(); }
/// <summary> /// Finishes the game. /// </summary> private void FinishGame() { // Retrieve remaining followers FollowerPlacement[] remaining = new FollowerPlacement[CurrentGameState.PlacedFollowers.Count]; CurrentGameState.PlacedFollowers.CopyTo(remaining); // Remove remaining followers foreach (var fp in remaining) { // Retrieve the score var score = GridExplorer.GetPointsForFollower(CurrentGameState.Grid, fp.TileCoords, fp.RegionId, forceOpen: true); // Remove the follower CurrentGameState.Scores[fp.Color] += score; FollowerRemovedEvent.Invoke(fp.Color, fp.TileCoords, score); } // Notify about end of the game and change state type CurrentGameState.CurrentPhase = GamePhase.GAME_OVER; GameEndedEvent.Invoke(); }