public void CreateEnemies() { enemy1 = new Goomba(1); //in current version, Goomba is always enemy1 because Goomba always appears on the EnemyAppearsForm Random randEnemy = new Random(); int enemy2_ID = randEnemy.Next(TYPES_OF_ENEMIES) + 1; //The random number generated will be one of the ID values of the current enemy classes available for building enemy2 = BuildEnemyCaller(enemy2, enemy2_ID, 2); //first parameter is the abstract object in memory to derive, second param is used as detailed above, third param is used for sprite display Thread.Sleep(2000); //Sleep function is used to ensure enough time passes before calling randomEnemy.Next() int enemy3_ID = randEnemy.Next(TYPES_OF_ENEMIES) + 1; enemy3 = BuildEnemyCaller(enemy3, enemy3_ID, 3); Thread.Sleep(2000); }
public BattleEnemy BuildEnemyCaller(BattleEnemy enemyToSet, int id, int spotOnScreen) //named this because this function calls the appropriate object's constructor { switch (id) { case 1: enemyToSet = new Goomba(spotOnScreen); break; case 2: enemyToSet = new SpikedGoomba(spotOnScreen); break; case 3: enemyToSet = new Paragoomba(spotOnScreen); break; } return(enemyToSet); }