コード例 #1
0
ファイル: AsteroidsGame.cs プロジェクト: unbelt/Telerik
        // 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
ファイル: AsteroidsGame.cs プロジェクト: unbelt/Telerik
        // 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
ファイル: Asteroid.cs プロジェクト: unbelt/Telerik
        // 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;
        }