代码拉取完成,页面将自动刷新
同步操作将从 吕焱飞/zuul 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
//import java.util.Timer;
import java.awt.Robot;
/**
* This class is the main class of the "World of Zuul" application.
* "World of Zuul" is a very simple, text based adventure game. Users
* can walk around some scenery. That's all. It should really be extended
* to make it more interesting!
*
* To play this game, create an instance of this class and call the "play"
* method.
*
* This main class creates and initialises all the others: it creates all
* rooms, creates the parser and starts the game. It also evaluates and
* executes the commands that the parser returns.
*
* @author Michael Kölling and David J. Barnes
* @version 2016.02.29
*/
public class Game
{
private Parser parser;
private Room currentRoom;
private Player player;
private Food food;
private Room room;
boolean finished = false;
/**
* Create the game and initialise its internal map.
*/
public Game()
{
createRooms();
parser = new Parser();
player = new Player();
}
/**
* Create all the rooms and link their exits together.
*/
private void createRooms()
{
Room outside,airport, prison, vineyard,colosseum,ck,down;
down = new Room("街道");
// create the rooms
outside = new Room("热情组织");
outside.setFood(new Food("李",10));
outside.setFood(new Food("香蕉",10));
//outside.setMonster(new Monster("史莱姆",15));
//outside.setMonster(new Monster("史姆",15));
airport = new Room("机场");
airport.setFood(new Food("香蕉",10));
airport.setFood(new Food("虫箭",100));
airport.setMonster(new Monster("斯克里普",50));
airport.setMonster(new Monster("布加拉提",60));
airport.setMonster(new Monster("康一",60));
prison = new Room("监狱");
prison.setFood(new Food("西瓜",10));
prison.setFood(new Food("洛卡卡卡果实",100));
vineyard = new Room("葡萄园");
vineyard.setFood(new Food("橙子",10));
vineyard.setFood(new Food("牛奶",10));
vineyard.setMonster(new Monster("伊鲁索",50));
colosseum = new Room("斗兽场");
colosseum.setFood(new Food("菠萝",10));
colosseum.setFood(new Food("李",10));
colosseum.setMonster(new Monster("迪亚波罗",150));
ck = new Room("出口");
ck.setFood(new Food("恭喜通关!!!",0));
ck.setMonster(new Monster("请输入quit退出游戏",5));
//outside,airport, prison, vineyard,colosseum;
// initialise room exits
outside.setExit("north",airport);
down.setExit("up",outside);
outside.setExit("down",down);
//theater.setExit(null, null, null, outside);
airport.setExit("west", prison);
airport.setExit("south", outside);
//pub.setExits(null, outside, null, null);
prison.setExit("south", vineyard);
prison.setExit("east", airport);
//lab.setExits(outside, office, null, null);
vineyard.setExit("west", colosseum);
vineyard.setExit("north", prison);
vineyard.setExit("east", outside);
colosseum.setExit("west",ck);
currentRoom = down; // start game outside
}
/**
* Main play routine. Loops until end of play.
*/
public void play()
{
printWelcome();
// Enter the main command loop. Here we repeatedly read commands and
// execute them until the game is over.
boolean finished = false;
while (! finished) {
Command command = parser.getCommand();
finished = processCommand(command);//空指针异常
}
System.out.println("Thank you for playing. Good bye.");
}
/**
* Print out the opening message for the player.
*/
private void printWelcome() //throws InterruptedException
{
try{
System.out.println();
Thread.sleep(500);
System.out.println("欢迎来到JOJO的奇妙冒险 黄金之风");
Thread.sleep(500);
//Thread.sleep(5000);
//time.sleep(5000);
System.out.println("住在意大利那不勒斯的青年乔鲁诺·乔巴拿,是继承了乔斯达家宿敌·DIO之血脉的儿子。");
Thread.sleep(500);
System.out.println("幼年时遭受迫害而自暴自弃的他,由于拯救了一名黑帮男子,");
Thread.sleep(500);
System.out.println("而学到了“相信他人”。不忘恩义、带着敬意对待自己的黑帮,");
Thread.sleep(500);
System.out.println("让他的心变得率直。就这样,乔鲁诺开始对“黑帮明星”怀有憧憬。");
Thread.sleep(500);
System.out.println("15岁的乔鲁诺,与统领意大利黑社会的黑帮组织“热情”一同引发事端,并成为被盯上的目标……");
Thread.sleep(500);
System.out.println("你将扮演JOJO,你的目标只有一个!");
Thread.sleep(500);
System.out.println("打败意大利黑帮BOOS");
Thread.sleep(500);
currentRoom.getDescription();
Thread.sleep(500);
player.check();//显示体力
Thread.sleep(500);
currentRoom.printExits();//出口方向
}catch(Exception e){}
}
/**
* Given a command, process (that is: execute) the command.
* @param command The command to be processed.
* @return true If the command ends the game, false otherwise.
*/
private boolean processCommand(Command command)
{
boolean wantToQuit = false;
if(command.isUnknown()) {
System.out.println("我不知道你的意思");
return false;
}
String commandWord = command.getCommandWord();
CommandWord cmd = CommandWord.valueOf(commandWord.toUpperCase());
switch(cmd){
case HELP:
printHelp();
break;
case GO:
player.walk();
if(!player.isAlive()){
System.out.println("您已经没有体力了,游戏结束!");
return true;
}
// else if(room.getDescription2()=="ck"){
// System.out.println("恭喜通关");
// wantToQuit = quit(command);
// }
goRoom(command);
break;
case QUIT:
wantToQuit = quit(command);
break;
case EAT:
player.eatFood(command);
//eat(command);
break;
case BATTLE:
balttle(command);
break;
case PICK:
//player.addToBag(food);
//捡起后没有去掉food////////////////
pick(command);
break;
case CHECK:
player.checkAndPrint();
break;
default:
}
// if (commandWord.equals("help")) {
// printHelp();
// }
// else if (commandWord.equals("go")) {
// player.walk();
// if(!player.isAlive()){
// System.out.println("您已经没有体力了,游戏结束!");
// return true;
// }
// goRoom(command);
// }
// else if (commandWord.equals("quit")) {
// wantToQuit = quit(command);
// }
// else if (commandWord.equals("eat")){
// eat(command);
// }
return wantToQuit;
}
// private void eat(Command command) {
// if(!command.hasSecondWord()) {
// // if there is no second word, we don't know where to go...
// System.out.println("你想吃什么?");
// return;
// }
// String name = command.getSecondWord();
// if (currentRoom.getFood(name) == null){
// System.out.println("这个房间没有吃的! ");
// }else{
// Food food = currentRoom.getFood(name);
// System.out.println("吃掉了:" + food.toString());
// player.eat(food);
// player.check();
// currentRoom.removeFood(name);
// }
// }
private void balttle(Command command) {
if(!command.hasSecondWord()) {
// if there is no second word, we don't know where to go...
System.out.println("你想打哪个敌人?");
return;
}
String name = command.getSecondWord();
if (currentRoom.getMonster(name) == null){
System.out.println("这个地方没有敌人可以打! ");
}else{
Monster monster = currentRoom.getMonster(name);
// System.out.println("打败了:" + monster.toString());
player.battle(monster);
player.check();
currentRoom.removeMonster(name);
}
}
// private void pick(Command command) {
// //Food f =new Food();
// //String name = command.getSecondWord();
// //Food food = currentRoom.getFood(name);
// // if(food!=null){
// if(!command.hasSecondWord()) {
// // if there is no second word, we don't know where to go...
// System.out.println("你想把哪个放入背包?");
// return;
// }
// //String name = command.getSecondWord();
// if (currentRoom.getMonster(name) == null){
// System.out.println("这个房间没有物品可以放入背包! ");
// }else{
// player.addToBag(food);
// currentRoom.removeFood(name);
// }
// }
// implementations of user commands:
private void pick(Command command) {
if(!command.hasSecondWord()) {
// if there is no second word, we don't know where to go...
System.out.println("你想将什么放入背包?");
return;
}
String name = command.getSecondWord();
if (currentRoom.getFood(name) == null){
System.out.println("这个房间没有这东西可以放进背包的! ");
}else{
Food food = currentRoom.getFood(name);
System.out.println("成功将"+food.toString()+"放入背包");
if(food.getName()=="洛卡卡卡果实"){
System.out.println("你成功获得洛卡卡卡果实,成就+1");
}
player.pick(food);
player.checkAndPrint();
currentRoom.removeFood(name);
}
}
/**
* Print out some help information.
* Here we print some stupid, cryptic message and a list of the
* command words.
*/
private void printHelp()
{
try{
CommandWords.printCommands();
Thread.sleep(1000);
System.out.println();
Thread.sleep(1000);
System.out.println("You are lost. You are alone. You wander");
Thread.sleep(1000);
System.out.println();
Thread.sleep(1000);
System.out.println("Your command words are:");
Thread.sleep(1000);
System.out.println(" go --前往下一个房间(要在后面追加方向)");
Thread.sleep(1000);
System.out.println(" help --获取游戏帮助");
Thread.sleep(1000);
System.out.println(" battle -- 与房间里的怪物战斗");
Thread.sleep(1000);
System.out.println(" !注意: 如果没有打败怪物,将扣血");
Thread.sleep(1000);
System.out.println(" pick -- 拾起东西");
Thread.sleep(1000);
System.out.println(" check -- 查看背包中的物品");
Thread.sleep(1000);
System.out.println(" eat -- 吃背包中的补给品(在后面追加物品)");
Thread.sleep(1000);
System.out.println(" quit -- 退出游戏");
Thread.sleep(1000);
}catch(Exception e){}
}
/**
* Try to go in one direction. If there is an exit, enter
* the new room, otherwise print an error message.
*/
private void goRoom(Command command)
{
if(!command.hasSecondWord()) {
// if there is no second word, we don't know where to go...
System.out.println("Go where?");
return;
}
String direction = command.getSecondWord();
Room nextRoom = currentRoom.goNext(direction);
// Try to leave current room.
// Room nextRoom = null;
// if(direction.equals("north")) {
// nextRoom = currentRoom.northExit;
// }
// if(direction.equals("east")) {
// nextRoom = currentRoom.eastExit;
// }
// if(direction.equals("south")) {
// nexthhuuhtRoom = currentRoom.southExit;
// }
// if(direction.equals("west")) {
// nextRoom = currentRoom.westExit;
// }
//这里显示怪物
if (nextRoom == null) {
System.out.println("此路不通");
}
else {
currentRoom = nextRoom;
currentRoom.getDescription();
player.check();
if(player.getSpecialItem()){
System.out.println("你成功获得洛卡卡卡果实,声望+1");
//}else if(room.hdDescription() =="出口"){
//boolean wantToQuit = true;
}
currentRoom.printExits();
}
}
/**
* "Quit" was entered. Check the rest of the command to see
* whether we really quit the game.
* @return true, if this command quits the game, false otherwise.
*/
private boolean quit(Command command)
{
if(command.hasSecondWord()) {
System.out.println("Quit what?");
return false;
}
else {
return true; // signal that we want to quit
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。