Пример #1
0
	void Start() {
		ship = this;
		_energy = maxEnergy;
		StartCoroutine(EnergyRegen());
	}
Пример #2
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Console.CursorVisible = false;
            Console.SetWindowSize(Constants.ConsoleWindowWidth, Constants.ConsoleWindowHeight);

            var UI = new UIfunctions();

            UI.DrawStartScreen();
            Console.ReadKey();
            Console.Clear();
            var lives  = Constants.StartingLives;
            var score  = Constants.StartingScore;
            var missed = Constants.MissedShips;

            UI.DrawFrame(lives, score, missed);

            var ship     = new MainShip();
            var gameOver = false;

            int redo = 0;

            ship.DrawShip();

            Stopwatch time = new Stopwatch();

            time.Start();

            do
            {
                if (time.Elapsed.Milliseconds % 100 == 0)
                {
                    bool updateFrame = false;
                    if (time.Elapsed.Seconds % 2 == 0 && time.Elapsed.Milliseconds == 0)
                    {
                        ship.SpawnEnemiyShips();
                    }
                    if ((time.Elapsed.Seconds * 1000 + time.Elapsed.Milliseconds) % 500 == 0)
                    {
                        Enemies.MoveEnemies(ship.EnemyShips, ref missed, ref updateFrame);

                        //game over check
                        gameOver = Enemies.CheckForCollision(ship.EnemyShips, ship);
                        if (missed >= 3)
                        {
                            gameOver = true;
                        }
                        if (gameOver)
                        {
                            if (ship.lives > 0)
                            {
                                UIfunctions.GameOver(UI, ship, ship.EnemyShips, score, ref missed);
                                ship.DrawShip();
                                gameOver = false;
                            }
                            else
                            {
                                UIfunctions.FinalScreen(score);
                                break;
                            }
                        }
                        //end of game over check
                    }
                    if (updateFrame)
                    {
                        Console.SetCursorPosition(78, 48);
                        Console.WriteLine(missed);
                    }
                    ship.UpdateEnemies();
                }
                else if (time.Elapsed.Milliseconds % 50 == 0)
                {
                    ship.UpdateBullets(ref score);
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo KeyInfo;
                    while (!Console.KeyAvailable)
                    {
                        //ship.UpdateBullets();
                        ship.UpdateEnemies();
                        Thread.Sleep(50);
                    }
                    KeyInfo = Console.ReadKey(true);
                    ship.MoveShip(KeyInfo, ship, ref ship.position);
                    //game over check
                    gameOver = Enemies.CheckForCollision(ship.EnemyShips, ship);
                    if (gameOver)
                    {
                        if (ship.lives > 0)
                        {
                            UIfunctions.GameOver(UI, ship, ship.EnemyShips, score, ref missed);
                            ship.DrawShip();
                            gameOver = false;
                        }
                        else
                        {
                            UIfunctions.FinalScreen(score);
                            break;
                        }
                    }
                    // end of game over check
                    continue;
                }
            } while (redo == 0);


            Console.ReadKey(true);
        }
Пример #3
0
 void Start()
 {
     ship    = this;
     _energy = maxEnergy;
     StartCoroutine(EnergyRegen());
 }