From 8e4bd75375edc060f7e31497922ad4b8c497a4e8 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 13 Nov 2012 16:39:02 -0500 Subject: Cleaned up Item and moved item instances into GridSpace --- src/com/fourisland/frigidearth/GridSpace.java | 26 ++ src/com/fourisland/frigidearth/Item.java | 315 +++------------------ .../fourisland/frigidearth/MapViewGameState.java | 253 +++++++---------- 3 files changed, 180 insertions(+), 414 deletions(-) create mode 100644 src/com/fourisland/frigidearth/GridSpace.java diff --git a/src/com/fourisland/frigidearth/GridSpace.java b/src/com/fourisland/frigidearth/GridSpace.java new file mode 100644 index 0000000..16dac4c --- /dev/null +++ b/src/com/fourisland/frigidearth/GridSpace.java @@ -0,0 +1,26 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.frigidearth; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author hatkirby + */ +public class GridSpace +{ + public Tile tile; + public boolean lit; + public List items; + + public GridSpace() + { + tile = Tile.Unused; + lit = false; + items = new ArrayList(); + } +} diff --git a/src/com/fourisland/frigidearth/Item.java b/src/com/fourisland/frigidearth/Item.java index d58f3c3..604432e 100644 --- a/src/com/fourisland/frigidearth/Item.java +++ b/src/com/fourisland/frigidearth/Item.java @@ -17,27 +17,7 @@ import java.util.Random; */ public enum Item { - ScrollOfHealing { - public String getItemName() - { - return "Scroll of Healing"; - } - - public char getDisplayCharacter() - { - return '~'; - } - - public Color getDisplayColor() - { - return Color.YELLOW; - } - - public ItemType getItemType() - { - return ItemType.Scroll; - } - + ScrollOfHealing("Scroll of Healing", '~', Color.YELLOW, ItemType.Scroll) { public boolean useItem() { Main.currentGame.health += 20; @@ -50,267 +30,32 @@ public enum Item return true; } }, - WoodenHelmet { - public String getItemName() - { - return "Wooden Helmet"; - } - - public char getDisplayCharacter() - { - return '^'; - } - - public Color getDisplayColor() - { - return new Color(128, 42, 42); - } - - public ItemType getItemType() - { - return ItemType.Helmet; - } - + WoodenHelmet("Wooden Helmet", '^', new Color(128, 42, 42), ItemType.Helmet) { public int getDefense() { return 1; } }, - WoodenSword { - public String getItemName() - { - return "Wooden Sword"; - } - - public char getDisplayCharacter() - { - return '/'; - } - - public Color getDisplayColor() - { - return new Color(128, 42, 42); - } - - public ItemType getItemType() - { - return ItemType.Sword; - } - + WoodenSword("Wooden Sword", '/', new Color(128, 42, 42), ItemType.Sword) { public int getAttackPower() { return 1; } }, - WoodenShield { - public String getItemName() - { - return "Wooden Shield"; - } - - public char getDisplayCharacter() - { - return 'O'; - } - - public Color getDisplayColor() - { - return new Color(128, 42, 42); - } - - public ItemType getItemType() - { - return ItemType.Shield; - } - + WoodenShield("Wooden Shield", 'O', new Color(128, 42, 42), ItemType.Shield) { public int getDefense() { return 1; } }, - RingOfRegeneration { - public String getItemName() - { - return "Ring of Regeneration"; - } - - public char getDisplayCharacter() - { - return 'o'; - } - - public Color getDisplayColor() - { - return Color.YELLOW; - } - - public ItemType getItemType() - { - return ItemType.Ring; - } - }, - Crocs { - public String getItemName() - { - return "Crocs"; - } - - public char getDisplayCharacter() - { - return 'd'; - } - - public Color getDisplayColor() - { - return new Color(128, 42, 42); - } - - public ItemType getItemType() - { - return ItemType.Shoes; - } - }, - GlassHelmet { - public String getItemName() - { - return "Glass Helmet"; - } - - public char getDisplayCharacter() - { - return '^'; - } - - public Color getDisplayColor() - { - return Color.CYAN; - } - - public ItemType getItemType() - { - return ItemType.Helmet; - } - - public int getDefense() - { - return 0; - } - }, - GlassSword { - public String getItemName() - { - return "Glass Sword"; - } - - public char getDisplayCharacter() - { - return '/'; - } - - public Color getDisplayColor() - { - return Color.CYAN; - } - - public ItemType getItemType() - { - return ItemType.Sword; - } - - public int getAttackPower() - { - return 0; - } - }, - GlassShield { - public String getItemName() - { - return "Glass Shield"; - } - - public char getDisplayCharacter() - { - return 'O'; - } - - public Color getDisplayColor() - { - return Color.CYAN; - } - - public ItemType getItemType() - { - return ItemType.Shield; - } - - public int getDefense() - { - return 0; - } - }, - WeddingRing { - public String getItemName() - { - return "Wedding Ring"; - } - - public char getDisplayCharacter() - { - return 'o'; - } - - public Color getDisplayColor() - { - return Color.YELLOW; - } - - public ItemType getItemType() - { - return ItemType.Ring; - } - }, - GlassSlippers { - public String getItemName() - { - return "Glass Slippers"; - } - - public char getDisplayCharacter() - { - return 'd'; - } - - public Color getDisplayColor() - { - return Color.CYAN; - } - - public ItemType getItemType() - { - return ItemType.Shoes; - } - }, - Key { - public String getItemName() - { - return "Key"; - } - - public char getDisplayCharacter() - { - return 'k'; - } - - public Color getDisplayColor() - { - return Color.YELLOW; - } - - public ItemType getItemType() - { - return ItemType.Special; - } - + RingOfRegeneration("Ring of Regeneration", 'o', Color.YELLOW, ItemType.Ring) {}, + Crocs("Crocs", 'd', new Color(128, 42, 42), ItemType.Shoes), + GlassHelmet("Glass Helmet", '^', Color.CYAN, ItemType.Helmet), + GlassSword("Glass Sword", '/', Color.CYAN, ItemType.Sword), + GlassShield("Glass Shield", 'O', Color.CYAN, ItemType.Shield), + WeddingRing("Wedding Ring", 'o', Color.YELLOW, ItemType.Ring), + GlassSlippers("Glass Slippers", 'd', Color.CYAN, ItemType.Shoes), + Key("Key", 'k', Color.YELLOW, ItemType.Special) { public boolean useItem() { ((MapViewGameState) Main.getGameState()).printMessage("There's nothing to use the key on!"); @@ -319,10 +64,38 @@ public enum Item } }; - public abstract String getItemName(); - public abstract char getDisplayCharacter(); - public abstract Color getDisplayColor(); - public abstract ItemType getItemType(); + private String itemName; + private char displayChar; + private Color displayColor; + private ItemType itemType; + + Item(String m_itemName, char m_displayChar, Color m_displayColor, ItemType m_itemType) + { + itemName = m_itemName; + displayChar = m_displayChar; + displayColor = m_displayColor; + itemType = m_itemType; + } + + public String getItemName() + { + return itemName; + } + + public char getDisplayCharacter() + { + return displayChar; + } + + public Color getDisplayColor() + { + return displayColor; + } + + public ItemType getItemType() + { + return itemType; + } public boolean useItem() { diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 0e136d5..67c7b19 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -38,12 +38,10 @@ public class MapViewGameState implements GameState private final int[][] OCTET_MULTIPLIERS = new int[][] {new int[] {1,0,0,-1,-1,0,0,1}, new int[] {0,1,-1,0,0,-1,1,0}, new int[] {0,1,1,0,0,-1,-1,0}, new int[] {1,0,0,1,-1,0,0,-1}}; private int mapWidth = 60; private int mapHeight = 60; - private Tile[][] grid; - private boolean[][] gridLighting; + private GridSpace[][] grid; private String[] messages = new String[MESSAGE_HEIGHT]; private List rooms = new ArrayList(); private List mobs = new ArrayList(); - private List items = new ArrayList(); private int playerx = 4; private int playery = 4; private int viewportx = 0; @@ -62,18 +60,17 @@ public class MapViewGameState implements GameState mapWidth += (50 * (floor-1)); mapHeight += (50 * (floor-1)); - grid = new Tile[mapWidth][mapHeight]; - gridLighting = new boolean[mapWidth][mapHeight]; + grid = new GridSpace[mapWidth][mapHeight]; for (int x=0; x (y-length); ytemp--) { - grid[xtemp][ytemp] = Tile.Corridor; + grid[xtemp][ytemp].tile = Tile.Corridor; } break; @@ -527,7 +512,7 @@ public class MapViewGameState implements GameState return false; } - if (grid[xtemp][ytemp] != Tile.Unused) + if (grid[xtemp][ytemp].tile != Tile.Unused) { return false; } @@ -535,7 +520,7 @@ public class MapViewGameState implements GameState for (xtemp = x; xtemp < (x+length); xtemp++) { - grid[xtemp][ytemp] = Tile.Corridor; + grid[xtemp][ytemp].tile = Tile.Corridor; } break; @@ -555,7 +540,7 @@ public class MapViewGameState implements GameState return false; } - if (grid[xtemp][ytemp] != Tile.Unused) + if (grid[xtemp][ytemp].tile != Tile.Unused) { return false; } @@ -563,7 +548,7 @@ public class MapViewGameState implements GameState for (ytemp = y; ytemp < (y+length); ytemp++) { - grid[xtemp][ytemp] = Tile.Corridor; + grid[xtemp][ytemp].tile = Tile.Corridor; } break; @@ -583,7 +568,7 @@ public class MapViewGameState implements GameState return false; } - if (grid[xtemp][ytemp] != Tile.Unused) + if (grid[xtemp][ytemp].tile != Tile.Unused) { return false; } @@ -591,7 +576,7 @@ public class MapViewGameState implements GameState for (xtemp = x; xtemp > (x-length); xtemp--) { - grid[xtemp][ytemp] = Tile.Corridor; + grid[xtemp][ytemp].tile = Tile.Corridor; } break; @@ -606,7 +591,7 @@ public class MapViewGameState implements GameState { for (int y=0; y 0) { - if ((ii.x == playerx) && (ii.y == playery)) + Item item = grid[playerx][playery].items.get(0); + printMessage("You get a " + item.getItemName().toLowerCase()); + Main.currentGame.inventory.add(item); + grid[playerx][playery].items.remove(0); + + if (item == Item.Key) { - printMessage("You get a " + ii.item.getItemName().toLowerCase()); - Main.currentGame.inventory.add(ii.item); - items.remove(ii); + printMessage("All the windows in the room shatter!"); - if (ii.item == Item.Key) + for (int x=0; x mobTypes = new ArrayList(); - switch (floor) + switch (Math.max(Main.currentGame.level, floor)) { case 10: case 9: @@ -1454,11 +1426,6 @@ public class MapViewGameState implements GameState public void dropItemAtPlayer(Item item) { - ItemInstance ii = new ItemInstance(); - ii.item = item; - ii.x = playerx; - ii.y = playery; - - items.add(ii); + grid[playerx][playery].items.add(item); } } -- cgit 1.4.1