예제 #1
0
    public void HandleInput()
    {
        const int SPEED = 5;

        if (SplashKit.KeyDown(KeyCode.RightKey))
        {
            X = X + SPEED;
        }
        else if (SplashKit.KeyDown(KeyCode.LeftKey))
        {
            X = X - SPEED;
        }
        else if (SplashKit.KeyDown(KeyCode.UpKey))
        {
            Y = Y - SPEED;
        }
        else if (SplashKit.KeyDown(KeyCode.DownKey))
        {
            Y = Y + SPEED;
        }
        if (SplashKit.KeyDown(KeyCode.EscapeKey))
        {
            Quit = true;
        }
        if (Lives <= 0)
        {
            SplashKit.ClearScreen(Color.Black);
            SplashKit.DrawText("GAME OVER! ", Color.White, 300, 300);
            //Quit = true;
        }
    }
예제 #2
0
        public static void Main()
        {
            Shape myshape = new Shape();

            new Window("Shape Drawer", 800, 600);
            do
            {
                SplashKit.ProcessEvents();
                SplashKit.ClearScreen();
                myshape.Draw();

                if (SplashKit.MouseClicked(MouseButton.LeftButton))
                {
                    myshape.X     = SplashKit.MouseX();
                    myshape.Y     = SplashKit.MouseY();
                    myshape.color = SplashKit.ColorGreen();
                }

                if (myshape.IsAt(SplashKit.MousePosition()))
                {
                    if (SplashKit.KeyTyped(KeyCode.SpaceKey))
                    {
                        myshape.color = SplashKit.RandomColor();
                    }
                }

                SplashKit.RefreshScreen();
            } while (!SplashKit.WindowCloseRequested("Shape Drawer"));
        }
예제 #3
0
파일: Program.cs 프로젝트: tonyphan04/OOP
        public static void Main()
        {
            Bitmap    background = SplashKit.LoadBitmap("background1", "background1.png");
            Aircraft  a          = new Aircraft();
            GameRules gr         = new GameRules();

            new Window("Aircraft One", 600, 800);

            while (!SplashKit.WindowCloseRequested("Aircraft One"))
            {
                SplashKit.ProcessEvents();
                SplashKit.ClearScreen();
                if (a.Lives > 0)
                {
                    SplashKit.DrawBitmap(background, 0, -100);
                    SplashKit.DrawText("Lives:" + a.Lives, Color.White, 5, 10);
                    SplashKit.DrawText("Score:" + a.Score, Color.White, 5, 30);
                    a.Draw();
                    a.Move();
                    SplashKit.HideMouse();
                    gr.ResetCollector();
                    gr.AddItem();
                    gr.DrawItem();
                    gr.MoveItem();
                    gr.AddObstacle();
                    gr.DrawObstacle();
                    gr.MoveProjectile();
                    gr.MoveObstacle();
                    gr.DrawProjectile();
                    gr.AddProjectile(a);
                    gr.Healing(a);
                    gr.Collision(a);
                    gr.CollisionProjectile(a);
                    if (a.Lives <= 0)
                    {
                        a.Alive = false;
                    }

                    if (a.Alive == false)
                    {
                        a.Lives          -= 1;
                        a.ProjectileImage = SplashKit.LoadBitmap("hadoken", "hadoken.png");
                        a.X     = SplashKit.MouseX();
                        a.Y     = SplashKit.MouseY();
                        a.Alive = true;
                    }
                    gr.CheckObstacle(a);
                    gr.Check();
                    gr.RemoveObj();
                }
                else
                {
                    SplashKit.DrawText("Game Over", Color.Black, 300, 100);
                    SplashKit.ShowMouse();
                }


                SplashKit.RefreshScreen();
            }
        }
예제 #4
0
    public static void Main()
    {
        new Window("Shape Drawer", 800, 600);
        var shape = new Shape(Color.Red, 300, 200, 100, 100);

        do
        {
            SplashKit.ProcessEvents();
            SplashKit.ClearScreen();

            shape.Draw();

            if (SplashKit.MouseClicked(MouseButton.LeftButton))
            {
                shape.X = SplashKit.MouseX();
                shape.Y = SplashKit.MouseY();
            }

            if (SplashKit.KeyTyped(KeyCode.SpaceKey) && shape.IsAt(SplashKit.MousePosition()))
            {
                Color newColor = SplashKit.RandomRGBColor(255);
                shape.Color = newColor;
            }

            if (SplashKit.KeyTyped(KeyCode.EscapeKey))
            {
                SplashKit.CloseAllWindows();
            }

            SplashKit.RefreshScreen();
        } while (!SplashKit.WindowCloseRequested("Shape Drawer"));
    }
예제 #5
0
    public static void Main()
    {
        new Window("Minesweeper", Constants.WINDOW_WIDTH, Constants.WINDOW_HEIGHT);

        do
        {
            /*
             *  this solution seems to work fine.
             *  Normal loop usually runs under 1 milliseconds in each loop (for fast cases)
             *  and may be because of large overhead
             *  when the multiplayer game is trying to connect to the server
             *  that SplashKit will instantly froze the whole window at that time.
             *  Therefore, by adding a little delay
             *  that is unnoticeable to most players (in this case, 5 millisecs),
             *  it helps the loop go over that huge overhead
             *  (my hunch for something can never be true, though)
             *  NOTE: this is entirely my trial and errors attempts
             *  and even if I search this situation up on Google,
             *  nothing will even match what I am going through...
             */
            Task.Delay(5).Wait();

            // refresh window
            SplashKit.RefreshScreen();
            SplashKit.ProcessEvents();

            if (SplashKit.MouseClicked(MouseButton.LeftButton))
            {
                UI.CurrentPage.Click(MouseButton.LeftButton);
            }

            if (SplashKit.MouseClicked(MouseButton.RightButton))
            {
                if (UI.CurrentPage is GamePage)
                {
                    (UI.CurrentPage as GamePage).Click(MouseButton.RightButton);
                }
                if (UI.CurrentPage is MultiplayerPage)
                {
                    (UI.CurrentPage as MultiplayerPage).Click(MouseButton.RightButton);
                }
            }

            if (SplashKit.KeyTyped(KeyCode.EscapeKey))
            {
                UI.Back();
            }

            // clear window with background color
            SplashKit.ClearScreen(Constants.BACKGROUND_COLOR);

            // draw everything to the screen(s)
            UI.CurrentPage.Draw();
        } while (!SplashKit.WindowCloseRequested("Minesweeper"));

        // trigger automatic cleanup so that there is no need to copy code anymore
        UI.Back();
        SplashKit.FreeAllJson();
    }
예제 #6
0
 public void Draw()
 {
     SplashKit.ClearScreen(_background);
     foreach (Shape shape in _shapes)
     {
         shape.Draw();
     }
 }
예제 #7
0
        public static void Main()
        {
            Bitmap   background = SplashKit.LoadBitmap("background", "background.png");
            Chicken  c          = new Chicken();
            GameMain game       = new GameMain();

            new Window("Chicken Invaders", 600, 800);
            while (!SplashKit.WindowCloseRequested("Chicken Invaders"))
            {
                SplashKit.ProcessEvents();
                SplashKit.ClearScreen();
                if (c.Hearts > 0)
                {
                    SplashKit.DrawBitmap(background, 0, -100);
                    SplashKit.DrawText("Hearts: " + c.Hearts, Color.Black, 5, 10);
                    SplashKit.DrawText("Score: " + c.Score, Color.Black, 5, 30);
                    c.Draw();
                    c.Move();
                    SplashKit.HideMouse();
                    game.ResetCollector();
                    game.AddHeart();
                    game.DrawHeart();
                    game.MoveHeart();
                    game.DrawObstacle();
                    game.AddObstacle();
                    game.MoveBullet();
                    game.DrawBullet();
                    game.MoveObstacle();
                    game.AddBullet(c);
                    game.Recover(c);
                    game.Collision(c);
                    game.CollisionBullet(c);

                    if (c.Hearts <= 0)
                    {
                        c.Alive = false;
                    }

                    if (c.Alive == false)
                    {
                        c.Hearts      = c.Hearts - 1;
                        c.BulletImage = SplashKit.LoadBitmap("bullet", "bullet.png");
                        c.X           = SplashKit.MouseX();
                        c.Y           = SplashKit.MouseY();
                        c.Alive       = true;
                    }
                    game.CheckObstacle(c);
                    game.Check();
                    game.RemoveObject();
                }
                else
                {
                    SplashKit.DrawText("Game Over", Color.Black, 260, 400);
                    SplashKit.ShowMouse();
                }
                SplashKit.RefreshScreen();
            }
        }
예제 #8
0
파일: Program.cs 프로젝트: LyanAzidie/snake
        public static void Main()
        {
            new Window("Snake-Remake", 800, 600);
            double x = 0.0, y = 0.0;
            double speed = 5.0;

            Map   snakeMap = new Map();
            Snake mySnake  = new Snake();

            snakeMap.Add(mySnake);
            Food food = new Food();

            snakeMap.Add(food);

            do
            {
                SplashKit.ProcessEvents();
                SplashKit.ClearScreen(Color.Black);
                mySnake.Update(x, y);
                snakeMap.Draw(x, y);

                if (SplashKit.KeyTyped(KeyCode.UpKey))
                {
                    x = 0;
                    y = -1 * speed;
                }

                if (SplashKit.KeyTyped(KeyCode.DownKey))
                {
                    x = 0;
                    y = speed;
                }

                if (SplashKit.KeyTyped(KeyCode.RightKey))
                {
                    x = speed;
                    y = 0;
                }

                if (SplashKit.KeyTyped(KeyCode.LeftKey))
                {
                    x = -1 * speed;
                    y = 0;
                }

                if (snakeMap.HasCollided(mySnake, food))
                {
                    snakeMap.Collide(mySnake, food, x * 150, y * 150);
                    food = new Food();
                    snakeMap.Add(food);
                }

                SplashKit.Delay(10);
                SplashKit.RefreshScreen();
            } while (!snakeMap.Lose(mySnake) || !SplashKit.WindowCloseRequested("Shape Drawer"));
        }
예제 #9
0
        public void Display()
        {
            SplashKit.ProcessEvents();
            SplashKit.ClearScreen();
            SplashKit.DrawBitmap("Background", 0, 0);
            Game.getInstance().LoadLevel(true);
            Game.getInstance().DisplayText.Clear();
            if (!startup)
            {
                Game.getInstance().Buttons.Clear();
                Game.getInstance().ButtonColor.Clear();
                Game.getInstance().ButtonColor.AddRange(Enumerable.Repeat(Game.getInstance().DefaultColor, 3));
                startup = true;
            }
            Game.getInstance().ButtonColor.AddRange(Enumerable.Repeat(Game.getInstance().DefaultColor, 3));
            Game.getInstance().DisplayText.Add(new Text("Paradigm  Jump", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 75, 50, 50));
            Game.getInstance().DisplayText.Add(new Text("Start", Game.getInstance().ButtonColor[0], Game.getInstance().DefaultFont, 35, 340, 175));
            Game.getInstance().DisplayText.Add(new Text("Exit", Game.getInstance().ButtonColor[1], Game.getInstance().DefaultFont, 35, 355, 250));
            Game.getInstance().DisplayText.Add(new Text("Modifier", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 25, 570, 180));
            Game.getInstance().DisplayText.Add(new Text("NoFail", Game.getInstance().ButtonColor[2], Game.getInstance().DefaultFont, 20, 560, 230));
            Game.getInstance().DisplayText.Add(new Text("Fast", Game.getInstance().ButtonColor[3], Game.getInstance().DefaultFont, 20, 575, 280));
            Game.getInstance().DisplayText.Add(new Text("Easy", Game.getInstance().ButtonColor[4], Game.getInstance().DefaultFont, 20, 575, 330));
            Game.getInstance().DisplayText.Add(new Text("Can't Fail", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 10, 660, 235));
            Game.getInstance().DisplayText.Add(new Text("Faster and", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 10, 660, 280));
            Game.getInstance().DisplayText.Add(new Text("Smaller Cubes", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 10, 660, 290));
            Game.getInstance().DisplayText.Add(new Text("Slower and", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 10, 660, 330));
            Game.getInstance().DisplayText.Add(new Text("Bigger Cubes", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 10, 660, 340));
            Game.getInstance().DisplayText.Add(new Text("How to play", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 25, 50, 180));
            Game.getInstance().DisplayText.Add(new Text("A - Move Left", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 50, 220));
            Game.getInstance().DisplayText.Add(new Text("D - Move Right", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 50, 240));
            Game.getInstance().DisplayText.Add(new Text("S - Drop Down", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 50, 260));
            Game.getInstance().DisplayText.Add(new Text("Space - Jump", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 50, 280));
            Game.getInstance().DisplayText.Add(new Text("RShift - Dash", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 50, 300));
            int index = Game.getInstance().Buttons.FindIndex(f => f.Width == 160);

            if (index == -1)
            {
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 320, 170, 160, 50));
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 320, 245, 160, 50));
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 550, 220, 100, 40));
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 550, 270, 100, 40));
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 550, 320, 100, 40));
            }
            Game.getInstance().Modifier.Toggle();
            foreach (GameObject o in Game.getInstance().Objects)
            {
                o.Draw();
            }
            foreach (HP o in Game.getInstance().HP)
            {
                o.Draw();
            }
        }
예제 #10
0
 public void Loop()
 {
     SplashKit.ProcessEvents();
     if (SplashKit.KeyDown(KeyCode.EscapeKey))
     {
         Game.getInstance().SetState(new Paused());
     }
     Game.getInstance().Update();
     Game.getInstance().HandleInput();
     SplashKit.ClearScreen();
     Game.getInstance().Draw();
     SplashKit.RefreshScreen(144);
 }
예제 #11
0
        public static void Main()
        {
            SplashKit.LoadFont("Roboto Regular", "fonts/Roboto-Regular.ttf");
            SplashKit.LoadFont("Roboto Bold", "fonts/Roboto-Bold.ttf");
            Puzzles.LoadPuzzles("puzzles.txt");

            Window window = new Window("Sudoku", 800, 600);
            Sudoku sudoku = new Sudoku(Puzzles.GetRandomPuzzle(), SplashKit.ScreenCenter());

            do
            {
                SplashKit.ProcessEvents();
                SplashKit.ClearScreen();

                sudoku.Update();
                sudoku.Draw(window);

                SplashKit.RefreshScreen();
            } while (!SplashKit.WindowCloseRequested("Sudoku"));
        }
예제 #12
0
        public void Display()
        {
            Game.getInstance().Timer.Pause();
            SplashKit.PauseMusic();
            SplashKit.ProcessEvents();
            SplashKit.ClearScreen();
            SplashKit.DrawBitmap("Background", 0, 0);
            Game.getInstance().ProgressBar();
            Game.getInstance().DisplayText.Clear();
            if (!startup)
            {
                Game.getInstance().Buttons.Clear();
                Game.getInstance().ButtonColor.Clear();
                Game.getInstance().ButtonColor.AddRange(Enumerable.Repeat(Game.getInstance().DefaultColor, 3));
                startup = true;
            }
            Game.getInstance().DisplayText.Add(new Text("Game Over", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 40, 275, 110));
            Game.getInstance().DisplayText.Add(new Text("Retry", Game.getInstance().ButtonColor[0], Game.getInstance().DefaultFont, 35, 340, 175));
            Game.getInstance().DisplayText.Add(new Text("Exit", Game.getInstance().ButtonColor[1], Game.getInstance().DefaultFont, 35, 355, 250));
            Game.getInstance().Player.Draw();
            Game.getInstance().Modifier.drawScore();
            int index = Game.getInstance().Buttons.FindIndex(f => f.Width == 160);

            if (index == -1)
            {
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 320, 170, 160, 50));
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 320, 245, 160, 50));
            }
            foreach (GameObject o in Game.getInstance().Objects)
            {
                o.Draw();
            }
            foreach (HP o in Game.getInstance().HP)
            {
                o.Draw();
            }
            foreach (GameObject o in Game.getInstance().HitObjects)
            {
                o.Draw();
            }
        }
예제 #13
0
        public void Draw()
        {
            SplashKit.ClearScreen();
            SplashKit.DrawBitmap("Background", 0, 0);
            foreach (GameObject o in Objects)
            {
                o.Draw();
            }
            if (HP.Count > 0)
            {
                for (int i = 0; i < HP.Count; i++)
                {
                    if (HP[i].Hit)
                    {
                        HP.Remove(HP[i]);
                    }
                    else
                    {
                        HP[i].Draw();
                    }
                }
            }
            if (HitObjects.Count > 0)
            {
                for (int i = 0; i < HitObjects.Count; i++)
                {
                    if (HitObjects[i].Y >= SplashKit.ScreenHeight() || HitObjects[i].Hit)
                    {
                        HitObjects.Remove(HitObjects[i]);
                    }
                    else
                    {
                        HitObjects[i].Draw();
                    }
                }
            }

            Player.Draw();
            Modifier.drawScore();
            ProgressBar();
        }
예제 #14
0
 public void RefreshScreen()
 {
     SplashKit.RefreshScreen();
     SplashKit.ClearScreen();
 }
예제 #15
0
 public override void OpenGameWindow(int cols, int rows)
 {
     new Window("BomberMan - Wright Edition", cols * Settings.CellWidth, rows * Settings.CellHeight);
     SplashKit.ClearScreen(Color.Gray);
 }
예제 #16
0
파일: Program.cs 프로젝트: LyanAzidie/tank
    public static void Main()
    {
        int level = 0;
        int counter = 0, shootCoolDown = 0;
        int windowWidth  = 1200;
        int windowHeight = 900;
        int speed        = 5;

        // new shape and window opened
        new Window("Tank Game", windowWidth, windowHeight);

        // required objects
        Map        gameMap    = Map.GetInstance(1);
        LivesBoard scoreBoard = LivesBoard.GetInstance(gameMap);
        Fort       fort       = new Fort(gameMap);
        Player     player     = new Player(gameMap);
        EnemyPool  enemyPool  = EnemyPool.GetInstance(1, gameMap);

        do
        {
            SplashKit.ProcessEvents();
            SplashKit.ClearScreen();
            gameMap.DrawObjects();
            scoreBoard.Draw(windowWidth, windowHeight);

            // load map - if new map is needed
            if (level != gameMap.Level)
            {
                level = gameMap.LoadNextLevel(level);
                enemyPool.UpdateMax(level);
            }

            // generate new enemies if needed
            if (SplashKit.Rnd(1, 500) <= 5)
            {
                enemyPool.GenerateEnemy(windowWidth, windowHeight);
            }

            // demo - turn up, down, left, right
            if (SplashKit.KeyDown(KeyCode.UpKey))
            {
                player.Move(0, speed);
            }
            else if (SplashKit.KeyDown(KeyCode.DownKey))
            {
                player.Move(0, -1 * speed);
            }
            else if (SplashKit.KeyDown(KeyCode.LeftKey))
            {
                player.Move(speed, 0);
            }
            else if (SplashKit.KeyDown(KeyCode.RightKey))
            {
                player.Move(-1 * speed, 0);
            }

            // press space - player shoot
            if (SplashKit.KeyTyped(KeyCode.SpaceKey) && shootCoolDown > 50)
            {
                player.Shoot();
                shootCoolDown = 0;
            }

            // generate a random powerup
            if (counter >= 500 && gameMap.CountObjects("item") < 1)
            {
                gameMap.GenerateRndItem(windowWidth, windowHeight);
                counter = 0;
            }

            // delete the powerUp after awhile, also cancels powerups
            if (gameMap.CountObjects("item") > 0 && counter >= 500)
            {
                gameMap.RemoveObject(gameMap.GetObject("item"));
                counter = 0;
            }

            // cancels powerup effects after a while
            if (player.FireRate == 3 && counter >= 400)
            {
                player.FireRate = 1;
                shootCoolDown   = 0;
            }

            gameMap.Update();
            shootCoolDown++;
            counter++;
            SplashKit.RefreshScreen(60);
        } while (!SplashKit.WindowCloseRequested("Tank Game"));
    }
예제 #17
0
        public static void Main()
        {
            Shape.RegisterShape("Rectangle", typeof(MyRectangle));
            Shape.RegisterShape("Circle", typeof(MyCircle));
            Shape.RegisterShape("Line", typeof(MyLine));
            ShapeKind kindToAdd = ShapeKind.Circle;
            Drawing   drawing   = new Drawing();

            new Window("Shape Drawer", 800, 600);
            do
            {
                SplashKit.ProcessEvents();
                SplashKit.ClearScreen();

                if (SplashKit.KeyTyped(KeyCode.RKey))
                {
                    kindToAdd = ShapeKind.Rectangle;
                }

                if (SplashKit.KeyTyped(KeyCode.CKey))
                {
                    kindToAdd = ShapeKind.Circle;
                }

                if (SplashKit.KeyTyped(KeyCode.LKey))
                {
                    kindToAdd = ShapeKind.Line;
                }

                if (SplashKit.MouseClicked(MouseButton.LeftButton))
                {
                    Shape newShape;

                    if (kindToAdd == ShapeKind.Circle)
                    {
                        MyCircle newCircle = new MyCircle();
                        newShape = newCircle;
                    }
                    else if (kindToAdd == ShapeKind.Rectangle)
                    {
                        MyRectangle newRect = new MyRectangle();
                        newShape = newRect;
                    }
                    else
                    {
                        MyLine newLine = new MyLine();
                        newShape = newLine;
                    }

                    newShape.X = SplashKit.MouseX();
                    newShape.Y = SplashKit.MouseY();

                    drawing.AddShape(newShape);
                }

                if (SplashKit.KeyTyped(KeyCode.SpaceKey))
                {
                    drawing.Background = Color.RandomRGB(255);
                }

                if (SplashKit.MouseClicked(MouseButton.RightButton))
                {
                    drawing.SelectShapesAt(SplashKit.MousePosition());
                }

                if (SplashKit.KeyTyped(KeyCode.BackspaceKey))
                {
                    drawing.SelectShapesAt(SplashKit.MousePosition());
                    drawing.DeleteShapes(drawing.SelectedShapes);
                }

                if (SplashKit.KeyTyped(KeyCode.SKey))
                {
                    drawing.Save("/home/lw/code/university/cos20007/2.2P/ShapeDrawer/TestDrawing.txt");
                }

                if (SplashKit.KeyTyped(KeyCode.OKey))
                {
                    try
                    {
                        drawing.Load("/home/lw/code/university/cos20007/2.2P/ShapeDrawer/TestDrawing.txt");
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error loading file: {0}", e.Message);
                    }
                }

                drawing.Draw();
                SplashKit.RefreshScreen();
            } while (!SplashKit.WindowCloseRequested("Shape Drawer"));
        }
예제 #18
0
        public void Display()
        {
            SplashKit.ProcessEvents();
            SplashKit.ClearScreen();
            SplashKit.DrawBitmap("Background", 0, 0);
            string rank;
            float  percentage = (float)Game.getInstance().Hits / (float)Game.getInstance().TotalHits;

            Game.getInstance().DisplayText.Clear();
            if (!startup)
            {
                Game.getInstance().Buttons.Clear();
                Game.getInstance().ButtonColor.Clear();
                Game.getInstance().ButtonColor.AddRange(Enumerable.Repeat(Game.getInstance().DefaultColor, 3));
                startup = true;
            }
            SplashKit.DrawRectangle(Game.getInstance().DefaultColor, 195, 150, 450, 95);
            Game.getInstance().DisplayText.Add(new Text("Level Complete", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 40, 225, 90));
            Game.getInstance().DisplayText.Add(new Text($"Score: {Game.getInstance().Score}", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 200, 160));
            Game.getInstance().DisplayText.Add(new Text($"Highest Combo: {Game.getInstance().Combo}", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 200, 180));
            Game.getInstance().DisplayText.Add(new Text($"Bombs Hit: {Game.getInstance().LivesUsed}", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 200, 200));
            Game.getInstance().DisplayText.Add(new Text($"Hits: {Game.getInstance().Hits} / {Game.getInstance().TotalHits}", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 200, 220));
            if (percentage == 1)
            {
                rank = "S+";
            }
            else if (percentage >= 0.9)
            {
                rank = "S";
            }
            else if (percentage >= 0.8)
            {
                rank = "A";
            }
            else if (percentage >= 0.7)
            {
                rank = "B";
            }
            else if (percentage >= 0.5)
            {
                rank = "C";
            }
            else if (percentage >= 0.2)
            {
                rank = "D";
            }
            else
            {
                rank = "F";
            }
            Game.getInstance().DisplayText.Add(new Text("Rank", Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 15, 580, 170));
            Game.getInstance().DisplayText.Add(new Text(rank, Game.getInstance().DefaultColor, Game.getInstance().DefaultFont, 35, 592, 190));
            Game.getInstance().DisplayText.Add(new Text("Retry", Game.getInstance().ButtonColor[0], Game.getInstance().DefaultFont, 35, 245, 270));
            Game.getInstance().DisplayText.Add(new Text("Exit", Game.getInstance().ButtonColor[1], Game.getInstance().DefaultFont, 35, 450, 270));
            int index = Game.getInstance().Buttons.FindIndex(f => f.Width == 160);

            if (index == -1)
            {
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 230, 265, 160, 50));
                Game.getInstance().Buttons.Add(new Button(Game.getInstance().DefaultColor, 415, 265, 160, 50));
            }
            foreach (GameObject o in Game.getInstance().Objects)
            {
                o.Draw();
            }
            foreach (HP o in Game.getInstance().HP)
            {
                o.Draw();
            }
            foreach (Button o in Game.getInstance().Buttons)
            {
                o.Draw();
            }
            Game.getInstance().Player.Draw();
        }
예제 #19
0
        public static void Main()
        {
            /*
             *  Points to button last clicked by the user. A value of null
             *  indicates that there is no active button
             */
            Button activeButton = null;
            Window shapesWindow;

            shapesWindow = new Window("Path Finding Visualizer", 1366, 768);
            InitUI();
            solver.TaskDelayTime = (int)animationDelaySlider.SliderValue;

            do
            {
                SplashKit.ProcessEvents();
                SplashKit.ClearScreen(Color.White);
                DrawUI();

                if (animationDelaySlider.HasBeenClicked(MouseButton.LeftButton))
                {
                    solver.TaskDelayTime = (int)animationDelaySlider.SliderValue;
                }

                // if there is no active button, sets a clicked button as teh active button
                if (!(activeButton is Button) || activeButton == drawOptionUserButton)
                {
                    if (setStartingPointButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        setStartingPointButton.Active = true;
                        activeButton = setStartingPointButton;
                    }
                    else if (setEndingPointButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        setEndingPointButton.Active = true;
                        activeButton = setEndingPointButton;
                    }
                    else if (solveDijiButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        solveDijiButton.Active = true;
                        activeButton           = solveDijiButton;
                    }
                    else if (solveAstarButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        solveAstarButton.Active = true;
                        activeButton            = solveAstarButton;
                    }
                    else if (drawOptionUserButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        drawOptionUserButton.Active = true;
                        activeButton = drawOptionUserButton;
                    }
                    else if (drawOptionRandomButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        drawOptionRandomButton.Active = true;
                        activeButton = drawOptionRandomButton;
                    }
                    else if (drawOptionMazeButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        drawOptionMazeButton.Active = true;
                        activeButton = drawOptionMazeButton;
                    }
                    else if (clearGridButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        clearGridButton.Active = true;
                        activeButton           = clearGridButton;
                    }
                    else if (clearPathButton.HasBeenClicked(MouseButton.LeftButton))
                    {
                        clearPathButton.Active = true;
                        activeButton           = clearPathButton;
                    }

                    if (drawOptionUserButton.Active && activeButton != drawOptionUserButton)
                    {
                        drawOptionUserButton.Active = false;
                    }
                }
                // if active button is set and is clicked again, removes it as active button
                else if (activeButton.HasBeenClicked(MouseButton.LeftButton))
                {
                    activeButton.Active = false;
                    activeButton        = null;
                }

                // depending on the active button different functionality are carried out
                if (setStartingPointButton.Active && (grid.IsAt(SplashKit.MousePosition()) && SplashKit.MouseClicked(MouseButton.LeftButton)))
                {
                    Cell clickedCell = grid.GetTargetCell(SplashKit.MousePosition());
                    if (startingCell is Cell && (startingCell != clickedCell))
                    {
                        startingCell.ForegroudColor = Color.White;
                    }
                    if (clickedCell is Cell)
                    {
                        startingCell = clickedCell;
                        startingCell.ForegroudColor = Color.LimeGreen;
                    }
                    setStartingPointButton.Active = false;
                    activeButton = null;
                }
                else if (setEndingPointButton.Active && (grid.IsAt(SplashKit.MousePosition()) && SplashKit.MouseClicked(MouseButton.LeftButton)))
                {
                    Cell clickedCell = grid.GetTargetCell(SplashKit.MousePosition());
                    if (endingCell is Cell && (endingCell != clickedCell))
                    {
                        endingCell.ForegroudColor = Color.White;
                    }
                    if (clickedCell is Cell)
                    {
                        endingCell = clickedCell;
                        endingCell.ForegroudColor = Color.Red;
                    }
                    setEndingPointButton.Active = false;
                    activeButton = null;
                }
                else if (solveAstarButton.Active)
                {
                    if (startingCell is Cell && endingCell is Cell)
                    {
                        grid.ResetPath();
                        solver.FindPathAstar(grid.Cells, startingCell, endingCell);
                    }

                    solveAstarButton.Active = false;
                    activeButton            = null;
                }
                else if (solveDijiButton.Active)
                {
                    if (startingCell is Cell && endingCell is Cell)
                    {
                        grid.ResetPath();
                        solver.FindPathDiji(grid.Cells, startingCell, endingCell);
                    }

                    solveDijiButton.Active = false;
                    activeButton           = null;
                }
                else if (drawOptionUserButton.Active && grid.IsAt(SplashKit.MousePosition()))
                {
                    if (SplashKit.MouseClicked(MouseButton.LeftButton) || SplashKit.MouseDown(MouseButton.LeftButton) && grid.IsAt(SplashKit.MousePosition()))
                    {
                        obstacleDrawer.DrawUser(grid, MouseButton.LeftButton);
                    }
                    else if (SplashKit.MouseClicked(MouseButton.RightButton) || SplashKit.MouseDown(MouseButton.RightButton) && grid.IsAt(SplashKit.MousePosition()))
                    {
                        obstacleDrawer.DrawUser(grid, MouseButton.RightButton);
                    }
                }
                else if (drawOptionRandomButton.Active)
                {
                    startingCell = null;
                    endingCell   = null;
                    grid.ResetGrid();
                    obstacleDrawer.DrawRandom(grid);

                    drawOptionRandomButton.Active = false;
                    activeButton = null;
                }
                else if (drawOptionMazeButton.Active)
                {
                    startingCell = null;
                    endingCell   = null;
                    grid.ResetGrid();
                    obstacleDrawer.DrawMaze(grid);

                    drawOptionMazeButton.Active = false;
                    activeButton = null;
                }
                else if (clearGridButton.Active)
                {
                    grid.ResetGrid();
                    startingCell = null;
                    endingCell   = null;

                    clearGridButton.Active = false;
                    activeButton           = null;
                }
                else if (clearPathButton.Active)
                {
                    grid.ResetPath();
                    if (startingCell is Cell)
                    {
                        startingCell.ForegroudColor = Color.LimeGreen;
                    }
                    if (endingCell is Cell)
                    {
                        endingCell.ForegroudColor = Color.Red;
                    }

                    clearPathButton.Active = false;
                    activeButton           = null;
                }


                grid.Draw();
                // draws the flag sprites on the starting and ending cells
                if (startingCell is Cell)
                {
                    green_flag.X = (float)startingCell.X - 2;
                    green_flag.Y = (float)startingCell.Y - 30;
                    green_flag.Draw();
                }
                if (endingCell is Cell)
                {
                    red_flag.X = (float)endingCell.X - 2;
                    red_flag.Y = (float)endingCell.Y - 30;
                    red_flag.Draw();
                }
                SplashKit.RefreshScreen(60);
            } while(!SplashKit.QuitRequested());
        }