Exemplo n.º 1
0
        /// <summary>
        /// If the human move is valid, plays one computer turn
        /// </summary>
        /// <param name="shape"></param>
        private void PlayComputer(ShapePawn shape)
        {
            bool res = mEngine.PlayHuman(shape.FromL + 1, shape.FromC + 1, shape.ToL + 1, shape.ToC + 1);

            if (res)
            {
                shape.OriginalLocation = shape.Location;

                if (mEngine.CheckHumanWon())
                {
                    MessageBox.Show("You Won!", "Game Over", MessageBoxButtons.OK);
                    EndGame(false);
                }
                else
                {
                    this.Cursor = Cursors.WaitCursor;
                    mLocked     = true;

                    ThreadPool.QueueUserWorkItem(new WaitCallback(PlayCompAsync));
                }
            }
            else
            {
                shape.Location = shape.OriginalLocation;
            }

            RedrawBoard();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize the pieces list
        /// </summary>
        /// <param name="pawns"></param>
        private void InitPawns(Pawn[] pawns)
        {
            mListShapes = new List <ShapeBase>();

            for (int i = 0; i < pawns.Length; i++)
            {
                ShapePawn s = new ShapePawn();

                if (pawns[i] != Pawn.Empty && pawns[i] != Pawn.None)
                {
                    int a = i % 8;
                    int b = (int)Math.Floor(i / 8.0);

                    s.IsDragged        = true;
                    s.Location         = new Point(FormXSpace + CellSpace + CellSize * a, FormYSpace + CellSpace + CellSize * b);
                    s.OriginalLocation = s.Location;
                    s.IsSelected       = false;
                    s.IsDragged        = false;
                    s.Locked           = mLocked;

                    if (pawns[i] == Pawn.KingX || pawns[i] == Pawn.KingO)
                    {
                        s.IsKing = true;
                    }
                    else
                    {
                        s.IsKing = false;
                    }

                    if (pawns[i] == Pawn.X || pawns[i] == Pawn.KingX)
                    {
                        s.Moveable = false;
                        if (mHumanStart)
                        {
                            s.Color = Brushes.White;
                        }
                        else
                        {
                            s.Color = Brushes.Red;
                        }
                    }
                    else
                    {
                        s.Moveable = true;
                        if (!mHumanStart)
                        {
                            s.Color = Brushes.White;
                        }
                        else
                        {
                            s.Color = Brushes.Red;
                        }
                    }

                    mListShapes.Add(s);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// If the human move is valid, plays one computer turn
        /// </summary>
        /// <param name="shape"></param>
        private void PlayComputer(ShapePawn shape)
        {
            bool res = mEngine.PlayHuman(shape.FromL + 1, shape.FromC + 1, shape.ToL + 1, shape.ToC + 1);

            if (res)
            {
                shape.OriginalLocation = shape.Location;

                if (mEngine.CheckHumanWon())
                {
                    MessageBox.Show("You Won!", "Game Over", MessageBoxButtons.OK);
                    EndGame(false);
                }
                else
                {
                    this.Cursor = Cursors.WaitCursor;
                    mLocked = true;

                    ThreadPool.QueueUserWorkItem(new WaitCallback(PlayCompAsync));
                }
            }
            else
            {
                shape.Location = shape.OriginalLocation;
            }

            RedrawBoard();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize the pieces list
        /// </summary>
        /// <param name="pawns"></param>
        private void InitPawns(Pawn[] pawns)
        {
            mListShapes = new List<ShapeBase>();

            for (int i = 0; i < pawns.Length; i++)
            {
                ShapePawn s = new ShapePawn();

                if (pawns[i] != Pawn.Empty && pawns[i] != Pawn.None)
                {
                    int a = i % 8;
                    int b = (int)Math.Floor(i / 8.0);

                    s.IsDragged = true;
                    s.Location = new Point(FormXSpace + CellSpace + CellSize * a, FormYSpace + CellSpace + CellSize * b);
                    s.OriginalLocation = s.Location;
                    s.IsSelected = false;
                    s.IsDragged = false;
                    s.Locked = mLocked;

                    if (pawns[i] == Pawn.KingX || pawns[i] == Pawn.KingO)
                    {
                        s.IsKing = true;
                    }
                    else
                    {
                        s.IsKing = false;
                    }

                    if (pawns[i] == Pawn.X || pawns[i] == Pawn.KingX)
                    {
                        s.Moveable = false;
                        if (mHumanStart) s.Color = Brushes.White;
                        else s.Color = Brushes.Red;
                    }
                    else
                    {
                        s.Moveable = true;
                        if (!mHumanStart) s.Color = Brushes.White;
                        else s.Color = Brushes.Red;
                    }

                    mListShapes.Add(s);
                }
            }
        }