示例#1
0
        // V6 Supercharged
        private static void Engine(List<Asteroid> asteroids, Ship ship)
        {
            char shieldOrientetion = 'L';

            while (lives > 0)
            {
                shieldOrientetion = PressedKey(shieldOrientetion);

                if (levelCounter == difficulty)
                {
                    // Control the asteroid creation
                    Asteroid newAsteroid = new Asteroid(PickUpChar(), ConsoleColor.Cyan);
                    if (newAsteroid.Symbol == '\u263A')
                    {
                        newAsteroid.Color = ConsoleColor.Yellow;
                    }

                    if (newAsteroid.Symbol == '\u2665')
                    {
                        newAsteroid.Color = ConsoleColor.Red;
                    }

                    asteroids.Add(newAsteroid);
                    levelCounter = 0;
                }

                levelCounter++;

                Shield shield = new Shield(shieldOrientetion, 1, ship);

                // Move the asteroids
                for (int index = 0; index < asteroids.Count; index++)
                {
                    asteroids[index].Clear();
                    asteroids[index].Move();
                }

                Collisions(asteroids, ship, shield);

                ship.Draw();
                shield.Draw();

                DrawInterface(lives, score); // draw score and lives in separated cells

                // Slow down the game
                Thread.Sleep(gameSpeed);
                shield.Clear();
            }
        }
示例#2
0
        // Shield && Ship
        private static void Collisions(List<Asteroid> asteroids, Ship ship, Shield shield)
        {
            // Collisions with ship
            for (int i = 0; i < asteroids.Count; i++)
            {
                if (ship.IsHittedBy(asteroids[i]))
                {
                    if (asteroids[i].Symbol == 'о' || asteroids[i].Symbol == 'O' || asteroids[i].Symbol == '0')
                    {
                        music = new SoundPlayer(@"AsteroidHit.wav");
                        music.Play();
                        DrawElement((Console.BufferWidth / 2) + 13 + lives - 1, 4, '\u2665'.ToString(), ConsoleColor.Black);
                        lives--; // loses lives only if hitted by asteroids
                    }

                    asteroids.Remove(asteroids[i]);
                    if (lives == 0)
                    {
                        break;
                    }
                }

                asteroids[i].Print();
            }

            // Collisions with shield
            for (int i = 0; i < asteroids.Count; i++)
            {
                if (asteroids[i].IsShieldHitted(shield))
                {
                    music = new SoundPlayer("ShieldHitAsteroid.wav");
                    music.Play();

                    if (asteroids[i].Symbol == '\u263A')
                    {
                        score += 9;
                        music = new SoundPlayer("Smile.wav");
                        music.Play();
                    }
                    else if (asteroids[i].Symbol == '\u2665')
                    {
                        if (lives < 6)
                        {
                            lives++;
                        }
                        else
                        {
                            score += 19;
                        }

                        music = new SoundPlayer("Heart.wav");
                        music.Play();
                    }

                    asteroids.RemoveAt(i);
                    score++; // increase current score

                    // Change the difficulty depending on the points earnt
                    if (score < 250)
                    {
                        gameSpeed = 100;
                        level = 1;
                    }
                    else if (score > 250 && score < 500)
                    {
                        gameSpeed = 75;
                        level = 2;
                    }
                    else if (score > 500 && score < 750)
                    {
                        gameSpeed = 50;
                        level = 3;
                    }
                    else if (score > 1000)
                    {
                        YouWin();
                    }
                }
            }
        }
示例#3
0
        // Check if any asteroid hitted the shield
        public bool IsShieldHitted(Shield shield)
        {
            if (this.XPos == shield.XPos && this.YPos == shield.YPos)
            {
                return true;
            }

            return false;
        }