Exemple #1
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();
                    }
                }
            }
        }