Ejemplo n.º 1
0
        public static void Run()
        {
            while (true)
            {
                ConsoleGraphics graphics = new ConsoleGraphics();
                GameEngine      engine   = new ArkanoidGameEngine(graphics);
                engine.Start();

                graphics.DrawString("FOR NEW GAME PRESS SPASE\n  FOR EXIT GAME PRESS ESC", "Arial", 0xFF000080, 460, 450, 20);
                graphics.DrawString("(FOR RESET BEST SCORS  PRESS (R)", "Arial", 0xFF000080, 530, 550, 10);
                graphics.FlipPages();

                while (Console.KeyAvailable)
                {
                    Console.ReadKey();
                }
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                ConsoleKey     key     = keyInfo.Key;

                if (key == ConsoleKey.Escape)
                {
                    break;
                }

                if (key == ConsoleKey.R)
                {
                    Scors.WriteInFileBestScors(0);
                    Scors.SetBestScors(0);
                }
            }
        }
Ejemplo n.º 2
0
        public override void Update(GameEngine engine)
        {
            int W = graphics.ClientWidth;
            int H = graphics.ClientHeight;

            if (isBallStandingOnBoard)
            {
                if (X < W - 70)
                {
                    if (Input.IsKeyDown(Keys.RIGHT))
                    {
                        X += 25;
                    }
                }

                if (X > 50)
                {
                    if (Input.IsKeyDown(Keys.LEFT))
                    {
                        X -= 25;
                    }
                }
            }

            if (Input.IsKeyDown(Keys.UP))
            {
                isBallStandingOnBoard = false;
            }

            if (!isBallStandingOnBoard)
            {
                X += Vx;
                Y += Vy;
                if (X <= 0 || X >= W - 5)
                {
                    Vx = -Vx;
                }
                if (Y <= 0)
                {
                    Vy = -Vy;
                }
                bool ballHasChangeDirection    = true;
                List <CGameObject> gameObjects = gameEngine.GetCollisions(this);
                foreach (var gO in gameObjects)
                {
                    if (gO is Board)
                    {
                        Vy = -Vy;
                    }
                    if (gO is Blocks)
                    {
                        BallCrushedBlocksCnt++;
                        if (ballHasChangeDirection)
                        {
                            Vy = -Vy;
                        }
                        ballHasChangeDirection = false;
                        gameEngine.RemoveGameObj(gO);
                        Scors.AddScors(10);
                    }
                }
                if (Y > graphics.ClientHeight)
                {
                    gameEngine.RemoveGameObj(this);
                }
            }
        }