Beispiel #1
0
 private bool isValidMove(Movement move, string playerId)
 {
     //if (Moves.Count == 0)
     //{
     //    return true;
     //}
     //else
     //{
     //    Movement lastMove = Moves.Values.LastOrDefault();
     //    if (lastMove == null)
     //    {
     //        return true;
     //    }
     //    else
     //    {
     //        if (lastMove.Piece == move.Piece)
     //        {
     //            return false;
     //        }
     //        else
     //        {
     //            return true;
     //        }
     //    }
     //}
     return true;
 }
Beispiel #2
0
        public bool AddMove(Movement move,string playerId)
        {
            if (move == null)
            {
                return false;
            }

            Player replyTo = null;
            Player from = null;
            if (this.Player1.Id != playerId)
            {
                replyTo = this.Player1;
                from = this.Player2;
            }
            else
            {
                replyTo = this.Player2;
                from = this.Player1;
            }

            if (!isValidMove(move, playerId))
            {
                NotificationEventArgs<string> args = new NotificationEventArgs<string>();
                args.Message = "Impossible. Invalid move!";
                RaiseErrorOccurred(args);
                return false;
            }
            else
            {
                move.Player = from;
                Board[move.X, move.Y] = move.Piece;
                Moves.Add(Moves.Count, move);
                RaisePlayerHasMoved(new NotificationEventArgs<Movement>(replyTo.Id, from.Nick + move.ToString(), move));

                if (this.IsWon())
                {
                    this.Winner = from;
                    Result = GameResult.PlayerWon;
                }
                else if(this.IsDraw())
                {
                    this.Winner = null;
                    Result = GameResult.Draw;
                }
                return true;
            }
        }