示例#1
0
    public void Run()
    {
        plane.Print();

        while (!settings.GameOver)
        {
            // adding chance to spawn @ 25%
            int chanceToSpawn = rnd.Next(0, 100);

            status.ClearStatus();
            status.PrintStatus();

            if (chanceToSpawn <= 80)
            {
                int objXPosition = 1;
                int objYPosition = rnd.Next(0, settings.Width - 2);
                destroyObject = new DestroyObject(new Point(objXPosition, objYPosition));
                gameObjectsList.AddLast(destroyObject);
            }

            if (chanceToSpawn <= 15)
            {
                int objXPosition = 1;
                int objYPosition = rnd.Next(0, settings.Width);
                collectObject = new CollectedObject(new Point(objXPosition, objYPosition));
                gameObjectsList.AddLast(collectObject);
            }

            while (gameObjectsList.Count > 0)
            {
                current = gameObjectsList.First;
                gameObjectsList.RemoveFirst();

                if (!current.Value.HaveCollision)
                {
                    PrintGameObject.PrintObject(current.Value);
                    newGameObjectsList.AddLast(current.Value);
                }
            }

            gameObjectsList = newGameObjectsList;
            newGameObjectsList = new LinkedList<GameObject>();

            while (Console.KeyAvailable)
            {
                ConsoleKeyInfo keyPressed = Console.ReadKey();
                plane.Clear();

                if (keyPressed.Key == ConsoleKey.UpArrow)
                {
                    plane.Position.X--;

                    if (plane.Position.X < 1)
                    {
                        plane.Position.X = 1;
                    }
                }

                if (keyPressed.Key == ConsoleKey.DownArrow)
                {
                    plane.Position.X++;

                    if (plane.Position.X > settings.Height - plane.PlaneHeight)
                    {
                        plane.Position.X = settings.Height - plane.PlaneHeight;
                    }
                }

                if (keyPressed.Key == ConsoleKey.LeftArrow)
                {
                    plane.Position.Y--;

                    if (plane.Position.Y < 0)
                    {
                        plane.Position.Y = 0;
                    }
                }

                if (keyPressed.Key == ConsoleKey.RightArrow)
                {
                    plane.Position.Y++;

                    if (plane.Position.Y > settings.Width - plane.PlaneWidth)
                    {
                        plane.Position.Y = settings.Width - plane.PlaneWidth;
                    }
                }

                if (keyPressed.Key == ConsoleKey.Spacebar)
                {
                    projectile = new Projectile(new Point(plane.Position.X - 1, plane.Position.Y + plane.PlaneWidth / 2));
                    projectilesFired.AddLast(projectile);
                    PrintGameObject.PrintObject(projectile);
                }

                if (keyPressed.Key == ConsoleKey.P)
                {
                    PauseScreenPage pause = new PauseScreenPage();
                    pause.PauseMain();
                    settings.Pause = !settings.Pause;
                    Console.ReadKey();
                    Console.Clear();
                }

                plane.Print();
            }

            while (projectilesFired.Count > 0)
            {
                Projectile current = (projectilesFired.First).Value;
                projectilesFired.RemoveFirst();
                PrintGameObject.ClearObject(current);
                current.Move();

                if (!current.HaveCollision)
                {
                    PrintGameObject.PrintObject(current);
                    projectilesInAir.AddLast(current);
                }
            }

            projectilesFired = projectilesInAir;
            projectilesInAir = new LinkedList<Projectile>();

            //foreach (var projectile in projectilesFired)
            //{
            //    if (projectile.UpLeftCorner.X >= 0)
            //    {
            //        PrintGameObject.ClearObject(projectile);
            //        projectile.Move();
            //        if (projectile.UpLeftCorner.X > 0)
            //        {
            //            PrintGameObject.PrintObject(projectile);
            //        }
            //    }
            //}

            while (gameObjectsList.Count > 0)
            {
                current = gameObjectsList.First;
                gameObjectsList.RemoveFirst();
                PrintGameObject.ClearObject(current.Value);
                current.Value.Move();

                if (!current.Value.HaveCollision)
                {
                    PrintGameObject.PrintObject(current.Value);
                    newGameObjectsList.AddLast(current);
                }
            }

            gameObjectsList = newGameObjectsList;
            newGameObjectsList = new LinkedList<GameObject>();

            status.Score += 1;
            Thread.Sleep(sleepTime);
        }

        Settings.PrintGameOver();
    }
示例#2
0
    public void Run()
    {
        plane.Print();

        if (FermiInTheAir.Utility.OpeningPage.playTutorial)
        {
            Settings.Tutorial(); // plays only one time when opening application
        }

        plane.Print();

        FermiInTheAir.Utility.OpeningPage.playTutorial = false;
        //set plane point coordinates to true

        while (!settings.GameOver)
        {
            // chance to spawn objects, adjust below for collectables / destroyables
            int chanceToSpawn = rnd.Next(0, 100);

            status.ClearStatus();
            status.PrintStatus();

            if (Convert.ToInt32(difficultyTimer.ElapsedMilliseconds) > 30000)
            {
                destroyObjectSpawnFrequency = 40;
            }

            if (chanceToSpawn <= destroyObjectSpawnFrequency) // previously = 40
            {
                int objXPosition = 1;
                int objYPosition = rnd.Next(11, settings.Width - 11); // previously = rnd.Next(0, settings.Width - 2);
                destroyObject = new DestroyObject(new Point(objXPosition, objYPosition));

                foreach (var point in destroyObject.PositionsCoordinates)
                {
                    if (CheckCollisionWithPlane(destroyObject, plane))
                    {
                        destroyObject.HaveCollision = true;
                        plane.Lives--;
                        sounds.Crash();
                        break;
                    }
                    if (CheckCollisionWhitOtherObject(point))
                    {
                        destroyObject.HaveCollision = true;
                    }
                }

                if (!destroyObject.HaveCollision)
                {
                    gameObjectsList.Add(destroyObject);
                    destroyObject.SetPositionsCoordinates();
                }
            }

            if (chanceToSpawn <= 15)
            {
                int objXPosition = 1;
                int objYPosition = rnd.Next(7, settings.Width - 7); // previously = rnd.Next(0, settings.Width);
                collectObject = new CollectedObject(new Point(objXPosition, objYPosition));

                if (CheckCollisionWithPlane(collectObject, plane))
                {
                    collectObject.HaveCollision = true;
                    settings.Score += 5; //TODO : regulate score
                }

                if (CheckCollisionWhitOtherObject(collectObject.UpLeftCorner))
                {
                    destroyObject.HaveCollision = true;
                }

                if (!destroyObject.HaveCollision)
                {
                    gameObjectsList.Add(collectObject);
                    collectObject.SetPositionsCoordinates();

                }
            }

            while (gameObjectsList.Count > 0)
            {
                current = gameObjectsList[gameObjectsList.Count - 1];
                gameObjectsList.RemoveAt(gameObjectsList.Count - 1);

                if (!current.HaveCollision)
                {
                    PrintGameObject.PrintObject(current);
                    newGameObjectsList.Add(current);
                }
            }

            if (plane.Lives < 0)
            {
                settings.GameOver = true;
                sounds.GameOver();
                break;
            }

            gameObjectsList = newGameObjectsList;
            newGameObjectsList = new List<GameObject>();

            while (Console.KeyAvailable)
            {

                plane.Clear();
                ConsoleKeyInfo keyPressed = Console.ReadKey(true);

                if (keyPressed.Key == ConsoleKey.UpArrow)
                {
                    plane.Position.X--;

                    if (plane.Position.X < 1)
                    {
                        plane.Position.X = 1;
                    }
                }

                if (keyPressed.Key == ConsoleKey.DownArrow)
                {
                    plane.Position.X++;

                    if (plane.Position.X > settings.Height - plane.PlaneHeight)
                    {
                        plane.Position.X = settings.Height - plane.PlaneHeight;
                    }
                }

                if (keyPressed.Key == ConsoleKey.LeftArrow)
                {
                    plane.Position.Y--;

                    if (plane.Position.Y < 0)
                    {
                        plane.Position.Y = 0;
                    }
                }

                if (keyPressed.Key == ConsoleKey.RightArrow)
                {
                    plane.Position.Y++;

                    if (plane.Position.Y > settings.Width - plane.PlaneWidth)
                    {
                        plane.Position.Y = settings.Width - plane.PlaneWidth;
                    }
                }

                if (keyPressed.Key == ConsoleKey.Spacebar)
                {
                    projectile = new Projectile(new Point(plane.Position.X - 1, plane.Position.Y + plane.PlaneWidth / 2));

                    if (CheckCollisionWhitOtherObject(projectile.UpLeftCorner))
                    {
                        projectile.HaveCollision = true;
                        sounds.DestroyObject();
                        settings.Score += 5;
                    }
                    else
                    {
                        gameObjectsList.Add(projectile);
                    }

                    PrintGameObject.PrintObject(projectile);
                }

                if (keyPressed.Key == ConsoleKey.P)
                {
                    PauseScreenPage pause = new PauseScreenPage();
                    pause.PauseMain();
                    settings.Pause = !settings.Pause;
                    Console.ReadKey();
                    Console.Clear();
                }

                plane.SetPlaneCoordinates();
                bool haveCollision = CheckPlaneCollision();

                if (haveCollision)
                {
                    plane.Lives--;
                    sounds.Crash();
                }

                if (plane.Lives < 0)
                {
                    settings.GameOver = true;
                    sounds.GameOver();
                    break;
                }

                plane.Print();
            }

            while (gameObjectsList.Count > 0)
            {
                current = gameObjectsList[gameObjectsList.Count - 1];
                gameObjectsList.RemoveAt(gameObjectsList.Count - 1);

                PrintGameObject.ClearObject(current);

                current.Move();
                current.SetPositionsCoordinates();

                if (CheckCollisionWithPlane(current, plane))
                {
                    current.HaveCollision = true;
                    if (current.Symbol != '$' && current.Symbol!= '^')
                    {
                        plane.Lives--;
                    }
                    else if (current.Symbol == '$')
                    {
                        settings.Score += 10;
                    }
                    sounds.Crash();
                }
                else if (CheckCollisionWhitOtherObject(current.UpLeftCorner))
                {
                    current.HaveCollision = true;
                    sounds.DestroyObject();
                    settings.Score += 5;
                }
                else
                {
                    PrintGameObject.PrintObject(current);
                    newGameObjectsList.Add(current);
                }
            }

            gameObjectsList = newGameObjectsList;
            newGameObjectsList = new List<GameObject>();

            status.Score = settings.Score;
            status.Lives = plane.Lives;
            Thread.Sleep(sleepTime);
        }

        Settings.PrintGameOver(status.Score);
    }