private bool MovePlayer(Player player, IDiceRoll roll) { // check if the game is still playable if (!this.IsGameActive) { // TODO: do we throw an invalid move here? return(false); } // get the player's position var position = player.Position; // see if we can move him var newPosition = position.Location + roll.Roll; if (newPosition > BoardLength) { OnInvalidMove?.Invoke(player, roll.Roll, newPosition); return(false); } // and if we can, check for events if (newPosition == BoardLength) { OnGameWon?.Invoke(player); IsGameActive = false; } // update the player's position player.Position = new Position(newPosition); return(true); }
/// <summary> /// Handles the invalid move packet /// </summary> /// <param name="inMsg">The message to decode</param> private void HandleInvalidMove(NetIncomingMessage inMsg) { GameMove move = GameMove.Decode(inMsg, myKnownPlayers); string reason = inMsg.ReadString(); OnInvalidMove?.Invoke(this, move.Move, reason); }
private void HandleInvalidMove() { var reason = lobbyReader.ReadString(); var move = GameMove.Decode(lobbyReader, ConnectedServer.Players); OnInvalidMove.Invoke(move.Move, reason); }
public override void Move(Direction direction) { var currentLocation = Location; if (CanMove(direction)) { currentLocation.UnsubscribePlayerFromEvents(EventHandler); base.Move(direction); OnValidMove?.Invoke(Location, direction); Location.SubscribePlayerToEvents(EventHandler); } else { OnInvalidMove?.Invoke(); } }