Exemple #1
0
        public AI(ref Tile[,] playerPBoard, ref Tile[,] enemyPBoard, ref TrackTile[,] enemyTBoard, ref Ship[] enemyShips)
        {
            this.playerPBoard = playerPBoard;
            this.enemyPBoard = enemyPBoard;
            this.enemyTBoard = enemyTBoard;
            this.enemyShips = enemyShips;

            this.lastXHit = 0;
            this.lastYHit = 0;
            this.direction = -1;
            this.search = 1;

            this.hitLast = false;

            this.notVU = this.notVD = this.notHL = this.notHR = false;

            this.RNG = new Random();
        }
Exemple #2
0
        /// <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()
        {
            status = -1;

            playerPBoard = new Tile[SIZE, SIZE];
            playerTBoard = new TrackTile[SIZE, SIZE];

            enemyPBoard = new Tile[SIZE, SIZE];
            enemyTBoard = new TrackTile[SIZE, SIZE];

            playerShips = new Ship[NUM_SHIPS];
            enemyShips = new Ship[NUM_SHIPS];

            pPatrolShip = new Ship("Patrol Boat");
            playerShips[0] = pPatrolShip;
            pDestroyerShip = new Ship("Destroyer");
            playerShips[1] = pDestroyerShip;
            pSubShip = new Ship("Submarine");
            playerShips[2] = pSubShip;
            pBattleShip = new Ship("Battleship");
            playerShips[3] = pBattleShip;
            pCarrierShip = new Ship("Aircraft Carrier");
            playerShips[4] = pCarrierShip;

            enemyShips[0] = new Ship("Patrol Boat");
            enemyShips[1] = new Ship("Destroyer");
            enemyShips[2] = new Ship("Submarine");
            enemyShips[3] = new Ship("Battleship");
            enemyShips[4] = new Ship("Aircraft Carrier");

            for (int i = 0; i < SIZE; i++)
            {
                for (int j = 0; j < SIZE; j++)
                {
                    playerTBoard[i, j] = new TrackTile();
                    enemyTBoard[i, j] = new TrackTile();
                }
            }

            for (int i = 0; i < SIZE; i++)
            {
                for (int j = 0; j < SIZE; j++)
                {
                    char let = (char)((int)'A' + j);
                    int num = i + 1;
                    playerPBoard[i, j] = new Tile(let, num);
                    enemyPBoard[i, j] = new Tile(let, num);
                }
            }

            enemy = new AI(ref playerPBoard, ref enemyPBoard, ref enemyTBoard, ref enemyShips);
            enemy.createRandPBoard(NUM_SHIPS);

            particles = new List<Particle>();

            base.Initialize();
        }
        public void update(float gameTime, TrackTile[,] track, Tile[,] own, Ship[] pships)
        {
            int mx = Mouse.GetState().X;
            int my = Mouse.GetState().Y;
            Random RNG = new Random();

            highx = -1;
            highy = -1;

            if (mx > 340 && my > 90 && mx < 650 && my < 380)
            {
                highx = (mx - 340) * 10 / (650 - 340);
                highy = (my - 90) * 10 / (380 - 90);
                highy = -highy + 9;
            }
            enemytracker = track;
            playertracker = own;
            playerships = pships;

            float ymin = -0.55f, ymax = -0.53f, dy = 0.000015f;

            foreach (WaterVertex v in water)
            {
                if (v.up)
                {
                    v.position.Y += dy * gameTime;
                    if (v.position.Y > ymax)
                        v.up = !v.up;
                }
                else
                {
                    v.position.Y -= dy * gameTime;
                    if (v.position.Y < ymin)
                        v.up = !v.up;
                }
                v.color = new Color(0f, (v.position.Y - ymin) * 22f, Color.DarkBlue.B);
            }

            for (int i = 0; i < particles.Count; i++)
            {
                particles[i].update();
                if ((particles[i].type == EXPLODE || particles[i].type == SPLASH) && (particles[i].getPosition().Y - particles[i].initPos.Y < 0 || particles[i].getPosition().X > 100.0))
                {
                    particles.RemoveAt(i--);
                }
                else if (particles[i].type == FIRE && particles[i].getPosition().Y - particles[i].initPos.Y > 0.1f)
                {
                    particles[i].setPosition(particles[i].initPos);
                    particles[i].setVelocity(new Vector3(0, (float)RNG.NextDouble() * 0.002f + 0.002f, 0));
                }
            }
        }