예제 #1
0
 public void ExecuteRequest(DraughtsInput input)
 {
     if (input is DraughtsInputKickRequest)
     {
         DraughtsInputKickRequest kr = (DraughtsInputKickRequest)input;
         var stone = FindStone(kr.X, kr.Y);
         if (stone != null)
         {
             stone.IsDead = true;
             stone.X      = -1;
             stone.Y      = -1; // so that FindStone is not in trouble about 2 stones on a field
         }
     }
     else if (input is DraughtsInputMoveRequest)
     {
         DraughtsInputMoveRequest mv = (DraughtsInputMoveRequest)input;
         var stone = FindStone(mv.FromX, mv.FromY);
         if (stone != null)
         {
             stone.X = mv.ToX;
             stone.Y = mv.ToY;
         }
     }
     else if (input is DraughtsInputPromoteRequest)
     {
         DraughtsInputPromoteRequest pr = (DraughtsInputPromoteRequest)input;
         var stone = FindStone(pr.X, pr.Y);
         if (stone != null)
         {
             stone.IsQueen = true;
         }
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            _board.Draw();
            DraughtsInput input = null;

            while (!((input = _reader.Read()) is DraughtsInputQuitRequest))
            {
                _board.ExecuteRequest(input);
                _board.Draw();
            }
        }
예제 #3
0
 public void ExecuteRequest(DraughtsInput input)
 {
     if (input is DraughtsInputKickRequest)
     {
         DraughtsInputKickRequest kr = (DraughtsInputKickRequest)input;
         var stone = FindStone(kr.X, kr.Y);
         if (stone != null)
         {
             stone.IsDead = true;
         }
     }
 }
예제 #4
0
        public void ExecuteRequest(DraughtsInput input)
        {
            Stone stone = null;

            if (input is IRequestHasPositionInformation)
            {
                IRequestHasPositionInformation infoStone = (IRequestHasPositionInformation)input;
                stone = FindStone(infoStone.X, infoStone.Y);
                if (stone == null)
                {
                    return;
                }

                if (BoardHasChanged != null)
                {
                    BoardHasChanged.Invoke(this, EventArgs.Empty);
                }
            }

            if (input is DraughtsInputKickRequest)
            {
                stone.IsDead = true;
                stone.X      = -1;
                stone.Y      = -1; // so that FindStone is not in trouble about 2 stones on a field

                if (BoardHasChanged != null)
                {
                    BoardHasChanged.Invoke(this, EventArgs.Empty);
                }
            }
            else if (input is DraughtsInputMoveRequest)
            {
                DraughtsInputMoveRequest mv = (DraughtsInputMoveRequest)input;

                stone.X = mv.ToX;
                stone.Y = mv.ToY;

                if (BoardHasChanged != null)
                {
                    BoardHasChanged.Invoke(this, EventArgs.Empty);
                }
            }
            else if (input is DraughtsInputPromoteRequest)
            {
                stone.IsQueen = true;

                if (BoardHasChanged != null)
                {
                    BoardHasChanged.Invoke(this, EventArgs.Empty);
                }
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            Board = new Board();

            DraughtsInput input = null;

            Board.BoardHasChanged += BoardOnBoardHasChanged;

            Board.Draw();
            while (!((input = _reader.Read()) is DraughtsInputQuitRequest))
            {
                Board.ExecuteRequest(input);
            }

            Board.Dispose();
            Board = null;
        }