Наследование: CDrawableComponent
Пример #1
0
 /// <summary>
 /// AddDeployedPlayer adds both players and will make sure
 /// that the AI player deploys all ships
 /// </summary>
 /// <param name="p"></param>
 public void AddDeployedPlayer(Player p)
 {
     if (_players(0) == null) {
         _players(0) = p;
     } else if (_players(1) == null) {
         _players(1) = p;
         CompleteDeployment();
     } else {
         throw new ApplicationException("You cannot add another player, the game already has two players.");
     }
 }
Пример #2
0
 protected override void Initialize()
 {
     player=new Player("faceSheet",new Vector2(200,100),32,32,0,this);
     level=new Level();
     level.add(new Wall("wall",new Vector2(200,200),32,32,0,this));
     level.add(new Wall("wall",new Vector2(300,100),32,32,0,this));
     level.add(new Wall("wall", new Vector2(232,200), 32, 32, 0, this));
     level.add(new Wall("wall", new Vector2(264, 200), 32, 32, 0, this));
     level.add(new Wall("wall",new Vector2(296,168),32,32,0,this));
     //builder=new LevelBuilder(this);
     base.Initialize();
 }
 public static void DrawPromotion()
 {
     lastPlayer = GameController.Players[Math.Abs(GameController.CurrentPlayerIndex-1)];
     MainGameController.DrawMainGame ();
     if (lastPlayer.isBlack)
     {
         SwinGame.DrawBitmap(GameResources.GameImage("Promo_B"),PROMO_X + 430, PROMO_Y);
     }
     else
     {
         SwinGame.DrawBitmap(GameResources.GameImage("Promo_W"),PROMO_X, PROMO_Y);
     }
 }
Пример #4
0
 public static void buySkillAddLife(string skillName, MenuElement menuElement, Player player)
 {
     PlayerSkill ps = GamerManager.getSessionOwner().data.skills[skillName];
     int XP = GamerManager.getSessionOwner().data.XP;
     if (!ps.obtained && ps.cost <= XP)
     {
         ps.obtained = true;
         GamerManager.getSessionOwner().data.XP -= ps.cost;
         menuElement.drawLinkedElement = true;
         player.addLifePortionsToMax();
         // playsound
     }
     else
     {
         // playsound
     }
 }
Пример #5
0
        public GameScreen()
        {
            closedList = new BigList<GameObject>();
            shells = new BigList<Shell>();

            player = new Player();
            earth = new Earth();
            glow = new Glow();
            //map = new Map();

            mCollisions = new MasterCollisions();

            closedList.Add(glow);
            closedList.Add(player);
            closedList.Add(earth);

            for (int i = 0; i < 100; i++)
            {
                shells.Add(new Shell());

                closedList.Add(shells.Last());

            }
        }
        /// <summary>
        /// Handles the input during the input state.
        /// </summary>
        static void HandleInputState()
        {
            // Sets the X and O player names as per the input.
            // Sets to default 'PlayerX' or 'PlayerO' if no input.
            if ( SwinGame.ButtonClicked ( "InputButton1" ))
            {
                if ( SwinGame.TextBoxText ( "PlayerXTextBox" ).TrimEnd () == "" )
                {
                    _playerX = new Player ( "PlayerX" );
                }
                else
                {
                    _playerX = new Player ( SwinGame.TextBoxText ( "PlayerXTextBox" ).TrimEnd () );
                }

                if ( SwinGame.TextBoxText ( "PlayerOTextBox" ).TrimEnd () == "" )
                {
                    _playerO = new Player ( "PlayerO" );
                }
                else
                {
                    _playerO = new Player ( SwinGame.TextBoxText ( "PlayerOTextBox" ).TrimEnd () );
                }

                SwinGame.HidePanel ( "PlayerInputPanel" );

                _activePlayer = PlayerX;

                GameController.SwitchState ( GameState.PlayState );
            }
        }
Пример #7
0
        /// <summary>
        /// Draws the player's grid and ships.
        /// </summary>
        /// <param name="grid">the grid to show</param>
        /// <param name="thePlayer">the player to show the ships of</param>
        /// <param name="small">true if the small grid is shown</param>
        /// <param name="showShips">true if ships are to be shown</param>
        /// <param name="left">the left side of the grid</param>
        /// <param name="top">the top of the grid</param>
        /// <param name="width">the width of the grid</param>
        /// <param name="height">the height of the grid</param>
        /// <param name="cellWidth">the width of each cell</param>
        /// <param name="cellHeight">the height of each cell</param>
        /// <param name="cellGap">the gap between the cells</param>
        private static void DrawCustomField(ISeaGrid grid, Player thePlayer, bool small, bool showShips, int left, int top, int width, int height, int cellWidth, int cellHeight,
        int cellGap)
        {
            //SwinGame.FillRectangle(Color.Blue, left, top, width, height)

            int rowTop = 0;
            int colLeft = 0;

            //Draw the grid
            for (int row = 0; row <= 9; row++)
            {
                rowTop = top + (cellGap + cellHeight) * row;

                for (int col = 0; col <= 9; col++)
                {
                    colLeft = left + (cellGap + cellWidth) * col;

                    Color fillColor = default(Color);
                    if (small)
                        fillColor = SMALL_SHIP;
                    else
                        fillColor = LARGE_SHIP;
                    bool draw = false;

                    draw = true;

                    switch (grid.Item(row, col))
                    {
                        case TileView.Ship:
                            draw = false;
                            break;
                        case TileView.Miss:
                            if (small)
                                fillColor = SMALL_MISS;
                            else
                                fillColor = LARGE_MISS;
                            break;
                        case TileView.Hit:
                            if (small)
                                fillColor = SMALL_HIT;
                            else
                                fillColor = LARGE_HIT;
                            break;
                        case TileView.Sea:
                            if (small)
                                fillColor = SMALL_SEA;
                            else
                                draw = false;
                            break;
                    }

                    if (draw)
                    {
                        SwinGame.FillRectangle(fillColor, colLeft, rowTop, cellWidth, cellHeight);
                        if (!small)
                        {
                            SwinGame.DrawRectangle(OUTLINE_COLOR, colLeft, rowTop, cellWidth, cellHeight);
                        }
                    }
                }
            }

            if (!showShips)
            {
                return;
            }

            int shipHeight = 0;
            int shipWidth = 0;
            string shipName = null;

            //Draw the ships
            foreach (Ship s in thePlayer)
            {
                if (s == null || !s.IsDeployed)
                    continue;
                rowTop = top + (cellGap + cellHeight) * s.Row + SHIP_GAP;
                colLeft = left + (cellGap + cellWidth) * s.Column + SHIP_GAP;

                if (s.Direction == Direction.LeftRight)
                {
                    shipName = "ShipLR" + s.Size;
                    shipHeight = cellHeight - (SHIP_GAP * 2);
                    shipWidth = (cellWidth + cellGap) * s.Size - (SHIP_GAP * 2) - cellGap;
                }
                else
                {
                    //Up down
                    shipName = "ShipUD" + s.Size;
                    shipHeight = (cellHeight + cellGap) * s.Size - (SHIP_GAP * 2) - cellGap;
                    shipWidth = cellWidth - (SHIP_GAP * 2);
                }

                if (!small)
                {
                    SwinGame.DrawBitmap(GameResources.GameImage(shipName), colLeft, rowTop);
                }
                else
                {
                    SwinGame.FillRectangle(SHIP_FILL_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                    SwinGame.DrawRectangle(SHIP_OUTLINE_COLOR, colLeft, rowTop, shipWidth, shipHeight);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Draws a small field, showing the attacks made and the locations of the player's ships
        /// </summary>
        /// <param name="grid">the grid to show</param>
        /// <param name="thePlayer">the player to show the ships of</param>
        public static void DrawSmallField(SeaGrid grid, Player thePlayer)
        {
            const int SMALL_FIELD_LEFT = 39;
            const int SMALL_FIELD_TOP = 373;
            const int SMALL_FIELD_WIDTH = 166;
            const int SMALL_FIELD_HEIGHT = 166;
            const int SMALL_FIELD_CELL_WIDTH = 13;
            const int SMALL_FIELD_CELL_HEIGHT = 13;
            const int SMALL_FIELD_CELL_GAP = 4;

            DrawCustomField(grid, thePlayer, true, true, SMALL_FIELD_LEFT, SMALL_FIELD_TOP, SMALL_FIELD_WIDTH, SMALL_FIELD_HEIGHT, SMALL_FIELD_CELL_WIDTH, SMALL_FIELD_CELL_HEIGHT,
            SMALL_FIELD_CELL_GAP);
        }
Пример #9
0
 /// <summary>
 /// Draws a large field using the grid and the indicated player's ships.
 /// </summary>
 /// <param name="grid">the grid to draw</param>
 /// <param name="thePlayer">the players ships to show</param>
 /// <param name="showShips">indicates if the ships should be shown</param>
 public static void DrawField(ISeaGrid grid, Player thePlayer, bool showShips)
 {
     DrawCustomField(grid, thePlayer, false, showShips, FIELD_LEFT, FIELD_TOP, FIELD_WIDTH, FIELD_HEIGHT, CELL_WIDTH, CELL_HEIGHT,
     CELL_GAP);
 }
Пример #10
0
        /// <summary>
        /// Starts a new game.
        /// </summary>
        /// <remarks>
        /// Creates an AI player based upon the _aiSetting.
        /// </remarks>
        public static void StartGame()
        {
            if (_theGame != null)
                EndGame();

            //Create the game
            _theGame = new BattleShipsGame();

            //create the players
            switch (_aiSetting)
            {
            case AIOption.Medium:
                _ai = new AIMediumPlayer(_theGame);
                break;
            case AIOption.Hard:
                _ai = new AIHardPlayer(_theGame);
                break;
            default:
                _ai = new AIHardPlayer(_theGame);
                break;
            }

            _human = new Player(_theGame);

            //AddHandler _human.PlayerGrid.Changed, AddressOf GridChanged
            _ai.PlayerGrid.Changed += GridChanged;
            _theGame.AttackCompleted += AttackCompleted;

            AddNewState(GameState.Deploying);
        }
 /// <summary>
 /// Increases the player score.
 /// </summary>
 /// <param name="player">Player.</param>
 public static void IncreasePlayerScore( Player player )
 {
     player.Score += 1;
 }
 /// <summary>
 /// Initializes the ScoreController.
 /// </summary>
 static ScoreController()
 {
     _playerO = GameController.PlayerO;
     _playerX = GameController.PlayerX;
 }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            random = new Random ();

            player = new Player();
            boss = new Boss ();

            bgLayer1 = new ParallaxingBackground ();
            bgLayer2 = new ParallaxingBackground ();

            enemies = new List<Enemy> ();
            explosions = new List<Explosion> ();
            lasers = new List<Laser> ();

            enemySpawnTime = TimeSpan.FromSeconds (1.0f);
            prevEnemySpawnTime = TimeSpan.Zero;
            laserSpawnTime = TimeSpan.FromSeconds (0.5f);

            healthBarVal = Constants.PLAYER_HEALTH;
            maxEnemyCount = Constants.ENEMY_COUNT;
            score = 0;
            bossFight = false;

            GameState = GameStates.Start;
            menuCursor = MenuOptions.Start;
            base.Initialize ();
        }
Пример #14
0
        public void TestPlayerConstructor()
        {
            Player _player = new Player ("Jarrod");

            Assert.IsTrue( _player.Name == "Jarrod" );
            Assert.IsTrue( _player.Score == 0 );
        }
        public static void HandlePromotionInput()
        {
            lastPlayer = GameController.Players[Math.Abs(GameController.CurrentPlayerIndex-1)];
            int x = GameController.Promoted.X;
            int y = GameController.Promoted.Y;
            bool black = lastPlayer.isBlack;

            if (SwinGame.MouseClicked (MouseButton.LeftButton))
            {
                if (PieceInBox (0, 0, 60, 69))
                {
                    GameController.Promotion = new Queen (x, y, black);
                }
                if (PieceInBox (60, 0, 51, 69))
                {
                    GameController.Promotion = new Knight (x, y, black);
                }
                if (PieceInBox (111, 0, 58, 69))
                {
                    GameController.Promotion = new Bishop (x, y, black);
                }
                if (PieceInBox (169, 0, 52, 69))
                {
                    GameController.Promotion = new Rock (x, y, black);
                }
            }

            if (GameController.Promotion != null)
            {
                GameController.Promotion.isDead = false;
                int idx = lastPlayer.PieceList.IndexOf (GameController.Promoted);
                lastPlayer.PieceList [idx] = GameController.Promotion;
                UtilityFunctions.CheckAvaiMoveOfAllPieces ();

                //Check checking
                bool check = MainGameController.isChecked ();
                GameController.Checking = check;
                if (check)
                {
                    if (!MainGameController.CanPreventAttack ())
                    {
                        MainGameController.isEnd = true;
                        GameController.Result = Math.Abs (GameController.CurrentPlayerIndex - 1);
                    } else
                    {
                        MainGameController.check_isBlack = black;
                        MainGameController.isCheck = true;
                    }
                }
                else
                {
                    if (MainGameController.AllPiecesCannotMove ())
                    {
                        GameController.Result = 2;
                        MainGameController.isEnd = true;
                        MainGameController.isDraw = true;
                    }
                }
                GameController.EndCurrentState ();
            }
        }