Edi, pershendetje!
pak a shume i kam dhene nje skeme ecurise se lojes:
dhomat deklarohen ne class Game,
Kodi:
private Parser parser;
private Room currentRoom;
/**
* Creates rooms and calls parser.
*/
public Game() {
createRooms();
parser = new Parser();
}
/**
* Creates single rooms and equips them with the exit help.
*/
private void createRooms() {
Room bridge;
Room courtyard;
Room stable;
Room mainhall;
Room kitchen;
Room stair1;
Room lounge;
Room shortcut;
Room stair2;
Room tower;
Room cell;
// single rooms being created
bridge = new Room("bridge","the middle of the bridge. Cross it over, and go towards the castle!");
courtyard = new Room("courtyard","the yard of the castle");
stable = new Room("stable","stable. The horseman might have something interesting for you!");
mainhall = new Room("mainhall", "the entrance of the castle, which takes you inside!");
kitchen = new Room("kitchen","the kitchen, where the servants used to work (better check in there!)");
stair1 = new Room("stair1","the stairway that takes you to the 2nd floor!");
lounge = new Room("lounge","the place where the treasuries of the Dark Warlord are kept(look in!)");
shortcut = new Room("shortcut","for the hidden and shorter way to win the game!");
stair2 = new Room("stair2"," the stairway that takes you to the highest floor of the castle!");
tower = new Room("tower","highest level of the castle!");
cell = new Room("cell","the place where the princess is locked!");
dhe lidhjet midis dhomave:
Kodi:
// sets the exits (with connecting rooms)
bridge.setExit(courtyard);
courtyard.setExit(bridge);
courtyard.setExit(stable);
courtyard.setExit(mainhall);
stable.setExit(courtyard);
mainhall.setExit(courtyard);
mainhall.setExit(kitchen);
mainhall.setExit(stair1);
kitchen.setExit(mainhall);
stair1.setExit(mainhall);
stair1.setExit(lounge);
stair1.setExit(stair2);
lounge.setExit(shortcut);
shortcut.setExit(lounge);
shortcut.setExit(cell);
stair2.setExit(stair1);
stair2.setExit(tower);
tower.setExit(stair2);
tower.setExit(cell);
cell.setExit(tower);
currentRoom = bridge; // loja fillon ne dhomen "bridge"
dhe kjo eshte pjesa tjeter e class Game:
Kodi:
/**
* The main method of the game. Cycles until the end of the game (as long
* as the processCommand method returns true value)
*/
public void play() {
printWelcome();
// the first cycle of the program - repeatedly the commands are read
//and then they are erased in the end of the game.
boolean finished = false;
while (!finished) {
Command command = parser.getCommand();
finished = processCommand(command);
}
System.out.println("Thank you for playing. See you soon. Good bye.");
System.out.println();
}
/**
* Writes beggining phrases for the player.
*/
private void printWelcome() {
System.out.println();
System.out.println("Welcome to Koon!");
System.out.println("Koon is a new, incredibly boring adventure game.");
System.out.println("Type 'help' if you need help.");
System.out.println();
System.out.println(currentRoom.longDescription());
}
/**
* The method works with the command like a parameter, and gives the
* answering method. If it's the end of the game, the method returns
* the true value, otherwise returns false.
*
*@param command the command, which has to be valuated
*@return returns true value, if it's the end of the game,
* else false.
*/
private boolean processCommand(Command command) {
if (command.isUnknown()) {
System.out.println("I don't know what you mean...");
return false;
}
String commandWord = command.getCommandWord();
if (commandWord.equals("help")) {
printHelp();
System.out.println();
}
else if (commandWord.equals("go")) {
goRoom(command);
}
else if (commandWord.equals("quit")) {
if (command.hasSecondWord()) {
System.out.println("Quit what?");
}
else {
return true;
}
}
return false;
}
// follows the implementation of single commands
/**
* Writes the first info after giving the help command. There is written
* the list of used commands.
*/
private void printHelp() {
System.out.println("You are on a wandering, in the wild Fanghorn Forest.");
System.out.println("You are looking for a castle, The Dark Warlord's Castle.");
System.out.println("Your mission is to get to the highest room, in the highest");
System.out.println("tower, so u can save the Princess of Noland");
System.out.println();
System.out.println("You find your way out of the Forest, look for a bridge");
System.out.println("Your command words are:");
parser.showCommands();
}
/**
* The "go" command. Tries to move towards the selected direction.
* If that direction is right, enters in a new area(room). If the command
* is not assigned, writes error message.
*
*@param command command - like the second parameter specifies a
* direction, which you can go.
*/
private void goRoom(Command command) {
if (!command.hasSecondWord()){
// if the second word is missing, then...
System.out.println("Go where?");
return;
}
String direction = command.getSecondWord();
// try to go into the next room
Room nextRoom = currentRoom.nextRoom(direction);
if (nextRoom == null) {
System.out.println("I can't go this way!");
}
else {
currentRoom = nextRoom;
System.out.println(currentRoom.longDescription());
}
}
}
une do ti postoj te gjithe class-et qe permban loja. doja pak ndihme per vendosjen, marrjen dhe perdorimin e sendeve nga dhomat e ndryshme.
-psh. lojtari, gjendet ne fillim mbi ure, pastaj me te njejten menyre komandash > go "dhoma", leviz drejt keshtjelles, ne oborrin e saj(courtyard), i cili ka lidhje me 2 dhoma te tjera, stallen(stable) dhe hyrjen ne keshtjelle(mainhall). ne stalle mendova te jete nje kalores(horseman) dhe objektet(items) kali dhe shpata.
-futet ne keshtjelle. nga [mainhall] und te shkohet ne [kitchen] ose [ne stair1]. ne [kitchen] jane objektet "meat" dhe "pan".
-me ane te shkalleve hipen ne katin e dyte, i cili ka lidhje me [lounge] dhe [stair2]. ne lounge, nuk lejohet te hysh nqs nuk gjen menyren per te shmangur nje "hellhound",menyre e cila eshte ti japesh mishin e gjetur ne [kitchen]. vete [lounge] ka lidhje me [shortcut], i cili te shpie te qelia ku eshte kycyr princesha.
nqs nuk ben kete, por vazhdon me ane te [stair2] per ne nivelin me te larte te keshtjelles [tower], takon "Dark Warlord", te cilit duhet ti tregosh "shpaten" e gjetur ne [stable] per ta mposhtur. pas mposhtjes ai le nje objekt po ne kete dhome, [key]. me ane te ketij objekti behet e mundur hyrja per ne dhomen qe vijon [cell].
kjo eshte me pak fjale ecuria e lojes Edi. do te doja te te pergjigjesha per cfaredo lloj paqartesie ose pyetje qe mund te kesh.
edhe dicka tjeter; e kam provuar qe me krijimin e ketyre objekteve, pasi i merr nga dhoma X, dhe vazhdon me tej per ne dhomen Y, por te mbushet mendja te kthehesh perseri te dhoma X, me dhenien e komandes "go dhomaX", te shfaqet perseri edhe ai objekti te cilin e ke marre nje here brenda lojes. do ishte mire qe objekti te merrej vetem nje here.
....>>>>
Krijoni Kontakt