コード例 #1
0
ファイル: EightGamePiece.cs プロジェクト: smelch/Stratego
 public override AttackResult Attack(GamePiece defender)
 {
     if (defender.Type == GamePieceType.Bomb)
     {
         return AttackResult.Win;
     }
     return base.Attack(defender);
 }
コード例 #2
0
ファイル: SpyGamePiece.cs プロジェクト: smelch/Stratego
        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
ファイル: GamePiece.cs プロジェクト: smelch/Stratego
        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
ファイル: GameSession.cs プロジェクト: smelch/Stratego
        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
ファイル: GameState.cs プロジェクト: smelch/Stratego
 public GameState()
 {
     Board = new GamePiece[10, 10];
     Turn = PlayerTurn.Setup;
     Bank = new PieceBank();
 }
コード例 #6
0
ファイル: StrategoGame.cs プロジェクト: smelch/Stratego
        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
ファイル: FlagGamePiece.cs プロジェクト: smelch/Stratego
 public override AttackResult Attack(GamePiece defender)
 {
     throw new Exception("Flags can not attack!");
 }
コード例 #8
0
ファイル: PieceBank.cs プロジェクト: smelch/Stratego
 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;
 }