public static void main(String[] args) { Phone tel1 = new CellPhone(); tel1.call(); tel1.message(); Phone tel2 = new SmartPhone(); tel2.call(); tel2.message(); Game game1 = new SmartPhone(); game1.playGame(); Game game2 = new PSP(); game2.playGame(); /* 使用匿名内部类实现接口方法 */ Game game3 = new Game() { @Override public void playGame() { System.out.println("interface used in unnamed class "); } }; game3.playGame(); /* 直接new实现接口函数 */ new Game() { @Override public void playGame() { System.out.println("interface used by new"); } }.playGame(); }
public void testFleeCommand() { Room room2 = new Room("a room with a monster", "room2"); room2.spawnMonster(new Monster("monster", 0, 0, 1000, 1000)); startingRoom.setExits(Exit.east, room2); game.playGame("go east"); while (game.getPlayer().inBattle()) { game.playGame("flee"); } assertTrue( "When player flees, it must go back to the previous room", game.getPlayer().getRoom() == startingRoom); }
// Initializes game and starts it. Called from server thread public ObjectTicTacToe(Message clientMessage, ObjectInputStream in, ObjectOutputStream out) { gameOngoing = true; iStream = in; oStream = out; gameState = clientMessage; Game currentGame = new Game(gameState); currentGame.playGame(); }
public static void main(String[] args) { GameCharacter player1 = new GameCharacter(); player1.setName("Felix"); player1.setRace("Dwarf"); player1.setHealthPoints(75); player1.setManaPoints(50); String direction; Scanner keyboard = new Scanner(System.in); System.out.println("Which direction would you like to head? North, South, East, or West."); direction = keyboard.nextLine(); player1.goOnAnAdventure(direction); Game game1 = new Game(); game1.playGame(); }
// For local game, legacy public void run(boolean withAI) { Game currentGame = new Game(withAI); currentGame.playGame(); }
public static void main(String[] args) { Game playGame = new GLHF(); playGame.playGame(2); }
public void testGameOver() { startingRoom.spawnMonster(new Monster("monster", 1000, 1, 1000, 1000)); game.playGame("fight"); assertTrue("When player dies to monster, ends the game", game.isGameOver()); }