1 Star 0 Fork 123

肖榜昌/zuul

forked from 吕焱飞/zuul 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Game.java 8.29 KB
一键复制 编辑 原始数据 按行查看 历史
肖榜昌 提交于 2021-06-20 22:23 . update Game.java.
import java.util.*;
/**
* 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 Food bag = null;
int energy = 150;
/**
* Create the game and initialise its internal map.
*/
public Game()
{
createRooms();
parser = new Parser();
}
/**
* Create all the rooms and link their exits together.
*/
private void createRooms()
{
Room a, b, c, d, e, f, boss, xiaoheiwu,chukou;
// create the rooms
b = new Room("你现在万毒窟,获得了御剑术秘笈,学习了御剑术可以快速飞行,灵敏度+10");
a = new Room("你遇见了三眼魔狼;它对你使用了魔眼使你进入的幻术世界 生命力-2;你用强大的念力破开了它的幻术并使用了血魔大法第一式:气血鬼爪杀掉了它");
d = new Room("这是一个秘境你在里面获得了许多灵药并且在此地修习了一段时间你成功突破到了筑基期洗的血魔大法第二式:血之爆裂术");
c = new Room("你发现的一把剑它锈迹斑斑你用血魔大法唤醒了它的器魂,它名为血刃魔剑。你的武力+100");
f= new Room("你用御剑术飞过了这里");
e= new Room("你用御剑术飞过了这里");
xiaoheiwu = new Room("你来到了一位修士的故居你获得了他的传承。");
chukou = new Room("你到到达了出口,你成功离开了万毒窟,现在你可以离开这里了",null);
boss = new Room("你遇到了三阶魔兽暗夜魔狼,你使用了气血鬼爪使它-100hp;它对你使用魔狼啸让你-20hp;最后你使用血刃魔剑加上血之爆裂术消灭了它");
// initialise room exits
b.setExit("east", a);
b.setExit("west", c);
a.setExit("east", d);
a.setExit("north", e);
d.setExit("west",e);
d.setExit("east",c );
e.setExit("south", c);
c.setExit("east",xiaoheiwu);
xiaoheiwu.setExit("east",boss);
boss.setExit("west",chukou);
currentRoom = b;// 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("你的灵力没有了,无法使用仙术");
}
/**
* Print out the opening message for the player.
*/
private void printWelcome()
{
System.out.println();
System.out.println("欢迎来到鬼谷八荒的世界,我是鬼谷子。你可以先选择自己的先天气运和储蓄戒,你现在在上古时期妖兽祸患的时候你首先要通过自己的能力离开这个大陆去到别的大陆修行。");
System.out.println("我将给予你一本秘笈名为血魔大法,它可以让你很快的提高修为。");
System.out.println("需要提示请输入“help”");
System.out.println();
System.out.println(currentRoom.getDescription());
currentRoom.printExits();
}
/**
* 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;
}
energy = energy - 10;
Word commandWord = command.getCommandWord();
switch(commandWord){
case HELP:
printHelp();
break;
case GO:
goRoom(command);
break;
case QUIT:
wantToQuit = quit(command);
break;
case LOOK:
Food food = currentRoom.getFood();
if(food != null){
System.out.println("房间里有" + food.getName());
}
else{
System.out.println("这个房间里没有武器和秘笈");
}
System.out.println("当前灵力值" + energy);
break;
case PICK:
Food food1 = currentRoom.getFood();
if(bag != null){
System.out.println("你的储蓄戒装不下了");
}
else{
System.out.println("你拿起了"+ food1.getName());
bag = food1;
}
System.out.println("当前灵力" + energy);
break;
case EAT:
if(bag != null){
System.out.println("使用" + bag.getName());
Food food2 = currentRoom.getFood();
energy += food2.getEnergy();
System.out.println("当前灵力值" + energy);
bag=null;
}
else{
System.out.println("没有可使用的东西");
}
break;
case CHECK:
if(bag != null){
System.out.println("储蓄戒有" + bag.getName());
}
else{
System.out.println("储蓄戒里没有东西");
}
break;
}
if((energy < 0)||(energy == 0)) {
wantToQuit = true;
}
return wantToQuit;
}
// implementations of user commands:
/**
* Print out some help information.
* Here we print some stupid, cryptic message and a list of the
* command words.
*/
private void printHelp()
{
System.out.println("你现在有很多仙术");
System.out.println();
Word[] words = Word.values();
for(int i=0;i<words.length;i++){
System.out.print(words[i].getCommandWord()+" ");
}
System.out.println("请你选择你需要用的仙术");
}
/**
* 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?");
System.out.println("要去哪里");
return;
}
String direction = command.getSecondWord();
// Try to leave current room.
Room nextRoom = currentRoom.goNext(direction);
if(nextRoom == null){
//System.out.print("There is no door!");
System.out.println("这貌似走不了呢");
}
else {
currentRoom = nextRoom;
System.out.println(currentRoom.getDescription());
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
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/xiao-bangchang/zuul.git
git@gitee.com:xiao-bangchang/zuul.git
xiao-bangchang
zuul
zuul
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385