Пример #1
0
        private static void Main(string[] args)
        {
            Console.CursorVisible = false;
            Console.WindowHeight  = 20;
            Console.WindowWidth   = 31;
            Ball b1 = new Ball(15, 1, 1, 1);
            Ball b2 = new Ball(15, 1, -1, 1);
            Ball b3 = new Ball(25, 20, 1, 1);
            Ball b4 = new Ball(5, 20, -1, 1);
            Ball v1 = new VerticalBall(20, 1);
            Ball v2 = new VerticalBall(10, 1);
            Ball v3 = new VerticalBall(5, 1);
            Ball v4 = new VerticalBall(25, 1);
            Ball h1 = new HorizontalBall(5, 1);
            Ball h2 = new HorizontalBall(15, 1);
            Ball h3 = new HorizontalBall(2, 1);
            Ball h4 = new HorizontalBall(18, 1);

            Ball[] balls = new Ball[12] {
                b1, b2, b3, b4, v1, v2, v3, v4, h1, h2, h3, h4
            };
            PlayerBall player = new PlayerBall(15, 10, 0, 0);
            int        timer  = 100;

            Console.WriteLine("Try to survive!\nPress Enter.");
            Console.ReadLine();

            while (timer > 0)
            {
                Console.Clear();

                //Ball
                foreach (Ball i in balls)
                {
                    i.Update();
                    i.Draw();
                }

                //SpelerBall
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    player.ChangeVelocity(key);
                }

                player.Update();
                player.Draw();

                //Check collisions
                foreach (Ball i in balls)
                {
                    if (Ball.CheckHit(i, player))
                    {
                        Console.Clear();
                        Console.WriteLine("You Lose.");
                        Console.WriteLine($"\nSCORE: {timer}");
                        Console.ReadLine();
                    }
                }
                System.Threading.Thread.Sleep(100);
                timer--;
            }
            Console.Clear();
            Console.WriteLine("You Win!");
            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.CursorVisible = false;
            Console.WindowHeight  = 20;
            Console.WindowWidth   = 30;

            var game   = new Game();
            var stages = new GameStage[] { new GameStage(10000), new GameStage(10000), new GameStage(15000) };


            while (!game.GameOver && game.Stage < 3)
            {
                var endOfStage = false;
                var player     = new PlayerBall(10, 10, 0, 0);

                stages[game.Stage - 1].FillBalls(game.Stage);
                stages[game.Stage - 1].FillEnemies(game.Stage);
                stages[game.Stage - 1].StageSplash(game.Stage);

                while (!game.GameOver && !endOfStage)
                {
                    //Ball
                    foreach (var item in stages[game.Stage - 1].StageBalls)
                    {
                        item.Update();
                        item.Draw();
                    }

                    //EnemyBall
                    foreach (var item in stages[game.Stage - 1].StageEnemies)
                    {
                        item.Update();
                        item.Draw();
                    }

                    //SpelerBall
                    if (Console.KeyAvailable)
                    {
                        var key = Console.ReadKey();
                        player.ChangeVelocity(key);
                    }

                    player.Update();
                    player.Draw();

                    //Check collisions
                    for (int i = 0; i < stages[game.Stage - 1].StageBalls.Count; i++)
                    {
                        if (Ball.CheckHit(stages[game.Stage - 1].StageBalls[i], player))
                        {
                            game.Points += 1000;
                            stages[game.Stage - 1].StageBalls.RemoveAt(i);
                        }
                    }

                    //Check collisions with enemies
                    foreach (var item in stages[game.Stage - 1].StageEnemies)
                    {
                        if (Ball.CheckHit(item, player))
                        {
                            game.GameOver = true;
                        }
                    }

                    System.Threading.Thread.Sleep(100);
                    stages[game.Stage - 1].TimeBonus -= 10;

                    //Check if all balls are taken
                    if (stages[game.Stage - 1].StageBalls.Count == 0)
                    {
                        endOfStage = true;
                        game.Stage++;
                    }
                }

                if (!game.GameOver)
                {
                    ResultStage(game, stages[game.Stage - 2]);
                    game.Points += stages[game.Stage - 2].TimeBonus;
                }
                else
                {
                    GameOverScreen(game);
                }
            }
        }