コード例 #1
0
ファイル: Shield.cs プロジェクト: unbelt/Telerik
        // Shield orientation
        public Shield(char orientation, int len, Ship ship)
        {
            this.Orientation = orientation;
            this.Len = len;

            if (this.Orientation == 'L' || this.Orientation == 'R')
            {
                this.View = "|";

                // Set left || right shield
                if (this.Orientation == 'L')
                {
                    this.XPos = ship.XPos - 2;
                    this.YPos = ship.YPos;
                }
                else
                {
                    this.XPos = ship.XPos + 2;
                    this.YPos = ship.YPos;
                }
            }
            else
            {
                this.View = "—";

                // Set top || bottom shield
                if (this.Orientation == 'U')
                {
                    this.XPos = ship.XPos;
                    this.YPos = ship.YPos - 1;
                }
                else
                {
                    this.XPos = ship.XPos;
                    this.YPos = ship.YPos + 1;
                }
            }
        }
コード例 #2
0
ファイル: AsteroidsGame.cs プロジェクト: unbelt/Telerik
        // Initial settings
        private static void Settings()
        {
            // Initialize an array for the asteroids
            List<Asteroid> asteroids = new List<Asteroid>();
            level = 1;
            levelCounter = 1;
            lives = 3; // starting lives
            score = 0;

            // Our hero ship
            Ship ship = new Ship('\u2588', gameWidth / 4, gameHeight / 2, ConsoleColor.White);

            Engine(asteroids, ship); // Start the game
            GameOver(score);
            Settings();
        }
コード例 #3
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();
                    }
                }
            }
        }
コード例 #4
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();
            }
        }