⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameengine.java

📁 Java based Snakes and Ladders game.
💻 JAVA
字号:
// The main game engine, this is where half the work takes placepublic class GameEngine{    // The Variables of the GameEngine        private Player player1, player2, currentPlayer;        private Player player;        private Dice dice;        private Gui gui;        private int playerCurrent;                // Set the game Array        private int[][] gameArray;    // The constructor of the GameEngine    public GameEngine(){        gui = new Gui();        // Settings player variables.        player1 = new Player("Player 1");        player2 = new Player("Player 2");        currentPlayer = player1;                playerCurrent = 1;        // this.player = currentPlayer; - Moved to RunGame        // Set the game Array size        gameArray = new int[49][2];                gameArray[0][1] = 0;        gameArray[1][1] = 5;    }    // Setting the game ready to play new    public void NewGame(){            }        // The methods of the GameEngine    public void RunGame(){        this.player = currentPlayer;        int playerSquare = player.playerRoll();                // Check for Snakes / Ladders / Competition        if(gameArray[playerSquare][1] == 1){            player.writePlayerPos( playerSquare + gameArray[playerSquare][2]);        }        if(gameArray[playerSquare][1] == 2){            player.writePlayerPos( playerSquare - gameArray[playerSquare][2]);        }        if(gameArray[playerSquare][1] == 3){            // END GAME HERE        }               gui.drawPlayer(playerSquare);                // Write the player possition        player.writePlayerPos(playerSquare);        changePlayer();        }        // The methods of the GameEngine    public void changePlayer(){        // Switch the players        if (currentPlayer == player1) {                currentPlayer = player2;                playerCurrent = 2;        } else if (currentPlayer == player2) {                currentPlayer = player1;                playerCurrent = 1;        } else {            // Check to make sure player = Legit                System.out.println ("Too Many Players");                System.exit (1);        }    }        public int playerCurrent(){        return playerCurrent;    }        public void debug(){        System.out.println(gameArray[1][1]);    }   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -