示例#1
0
 private Space(Settings settings)
 {
     playerShip   = ObjectCreation.PlayerShipCreation(settings);
     playerBullet = new List <Object>();
     enemyBullet  = new List <Object>();
     enemy        = new List <Object>();
 }
示例#2
0
        public void Run()
        {
            int    enemyMoveCounter         = 0;
            int    addingEnemyCouter        = 0;
            int    playerBulletMoveCounter  = 0;
            int    addingPlayerBulletCouter = 0;
            int    enemyBulletMoveCounter   = 0;
            int    addingEnemyBulletCounter = 0;
            int    bossBulletMoveCounter    = 0;
            int    addingBossBulletCounter  = 0;
            int    bossMoveCounter          = 0;
            int    enemiesCounter           = 0;
            int    bossDelay    = 0;
            bool   bossCreation = false;
            Random randomeValue = new Random();

            gameOver = false;

            do
            {
                screenRender.ClearScreen();
                screenRender.Render(space);
                CalculateCollision();
                Thread.Sleep(settings.updateRate);
                if (enemyMoveCounter == settings.enemySpeed)
                {
                    EnemyMove();
                    enemyMoveCounter = 0;
                }
                if (addingEnemyCouter == settings.speedAddingEnemy && enemiesCounter < settings.enemiesNumber)
                {
                    int enemyStartPosition = randomeValue.Next() % (settings.consoleWidth - settings.enemyBodyWidth + 1);
                    space.enemy.Add(ObjectCreation.EnemyCreation(settings, enemyStartPosition, 0));
                    ++enemiesCounter;
                    if (enemiesCounter == settings.enemiesNumber)
                    {
                        bossCreation = true;
                    }
                    addingEnemyCouter = 0;
                }
                if (playerBulletMoveCounter == settings.playerBulletSpeed)
                {
                    PlayerBulletMove();
                    playerBulletMoveCounter = 0;
                }
                if (addingPlayerBulletCouter == settings.speedAddingPlayerBullet)
                {
                    int startPositionX = space.playerShip.positionX + space.playerShip.bodyWidth / 2;
                    int startPositionY = space.playerShip.positionY - 1;
                    space.playerBullet.Add(ObjectCreation.PlayerBulletCreation(settings, startPositionX, startPositionY));
                    if (PositionPossibility(space.playerBullet[space.playerBullet.Count() - 1], 0, 0) == false)
                    {
                        space.playerBullet.RemoveAt(space.playerBullet.Count() - 1);
                    }
                    addingPlayerBulletCouter = 0;
                }
                if (enemyBulletMoveCounter == settings.enemyBulletSpeed)
                {
                    EnemyBulletMove();
                    enemyBulletMoveCounter = 0;
                }
                if (addingEnemyBulletCounter == settings.speedAddingEnemyBullet)
                {
                    for (int i = 0; i < space.enemy.Count(); ++i)
                    {
                        int startPositionX = space.enemy[i].positionX + space.enemy[i].bodyWidth / 2;
                        int startPositionY = space.enemy[i].positionY + space.enemy[i].bodyHeight;
                        space.enemyBullet.Add(ObjectCreation.EnemyBulletCreation(settings, startPositionX, startPositionY));
                        if (PositionPossibility(space.enemyBullet[space.enemyBullet.Count() - 1], 0, 0) == false)
                        {
                            space.enemyBullet.RemoveAt(space.enemyBullet.Count() - 1);
                        }
                    }
                    addingEnemyBulletCounter = 0;
                }
                if (bossCreation == true)
                {
                    if (bossDelay < settings.speedAddingEnemy)
                    {
                        ++bossDelay;
                    }
                    else
                    {
                        space.boss   = ObjectCreation.BossCreation(settings);
                        bossCreation = false;
                    }
                }
                if (bossMoveCounter == settings.bossSpeed)
                {
                    BossMove();
                    bossMoveCounter = 0;
                }
                if (addingBossBulletCounter == settings.speedAddingBossBullet)
                {
                    int startPositionX = space.boss.positionX;
                    int startPositionY = space.boss.positionY + space.boss.bodyHeight;
                    space.enemyBullet.Add(ObjectCreation.EnemyBulletCreation(settings, startPositionX + 2, startPositionY - 1));
                    space.enemyBullet.Add(ObjectCreation.EnemyBulletCreation(settings, startPositionX + 5, startPositionY));
                    space.enemyBullet.Add(ObjectCreation.EnemyBulletCreation(settings, startPositionX + 9, startPositionY));
                    space.enemyBullet.Add(ObjectCreation.EnemyBulletCreation(settings, startPositionX + 12, startPositionY - 1));
                    addingBossBulletCounter = 0;
                }
                if (space.boss != null && space.bossBullet == null)
                {
                    int startPositionX = space.boss.positionX + space.boss.bodyWidth / 2;
                    int srartPositionY = space.boss.positionY + space.boss.bodyHeight - 1;
                    space.bossBullet = ObjectCreation.BossBulletCreation(settings, startPositionX, srartPositionY);
                }
                if (bossBulletMoveCounter == settings.bossBulletSpeed)
                {
                    BossBulletMove();
                    bossBulletMoveCounter = 0;
                }
                if (space.boss != null)
                {
                    ++bossMoveCounter;
                    ++bossBulletMoveCounter;
                    ++addingBossBulletCounter;
                }
                ++enemyBulletMoveCounter;
                ++addingEnemyBulletCounter;
                ++enemyMoveCounter;
                ++addingEnemyCouter;
                ++playerBulletMoveCounter;
                ++addingPlayerBulletCouter;
            } while (!gameOver);
        }