示例#1
0
 public override AttackResult Attack(GamePiece defender)
 {
     if (defender.Type == GamePieceType.Bomb)
     {
         return AttackResult.Win;
     }
     return base.Attack(defender);
 }
示例#2
0
        public override AttackResult Attack(GamePiece defender)
        {
            if (defender.Type == GamePieceType.One)
                return AttackResult.Win;
            if (defender.Type == GamePieceType.Spy)
                return AttackResult.Tie;

            return AttackResult.Lose;
        }
示例#3
0
        public virtual AttackResult Attack(GamePiece defender)
        {
            switch(Math.Sign(defender.Type - Type)) {
                case -1:
                    return AttackResult.Lose;
                case 0:
                    return AttackResult.Tie;

            }

            return AttackResult.Win;
        }
示例#4
0
        public bool PlacePiece(Guid player, GamePiece piece, Point to)
        {
            if (game.GetTurn() == PlayerTurn.Setup)
            {
                bool playerIsRed = GetPlayerIsRed(player);
                if (playerIsRed)
                {
                    piece |= GamePiece.Red;
                }
                else
                {
                    piece &= ~GamePiece.Red;
                }

                return game.PlacePiece(piece, to);
            }

            return false;
        }
示例#5
0
 public GameState()
 {
     Board = new GamePiece[10, 10];
     Turn = PlayerTurn.Setup;
     Bank = new PieceBank();
 }
示例#6
0
        public bool IsValidMove(GamePiece Piece, Point from, Point to)
        {
            if (this.IsOver)
            {
                return false;
            }

            if (to.x < 0 || to.x > 9 || to.y < 0 || to.y > 9)
            {
                return false;
            }

            int deltaX = to.x - from.x;
            int deltaY = to.y - from.y;

            if (Piece.IsRed && state.Turn != PlayerTurn.Red || !Piece.IsRed && state.Turn == PlayerTurn.Red)
            {
                return false;
            }

            if (Piece.Type == GamePieceType.Bomb || Piece.Type == GamePieceType.Flag || Piece.Type == GamePieceType.Block)
            {
                return false;
            }

            if (GetPiece(to) != null && GetPiece(to).IsRed == Piece.IsRed)
            {
                return false;
            }

            if (deltaX != 0 && deltaY != 0)
            {
                return false;
            }

            //Nine Movement
            if (Piece.Type == GamePieceType.Nine)
            {
                Point offset = new Point(Math.Sign(deltaX), Math.Sign(deltaY));

                while ((from += offset) != to)
                {
                    if (GetPiece(from) != null)
                    {
                        return false;
                    }
                }
            }
            else
            {
                //Check for multiple move
                if (Math.Abs(deltaX) > 1 || Math.Abs(deltaY) > 1)
                {
                    return false;
                }
            }

            var destination = GetPiece(to);
            if (destination == null)
            {
                return true;
            }
            if (destination.Type == GamePieceType.Block || destination.IsRed == Piece.IsRed)
            {
                return false;
            }

            return true;
        }
示例#7
0
 public override AttackResult Attack(GamePiece defender)
 {
     throw new Exception("Flags can not attack!");
 }
示例#8
0
 internal void ReturnPiece(GamePiece Piece)
 {
     var b = (Piece.IsRed) ? redBank : bank;
     b[Piece.Type].Add(Piece);
 }
示例#9
0
文件: Game1.cs 项目: smelch/Stratego
 private void ShowAttack(GamePiece attacker, GamePiece defender)
 {
     LastAttacker = attacker;
     LastDefender = defender;
 }
示例#10
0
文件: Game1.cs 项目: smelch/Stratego
 private void PickUpPiece(GamePiece piece, Action<int, int> callback)
 {
     ActivePiece = piece;
     PieceDropAction = callback;
 }
示例#11
0
文件: Game1.cs 项目: smelch/Stratego
        private void HandleMouseForBoard(MouseState state)
        {
            int x = state.X / GRID_SIZE;
            int y = state.Y / GRID_SIZE;

            PickUpPiece(stratego.GetPiece(new Stratego.Core.Point(x, y)), (X, Y) => {
                if (stratego.GetTurn() == PlayerTurn.Setup)
                {
                    stratego.RemovePiece(new Stratego.Core.Point(x, y));
                    if (!stratego.PlacePiece(ActivePiece.Type, ActivePiece.IsRed, new Stratego.Core.Point(X, Y)))
                    {
                        stratego.PlacePiece(ActivePiece.Type, ActivePiece.IsRed, new Stratego.Core.Point(x, y));
                        ActivePiece = null;
                    }
                }
                else
                {
                    if (stratego.IsValidMove(ActivePiece, new Stratego.Core.Point(x, y), new Stratego.Core.Point(X, Y)))
                    {
                        var piece = stratego.GetPiece(new Stratego.Core.Point(X, Y));
                        if (piece != null)
                        {
                            ShowAttack(ActivePiece, piece);
                        }
                        stratego.Move(new Stratego.Core.Point(x, y), new Stratego.Core.Point(X, Y));
                    }
                }
            });
        }
示例#12
0
文件: Game1.cs 项目: smelch/Stratego
        private void HandleMouse()
        {
            MouseState state = Mouse.GetState();
            if (state.LeftButton == ButtonState.Pressed)
            {
                if (!mouseDown)
                {
                    mouseDown = true;
                    if (state.Y >= 0 && state.Y <= 480)
                    {
                        if (state.X >= 500)
                        {
                            HandleMouseForBank(state);
                        }
                        else if (state.X >= 0 && state.X <= 480)
                        {
                            HandleMouseForBoard(state);
                        }
                    }
                }
            }
            else
            {
                if (mouseDown)
                {
                    if (ActivePiece != null)
                    {
                        int x = (int)(state.X / GRID_SIZE);
                        int y = (int)(state.Y / GRID_SIZE);

                        if (x < 10 && y < 10)
                        {
                            DropPiece(x, y);
                        }
                        ActivePiece = null;
                    }

                    mouseDown = false;
                }
            }
        }
示例#13
0
文件: Game1.cs 项目: smelch/Stratego
 private void DropPiece(int x, int y)
 {
     if (PieceDropAction != null)
     {
         PieceDropAction(x, y);
         PieceDropAction = null;
     }
     ActivePiece = null;
 }