示例#1
0
 public void Update(KaroGameManager manager, MouseClick click)
 {
     IEnumerable<MoveWrapper> legalMoves = manager.FindLegalMoves(manager.CurrentPlayer);
     MoveWrapper move = legalMoves.FirstOrDefault(m =>
         m.GetFromCell() == manager.CurrentMove.GetFromCell() &&
         m.GetToCell() == manager.CurrentMove.GetToCell() &&
         m.HasUsedCell() &&
         m.GetUsedCell() == new Vector2DWrapper(click.Position.X, click.Position.Y));
     if (move != null)
     {
         CommunicationProtocolConversionUtility util = new CommunicationProtocolConversionUtility(manager.Game);
         //Debug.WriteLine(util.MoveWrapperToString(move));
         Debug.WriteLine(util.TurnToString(util.ConvertMoveToTurn(move)));
         // We now have a valid move. Execute it!
         Debug.WriteLine("Clicked on moveable tile.");
         manager.ExecuteMove(move);
         manager.CurrentMove = null;
         if (!(manager.CurrentState is ComputerState) && !(manager.CurrentState is WaitForUndoState))
         {
             manager.ChangeState(PieceSourceState.Instance);
         }
     }
     else
     {
         // Clicked on invalid tile. Back to PieceSourceState.
         Debug.WriteLine("Clicked on a non moveable tile.");
         manager.SendMoveIsNotValid();
         manager.CurrentMove = null;
         manager.ChangeState(PieceSourceState.Instance);
     }
 }
示例#2
0
文件: PlaceState.cs 项目: Bakkes/Karo
        public void Update(KaroGameManager manager, MouseClick click)
        {
            IEnumerable<MoveWrapper> legalMoves = manager.FindLegalMoves(manager.CurrentPlayer);
            MoveWrapper move = legalMoves.FirstOrDefault(m =>
                m.GetToCell() == new Vector2DWrapper(click.Position.X, click.Position.Y));

            // We have a valid move.
            if (move != null)
            {

                Debug.WriteLine(move.GetToCell());
                CommunicationProtocolConversionUtility util = new CommunicationProtocolConversionUtility(manager.Game);
                Debug.WriteLine(util.TurnToString(util.ConvertMoveToTurn(move)));

                manager.ExecuteMove(move);
                Debug.WriteLine("Placed a new piece.");

            }
            else
            {
                manager.SendMoveIsNotValid();
                Debug.WriteLine("Can't place a new piece");
            }

            // Change state to Piece source state if all 6 pieces are on the board.
            if (manager.Board.GetOccupiedCells().Count == MaxPieceCount)
            {
                if (!(manager.CurrentState is ComputerState) && !(manager.CurrentState is WaitForUndoState))
                {
                    Debug.WriteLine("All {0} pieces are placed at the board.", MaxPieceCount);
                    manager.ChangeState(PieceSourceState.Instance);
                }
            }
        }
示例#3
0
 public void Enter(KaroGameManager manager)
 {
     _timer = new Timer();
     _timer.Elapsed += delegate { Finished(manager); };
     _timer.AutoReset = true;
     _timer.Interval = 1000;
     _timer.Start();
 }
示例#4
0
        public void Enter(KaroGameManager manager)
        {
            Debug.WriteLine("Entering ComputerState...");

            Thread ExecuteThread = new Thread(ExecuteMoveThread);
            _manager = manager;
            ExecuteThread.Start();
        }
示例#5
0
        public void Update(KaroGameManager manager, MouseClick click)
        {
            IEnumerable<MoveWrapper> legalMoves = manager.FindLegalMoves(manager.CurrentPlayer);
            // Get the move with the correct source tile from the last click.
            IEnumerable<MoveWrapper> sourceLegalMoves = legalMoves.Where(m =>
                m.GetFromCell() == manager.CurrentMove.GetFromCell());

            // Get the move (if it exists) with the correct destination tile.
            MoveWrapper move = sourceLegalMoves.FirstOrDefault(m =>
                m.GetToCell() == new Vector2DWrapper(click.Position.X, click.Position.Y));

            if (move != null)
            {
                var usedTile = move.HasUsedCell();
                Debug.WriteLine("Clicked on valid destination");
                // Check if the destination tile exists or if a tile has to be moved.
                if (move.HasUsedCell())
                {
                    Debug.WriteLine("Empty tile must be moved to destination");
                    manager.CurrentMove = move;
                    manager.ChangeState(CellSourceState.Instance);
                }
                // Valid move, execute it.
                else
                {
                    Debug.WriteLine("Moving tile at {0} to {1}",
                        move.GetFromCell(), move.GetToCell());
                    manager.ExecuteMove(move);

                    CommunicationProtocolConversionUtility util = new CommunicationProtocolConversionUtility(manager.Game);
                    Debug.WriteLine(util.TurnToString(util.ConvertMoveToTurn(move)));

                    if (!(manager.CurrentState is ComputerState) && !(manager.CurrentState is WaitForUndoState))
                    {
                        manager.ChangeState(PieceSourceState.Instance);
                    }
                    //Debug.WriteLine(move.GetToCell());
                }
            }
            else
            {

                // Clicked on invalid destination tile. Get rid of the current
                // move and go back to PieceSourceState.
                Debug.WriteLine("Can't move selected piece to tile.", click);
                manager.SendMoveIsNotValid();
                manager.CurrentMove = null;
                manager.ChangeState(PieceSourceState.Instance);
            }
        }
示例#6
0
 public void Update(KaroGameManager manager, MouseClick click)
 {
     if (click.Button != MouseButton.RIGHT)
     {
         return;
     }
     manager.UndoLastMove();
     if (manager.Board.GetOccupiedCells().Count == 12)
     {
         manager.ChangeState(PieceSourceState.Instance);
     }
     else
     {
         manager.ChangeState(PlaceState.Instance);
     }
 }
示例#7
0
        public void Update(KaroGameManager manager, MouseClick click)
        {
            IEnumerable<MoveWrapper> legalMoves = manager.FindLegalMoves(manager.CurrentPlayer);

            // See if there is any move with the same source as the clicked tile.
            MoveWrapper move = legalMoves.FirstOrDefault(m =>
                m.GetFromCell() == new Vector2DWrapper(click.Position.X, click.Position.Y));

            // Valid source piece clicked, save the move.
            if (move != null)
            {
                Debug.WriteLine("Valid source piece selected");
                manager.CurrentMove = move;
                manager.ChangeState(PieceDestinationState.Instance);
            }
            else
            {
                Debug.WriteLine("Clicked tile does not have a moveable piece");
            }
        }
示例#8
0
 private void Finished(KaroGameManager manager)
 {
     _timer.Stop();
     manager.ChangeState(ComputerState.Instance);
 }
示例#9
0
 public void Exit(KaroGameManager manager)
 {
     _timer.Stop();
 }
示例#10
0
 public void Exit(KaroGameManager manager)
 {
     Debug.WriteLine("Exiting PieceDestinationState...");
 }
示例#11
0
 public void Exit(KaroGameManager manager)
 {
     Debug.WriteLine("Exiting TileSourceState...");
 }
示例#12
0
 public void Enter(KaroGameManager manager)
 {
     Debug.WriteLine("Entering PieceSourceState...");
 }
示例#13
0
 /// <summary>
 /// ComputerState doesn't listen to clickevents. The entry method will
 /// do everything AI related.
 /// </summary>
 public void Update(KaroGameManager manager, MouseClick click)
 {
 }
示例#14
0
 public void Exit(KaroGameManager manager)
 {
     Debug.WriteLine("Exiting ComputerState...");
 }