示例#1
0
        //Click event for starting the game
        public void Click(GameLoop game, Tile[] array, Board board)
        {
            //Instatiates class and randomises the tile placement
            Shuffle shuffle = new Shuffle();
            shuffle.ShuffleArray(array);

            //Creates variables
            int rowCounter  = 0;
            int colCounter  = 0;
            Tile index;

            //Loops through array of tiles
            for (int i = 0; i < array.Length; i++)
            {
                //Checks if the current tile is empty and it isn't placed in the bottom right
                if (array[i] == null && i != array.Length - 1)
                {
                    //Stores tile currently in bottom right
                    index = array[array.Length - 1];

                    //Swaps it with empty tile
                    array[array.Length - 1] = null;
                    array[i]                = index;

                }
            }

            //Loops through array of tiles
            for (int i = 0; i < array.Length; i++)
            {
                //Checks counter hasn't reached the empty tile
                if (i < array.Length - 1)
                {
                    //Assigns tile's column and row
                    array[i].Col = colCounter;
                    array[i].Row = rowCounter;

                    //Increment column counter
                    colCounter++;

                    //If the end of the row has been reached, reset column to zero and move to next row
                    if (colCounter >= 4)
                    {
                        colCounter = 0;
                        rowCounter++;
                    }

                    //Sets current tile's x and y position based on row and column
                    array[i].SetPos(board);
                }
            }

            //Tracks that the game is now in progress
            game.GameStarted = true;
        }
示例#2
0
 public void CheckClick(int x, int y, GameLoop game)
 {
     if (x >= start.X && x <= start.X + start.W && y >= start.Y && y <= start.Y + start.H)
     {
         start.Click(game);
     }
     else if (x >= options.X && x <= options.X + options.W && y >= options.Y && y <= options.Y + options.H)
     {
         options.Click(game);
     }
     else if (x >= quit.X && x <= quit.X + quit.W && y >= quit.Y && y <= quit.Y + quit.H)
     {
         quit.Click(game);
     }
 }
示例#3
0
        //Checks for input every tick
        public void Update(GameLoop game, Board board)
        {
            //Gets the current state of the mouse
            MouseState newMState = Mouse.GetState();
            KeyboardState newKState = Keyboard.GetState();
            kArray = oldKState.GetPressedKeys();
            Keys pressedKey = Keys.A;
            if (kArray.Length > 0)
            {
                pressedKey = kArray[kArray.Length - 1];
            }

            //Checks if the mouse has just been clicked by comparing the current state with the previous state
            if (newMState.LeftButton == ButtonState.Pressed && oldMState.LeftButton == ButtonState.Released)
            {
                //Logs click coordinates
                int x = newMState.X;
                int y = newMState.Y;

                //Checks if a button has been pressed before checking if a tile was clicked
                if (board.ButtonClick(x, y, game) == false)
                {
                    board.TileClick(x, y);
                    board.CheckWin();
                }
            }

            //Resets old mouse state
            oldMState = newMState;

            //Checks if keys have been pressed to end the game
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
               game.Exit();
            }

            if ((newKState.IsKeyUp(Keys.Left) && oldKState.IsKeyDown(Keys.Left)) || (newKState.IsKeyUp(Keys.Right) && oldKState.IsKeyDown(Keys.Right)) || (newKState.IsKeyUp(Keys.Down) && oldKState.IsKeyDown(Keys.Down)) || (newKState.IsKeyUp(Keys.Up) && oldKState.IsKeyDown(Keys.Up)))
            {
                board.TileKeyboard(pressedKey);
            }

            oldKState = newKState;
        }
 public void Click(GameLoop game)
 {
     game.Exit();
 }
 public void Click(GameLoop game)
 {
     game.EGameState = GameLoop.EGameStates.options;
 }
 public void Click(GameLoop game)
 {
     game.EGameState = GameLoop.EGameStates.ingame;
 }
示例#7
0
 static void Main()
 {
     using (var game = new GameLoop())
         game.Run();
 }
示例#8
0
        //Checks if a button has been pressed
        public bool ButtonClick(int x, int y, GameLoop game)
        {
            //Takes sizes and positions of buttons
            int height = start.H;
            int width = start.W;
            int startX = start.X;
            int startY = start.Y;

            //If the click coordinates are within the start button
            if (x >= startX && x <= startX + width && y >= startY && y <= startY + height)
            {
                //Call function and return bool
                start.Click(game, array, self);
                return true;
            }

            //No button was clicked
            return false;
        }