| AJIKA Super Crazy Member
 
  
 
       ჯგუფი: Members
 წერილები: 5875
 წევრი No.: 80350
 რეგისტრ.: 26-December 08
 
 
   | #58767290 · 11 Jan 2022, 14:30  ·  · პროფილი · პირადი მიმოწერა · ჩატი 
  გამარჯობა!ვცდილობ ჯავაში ტექსტური თამაშის დაწერას OOP პრინციპების გამოყენებით.
 შევქმენი შემდეგი კლასები : Item, Hero, Room, Paths, Adventure, Main, Entity.
 
 Paths არის enum კლასი რომელიც მოიცავს ინფორმაციას მიმართულებების შესახებ : EAST, WEST, SOUTH, NORTH.
 
 
 | CODE |  | package gameModel; public enum Paths{
 EAST ("E"),
 WEST ("W"),
 NORTH ("N"),
 SOUTH ("S")
 ;
 /* Important Note: Must have semicolon at
 * the end when there is a enum field or method
 */
 private final String shortCode;
 
 Paths(String code) {
 this.shortCode = code;
 }
 
 public String getDirectionCode() {
 return this.shortCode;
 }
 }
 | 
 
 
 Entity აბსტრაქტული კლასი უნდა ყოფილიყო რომელსაც გამოიყენებდა room, item და hero, მაგრამ დიდად საჭირო არაა მგონი
 
 | CODE |  | package gameModel; 
 public class Entity {
 private String entityName;
 private String entityDescription;
 
 public Entity(String name, String desc) {
 this.entityName=name;
 this.entityDescription=desc;
 }
 
 public String getEntityName() {
 return entityName;
 }
 
 public void setEntityName(String entityName) {
 this.entityName = entityName;
 }
 
 public String getEntityDescription() {
 return entityDescription;
 }
 
 public void setEntityDescription(String entityDescription) {
 this.entityDescription = entityDescription;
 }
 }
 
 | 
 
 item
 
 | CODE |  | package gameModel; 
 public class Item {
 private String itemName;
 private String itemDesc;
 private Room itemLocation;
 
 public Item() {}
 public Item(String name) {
 this.itemName = name;
 
 }
 public void setitemName(String itemName) {
 this.itemName = itemName;
 }
 public String getitemName() {
 return itemName;
 }
 public void setItemDesc(String itemDesc) {
 this.itemDesc = itemDesc;
 }
 public String getitemDesc() {
 return itemDesc;
 }
 public void setItemLocation(Room itemLocation) {
 this.itemLocation = itemLocation;
 }
 public Room getItemLocation() {
 return itemLocation;
 }
 public String look() {
 return getitemDesc();
 }
 @Override
 public String toString() {
 return "Thing name=" + itemName + ", desc=" + itemDesc +", item location" + itemLocation;
 }
 }
 
 
 | 
 
 Hero
 
 | CODE |  | package gameModel; import java.util.*;
 public class Hero {
 private static Room currentLocation;
 private static int healthLevel = 5;
 private ArrayList<Item> inventory;
 
 public Hero() {
 
 }
 public void setCurrentLocation(Room room) {
 this.currentLocation = room;
 
 }
 public Room getcurrentLocation() {
 return currentLocation;
 
 }
 public void lookRoom(HashMap<String,Room> rooms) {
 rooms.get(currentLocation).getRoomDesc();
 }
 public void checkHealth(int healthLevel) {
 System.out.println("Health level is " + healthLevel);
 }
 public ArrayList<Item> getInventory() {
 return inventory;
 }
 public void setInventory(ArrayList<Item> inventory) {
 this.inventory = inventory;
 }
 }
 
 | 
 
 Room
 
 
 | CODE |  | package gameModel;
 import java.util.*;
 public class Room {
 
 private String roomName;
 private String roomDesc;
 private HashMap<Item, Room> roomItems = new HashMap<Item, Room>();
 private HashMap<Paths, Room> exits;
 
 public Room(String name) {
 this.roomName = name;
 this.exits = new HashMap<Paths,Room>();
 this.roomItems = new HashMap<Item,Room>();
 }
 
 /**
 * @return the roomName
 */
 public String getRoomName() {
 return roomName;
 }
 
 /**
 * @param roomName the roomName to set
 */
 public void setRoomName(String roomName) {
 this.roomName = roomName;
 }
 
 /**
 * @return the roomDesc
 */
 public String getRoomDesc() {
 return roomDesc;
 }
 
 /**
 * @param roomDesc the roomDesc to set
 */
 public void setRoomDesc(String roomDesc) {
 this.roomDesc = roomDesc;
 }
 
 /**
 * @return the inventoryItems
 */
 public HashMap<Item, Room> getRoomItems() {
 return roomItems;
 }
 
 /**
 * @param inventoryItems the inventoryItems to set
 */
 public void setInventoryItems(Item it, Room room) {
 roomItems.put(it, room);
 }
 
 /**
 * @return the exits
 */
 public HashMap<Paths, Room> getExits() {
 return exits;
 }
 
 /**
 * @param exits the exits to set
 */
 public void setExit(Paths direction, Room neighbor) {
 exits.put(direction, neighbor);
 }
 
 
 
 
 }
 
 | 
 
 Adventure
 
 | CODE |  | package gameModel; import java.util.*;
 
 public class Adventure {
 static Room forest, boarden, meadow, river , mistletoetrees ,villageroad
 ,villageentrance, village;
 
 static Item yeast,harp,mistletoe,barrel,flask;
 
 private Room currentLocation = forest;
 
 static Hero idefix;
 public static void setupWorld() {
 
 idefix = new Hero();
 idefix.setCurrentLocation(forest);
 
 //Room 1
 forest = new Room("Forests");
 forest.setRoomDesc("Idefix, after walking around in the forest, lost sight of Obelix"
 +"In the dark forest he could see a pathway going to the east");
 forest.setExit(Paths.EAST, boarden);
 
 // Room2
 boarden = new Room("Boar Den");
 boarden.setRoomDesc("Ideafix meets a hangry boar in the forest.\n"
 + " Accidentally, Idefix saw some yeast nearby that the hungry boar could not see\n"
 +" This yeast could easely end the hunger/anger of the boar "
 +" Apart from barking at the boar or getting the yeast for it,"
 +" Idefix can also try to go towards the southern path to avoid trouble");
 
 boarden.setExit(Paths.WEST, forest);
 boarden.setExit(Paths.SOUTH, meadow);
 yeast = new Item("Yeast");
 
 yeast.setItemDesc("It is one of boar's favorite foods");
 yeast.setItemLocation(boarden);
 
 // Room 3
 meadow = new Room("Meadow");
 meadow.setRoomDesc("Good thing Idefix got away from that boar!"
 +"Far away he can hear Chants. He decides to approach the sound\n "
 +"and sees Assurancetourix; who has lost his harp.\n"
 +"Assurancetourix asks Idefix if he can look around for the harp\n"
 +"Idefix really wants to help but also sees a path to the east that could lead to Obelix\n"
 +"What should idefix do?");
 
 meadow.setExit(Paths.NORTH, boarden);
 meadow.setExit(Paths.EAST, river);
 harp = new Item("Harp");
 
 harp.setItemDesc("This is Assourancetourix's favorite harp!");
 harp.setItemLocation(meadow);
 
 // Room 4
 river = new Room("River");
 river.setRoomDesc("Idefix comes across a river up north that seems a little bit too fast to cross by himself\n"
 +"He could try to cross it, but he could drown\n"
 +"Or, Idefix can use the bone that he got to cross the river\n"
 +"Of course, he can go back west where Assurancetourix was");
 river.setExit(Paths.WEST, meadow);
 river.setExit(Paths.NORTH, mistletoetrees);
 
 // Room 5
 mistletoetrees = new Room("Mistletoe Trees");
 mistletoetrees.setRoomDesc("Once on the other side, Idefix recognises the tree Panoramix\n"
 + " comes to often to get mistletoe for his famous potion. Idefix sits by the tree to take\n"
 +" a nap until he gets woken up by the marches of the Roman Army. In panic he climbs up the tree.\n"
 +" Idefix knows that Romans are interested in mistletoe, so if he would give it to them, they would\n"
 +" probably leave.Also, to the west he sees a path that might lead out of the forest.");
 
 mistletoetrees.setExit(Paths.WEST, villageroad);
 mistletoetrees.setExit(Paths.SOUTH, river);
 
 mistletoe = new Item("Mistletoe");
 mistletoe.setItemDesc("The powerful plant used for creating the famous magic potion");
 mistletoe.setItemLocation(mistletoetrees);
 
 barrel = new Item("Wine Barrel");
 barrel.setItemDesc("A hige wooden barrel filled with high quality Roman wine");
 barrel.setItemLocation(mistletoetrees);
 
 
 // Room 6
 villageroad = new Room("Village Road");
 villageroad.setRoomDesc("Finally, Idefix is almost out of the forest! On his way back, he crossed Panoramix\n"
 +" who saw him with a huge wine barrel that romans gave to him in return for mistletoe.\n"
 +" This barrel could be usefor for Panoramix to get up on the mistletoe tree to get the ingredients\n"
 +" for his magic potion. In return for the wine barrel, Panoramix promised to give Idefix a flask of magic potion,\n"
 +" as well as telling him that the way to the village lies across the western path.");
 villageroad.setExit(Paths.EAST, mistletoetrees);
 villageroad.setExit(Paths.WEST, villageentrance);
 
 flask = new Item("Flask");
 flask.setItemDesc("A flask full of Panoramix's magic potion. To be used with care!");
 flask.setItemLocation(villageroad);
 
 // Room 7
 villageentrance = new Room("Village Entrance");
 villageentrance.setRoomDesc("As Idefix continues walk back to the village,\n"
 +" his passage is blocked by a huge menhir. What should Idefix do? He still has the flask with the magic potion.\n"
 +" Also, now he can see the village to the south!");
 villageentrance.setExit(Paths.SOUTH, village);
 villageentrance.setExit(Paths.EAST, villageroad);
 
 // Room 8
 village = new Room("Village");
 village.setRoomDesc("As he drinks the liquied, a surge of energy flows through his body.\n"
 +" It is a magic potion! He runs through the stone which shatters in pieces.\n"
 +" Idefix sees Obelix by the gates of the village. He makes a huge jupm straight into Obelix's arms.\n"
 +" To celebrate the reunion of friends, they organize a feast with beer and boar with the whole village.\n"
 +" At the end, because Idefix managed to find his way back after a long absence,\n"
 +" Fabala gives him a big kiss.");
 village.setExit(Paths.WEST, villageentrance);
 
 // Creating a map
 ArrayList<Room> map = new ArrayList<Room>();
 map.add(forest);
 map.add(boarden);
 map.add(meadow);
 map.add(mistletoetrees);
 map.add(river);
 map.add(villageroad);
 map.add(villageentrance);
 map.add(village);
 
 // Adding the items to the map
 ArrayList<Item> itemsMap = new ArrayList<Item>();
 itemsMap.add(yeast);
 itemsMap.add(harp);
 itemsMap.add(mistletoe);
 itemsMap.add(barrel);
 itemsMap.add(flask);
 
 // Creating player inventory
 ArrayList<Item> inventory = new ArrayList<Item>();
 }
 }
 
 | 
 
 
 და ბოლოს სავარაუდოდ Main-ში დავწერ ლუპს რომელიც გააკონტროლებს თამაშის მიმდინაორებას.
 
 | CODE |  | package gameModel; import java.util.*;
 import gameModel.Adventure;
 
 
 
 public class Main {
 public void start() {
 boolean gameFinished = false;
 do while(!gameFinished) {
 
 };
 
 
 
 
 }
 public static void main(String[] args) {
 
 Scanner input = new Scanner(System.in);
 Adventure.setupWorld();
 
 
 }
 }
 
 | 
 თხოვნა მცოდნეებთან, იქნებ გადახედოთ და მითხრათ რისი შესწორება შეიძლება სანამ მთავარ ლუფზე გადავალ. ვარ დამწყები და ძლივს-ძლივობით მოვაბით ამ ყველაფერს თავი    
 --------------------
 
 Love United |