Пример #1
0
        public Game()
        {
            //Instantiate a Unit that will represent the player.
            //Unit constructor's signature: X pos, Y pos, Char.
            playerUnit = new PlayerUnit(10, 17, "@");

            //Instantiate a Unit that will represent the enemy.
            //Unit constructor's signature: X pos, Y pos, Char.

            //Instantiate the array that will hold our enemies.
            enemyUnits = new Unit[numEnemies];
            //Right now, our enemyUnits array is instantiated,
            //but each slot is empty.


            Random = new Random();
            Score  = 0;


            for (int i = 0; i < enemyUnits.Length; i++)
            {
                int row = Random.Next(0, Console.WindowHeight - 1);
                enemyUnits[i] = new EnemyUnit(Console.WindowWidth - 1, row, "X");
            }


            stopwatch = new Stopwatch();
        }
Пример #2
0
        // This is our constructor -- it gets run automatically when a new INSTANCE of Game is created.
        public Game()
        {
            //Instantiate a Unit that will represent the player.
            playerUnit = new PlayerUnit(10, 17, "@");

            // Instanciate the enemy
            enemyUnit = new EnemyUnit(20, 17, "X");

            stopwatch = new Stopwatch();
        }
Пример #3
0
 public Game()
 {
     player  = new PlayerUnit(5, 10, "@");
     enemies = new Unit[numEnemies];
     Random  = new Random();
     Score   = 0;
     for (int i = 0; i < enemies.Length; i++)
     {
         int row = Game.Random.Next(0, Console.WindowHeight - 1);
         enemies[i] = new EnemyUnit(Console.WindowWidth - 1, row, "X");
     }
     stopwatch = new Stopwatch();
 }
Пример #4
0
        /*Game() Constructor
         * Constructors read the entire class before 'building',
         * So you can place at top, and it will read variables below it
         */
        public Game()
        {
            //Clearing the screen at game start
            Console.Clear();

            //Instantiate a Unit that will represent the player.
            //new Unit has () because you can pass variables in (to the constructor)
            playerUnit = new PlayerUnit(15, 17, ">"); //Unit(15, 20, "H");

            /*
             * allowed since 'set' for X was set to public
             * secretly setting _x, allowing for validity checking
             */
            //playerUnit.X = 15;
            //playerUnit.Y = 10;
            //playerUnit.UnitGraphic = "H";
            //also allowed since 'get' for X was set to public, reading _x
            if (playerUnit.X > 20)
            {
                //Do something
            }

            //Instantiate a single enemy Unit --Obsolete with [] enemies
            //enemyUnit = new EnemyUnit(Console.WindowWidth - 1, 17, "M");

            /*Create many Array that will hold our enemies
             * When instiating an array, must list size
             * --In most languages, Arrays have a fixed size after creation
             */
            enemyUnits = new Unit[numEnemies];
            //Right now, enemyUnits is created, but each slot is empty

            //Random number generator
            random = new Random();
            //Set score at beginning to 0
            Score = 0;

            for (int i = 0; i < enemyUnits.Length; i++)
            {
                //Setting a random row for the enemy to appear
                int row = random.Next(0, Console.WindowHeight - 1);
                //Filling each index with it's own EnemyUnit
                enemyUnits[i] = new EnemyUnit(Console.WindowWidth - 1, row, "M");
            }

            //Making an array of UpSlopeEnemies
            upSlopeEnemies = new Unit[numEnemies / 5]; //Want a lot fewer of these

            for (int i = 0; i < upSlopeEnemies.Length; i++)
            {
                //Setting a random row for the enemy to appear
                int yStart = Console.WindowHeight - 1;
                int xStart = random.Next(Console.WindowWidth / 4, Console.WindowWidth - 1);
                //Filling each index with it's own EnemyUnit
                upSlopeEnemies[i] = new UpSlopeEnemy(xStart, yStart, "N");
            }

            //Making an array of DownSlopeEnemies
            downSlopeEnemies = new Unit[numEnemies / 5]; //Want a lot fewer of these

            for (int i = 0; i < downSlopeEnemies.Length; i++)
            {
                //Setting a random row for the enemy to appear
                int yStart = 1;
                int xStart = random.Next(Console.WindowWidth / 4, Console.WindowWidth - 1);
                //Filling each index with it's own EnemyUnit
                downSlopeEnemies[i] = new DownSlopeEnemy(xStart, yStart, "N");
            }

            stopwatch = new Stopwatch();
        }