Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Main
- public class Main {
- public static boolean validGender(char gender) {
- char[] genders = {'m', 'f', 'o'};
- for (int i = 0; i < genders.length; i++) {
- if (genders[i] == Character.toLowerCase(gender))
- return true;
- }
- return false;
- }
- public static boolean playerIsGah(String name) {
- if (name.toLowerCase().equals("gah"))
- return true;
- return false;
- }
- public static boolean validMovement(char[] validMovements, char movement) {
- for (char validMovement : validMovements) {
- if (validMovement == movement)
- return true;
- }
- return false;
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- Player player = new Player();
- Item trumpet = new Item("Instrument", "Trumpet");
- Item fiestita = new Item("Album", "La fiesta del rey dramita");
- Item cello = new Item("Instrument", "Cello");
- Item kidAcito = new Item("Album", "Kid A");
- List<Item> initialItems = Arrays.asList(trumpet, fiestita);
- List<Item> purrrsiaItems = Arrays.asList(cello, kidAcito);
- char[] startAdjacentRooms = new char[]{'n'};
- char[] purrrsiaAdjacentRooms = new char[]{'s'};
- char[] nyazuAdjacentRooms = new char[]{'s', 'w'};
- Room start = new Room("Start", new int[]{0, 0, 0, 0}, initialItems, startAdjacentRooms);
- Room purrrsia = new Room("Purrrsia", new int[]{1, 0, 0, 0}, purrrsiaItems, purrrsiaAdjacentRooms);
- Room nyazu = new Room("Nyazu", new int[]{2, 1, 0, 0}, purrrsiaItems, nyazuAdjacentRooms);
- Room[] gameRooms = new Room[]{start, purrrsia, nyazu};
- GameMap nicelyNiceMap = new GameMap(gameRooms);
- }
- }
- // GameMap
- public class GameMap {
- private Map<String, Room> rooms = new LinkedHashMap<>();
- public GameMap(Room[] rooms) {
- for (Room room : rooms) {
- this.rooms.put(room.getLocationToString(), room);
- }
- }
- public Map<String, Room> getRooms() {
- return rooms;
- }
- }
- // Room
- public class Room {
- private String name;
- private Map<Character, Integer> location = new LinkedHashMap<>();
- private List<Item> items = new ArrayList<>();
- private char[] adjacentRooms;
- public Room(String name, int[] coordinates, List<Item> items, char[] adjacentRooms) {
- this.name = name;
- this.location.put('n', coordinates[0]);
- this.location.put('e', coordinates[1]);
- this.location.put('s', coordinates[2]);
- this.location.put('w', coordinates[3]);
- this.items.addAll(items);
- this.adjacentRooms = adjacentRooms;
- }
- public String toString() {
- return this.name;
- }
- public String getLocationToString() {
- String locationStr = "";
- for (Map.Entry<Character, Integer> entry : location.entrySet()) {
- locationStr += entry.getValue() + " ";
- }
- return locationStr.trim();
- }
- public String getName() {
- return name;
- }
- public Map<Character, Integer> getLocation() {
- return location;
- }
- public List<Item> getItems() {
- return items;
- }
- public char[] getAdjacentRooms() {
- return adjacentRooms;
- }
- }
- // Item
- public class Item {
- private String type;
- private String name;
- public Item(String type, String name) {
- this.type = type;
- this.name = name;
- }
- public String toString() {
- return this.name;
- }
- public String getType() {
- return type;
- }
- public String getName() {
- return name;
- }
- }
- // Player
- public class Player {
- private String name;
- private char gender;
- private Map<String, List<String>> inventory = new HashMap<>();
- private Map<Character, Integer> position = new LinkedHashMap<>();
- public Player() {
- this("Gah", 'o');
- }
- public Player(String name, char gender) {
- this.name = name;
- this.gender = gender;
- this.inventory.put("albums", new ArrayList<String>());
- this.inventory.put("instruments", new ArrayList<String>());
- this.position.put('n', 0);
- this.position.put('e', 0);
- this.position.put('s', 0);
- this.position.put('w', 0);
- }
- public void updateNorth(char direction) {
- if (position.get('s') > 0) {
- position.put('s', position.get('s') - 1);
- }
- else {
- position.put('n', position.get('n') + 1);
- }
- }
- public void updateSouth(char direction) {
- if (position.get('n') > 0) {
- position.put('n', position.get('n') - 1);
- }
- else {
- position.put('s', position.get('s') + 1);
- }
- }
- public void updateEast(char direction) {
- if (position.get('w') > 0) {
- position.put('w', position.get('w') - 1);
- }
- else {
- position.put('e', position.get('e') + 1);
- }
- }
- public void updateWest(char direction) {
- if (position.get('e') > 0) {
- position.put('e', position.get('e') - 1);
- }
- else {
- position.put('w', position.get('w') + 1);
- }
- }
- public void move(char direction) {
- switch(direction) {
- case 'n':
- updateNorth(direction);
- break;
- case 'e':
- updateEast(direction);
- break;
- case 's':
- updateSouth(direction);
- break;
- case 'w':
- updateWest(direction);
- break;
- }
- }
- public String getPositionToString() {
- String positionStr = "";
- for (Map.Entry<Character, Integer> coordinate : this.position.entrySet()) {
- positionStr += coordinate.getValue() + " ";
- }
- return positionStr.trim();
- }
- public String getName() {
- return name;
- }
- public char getGender() {
- return gender;
- }
- public Map<String, List<String>> getInventory() {
- return inventory;
- }
- public Map<Character, Integer> getPosition() {
- return position;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement