about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/fourisland/frigidearth/Game.java128
-rw-r--r--src/com/fourisland/frigidearth/InventoryOverlay.java4
-rw-r--r--src/com/fourisland/frigidearth/Item.java102
-rw-r--r--src/com/fourisland/frigidearth/ItemType.java28
-rw-r--r--src/com/fourisland/frigidearth/MapViewGameState.java6
-rw-r--r--src/com/fourisland/frigidearth/MessageOverlay.java67
6 files changed, 326 insertions, 9 deletions
diff --git a/src/com/fourisland/frigidearth/Game.java b/src/com/fourisland/frigidearth/Game.java index 3487729..fdd4110 100644 --- a/src/com/fourisland/frigidearth/Game.java +++ b/src/com/fourisland/frigidearth/Game.java
@@ -19,4 +19,132 @@ public class Game
19 public int level = 1; 19 public int level = 1;
20 public int experience = 0; 20 public int experience = 0;
21 public List<Item> inventory = new ArrayList<Item>(); 21 public List<Item> inventory = new ArrayList<Item>();
22 private Item helmet = null;
23 private Item sword = null;
24 private Item shield = null;
25 private Item ring = null;
26 private Item shoes = null;
27
28 public boolean equipItem(final Item i)
29 {
30 if ((i.getItemType() != ItemType.Helmet) && (i.getItemType() != ItemType.Sword) && (i.getItemType() != ItemType.Shield) && (i.getItemType() != ItemType.Ring) && (i.getItemType() != ItemType.Shoes))
31 {
32 throw new IllegalArgumentException("You can only equip helmets, swords, shields, rings and shoes.");
33 }
34
35 boolean alreadyEquipped = false;
36 boolean alreadyEquippedSame = false;
37 Item equippedItem = null;
38
39 switch (i.getItemType())
40 {
41 case Helmet:
42 if (helmet != null)
43 {
44 alreadyEquipped = true;
45 equippedItem = helmet;
46
47 if (helmet == i)
48 {
49 alreadyEquippedSame = true;
50 }
51 }
52
53 break;
54
55 case Sword:
56 if (sword != null)
57 {
58 alreadyEquipped = true;
59 equippedItem = sword;
60
61 if (sword == i)
62 {
63 alreadyEquippedSame = true;
64 }
65 }
66
67 break;
68
69 case Shield:
70 if (shield != null)
71 {
72 alreadyEquipped = true;
73 equippedItem = shield;
74
75 if (shield == i)
76 {
77 alreadyEquippedSame = true;
78 }
79 }
80
81 break;
82
83 case Ring:
84 if (ring != null)
85 {
86 alreadyEquipped = true;
87 equippedItem = ring;
88
89 if (ring == i)
90 {
91 alreadyEquippedSame = true;
92 }
93 }
94
95 break;
96
97 case Shoes:
98 if (shoes != null)
99 {
100 alreadyEquipped = true;
101 equippedItem = shoes;
102
103 if (shoes == i)
104 {
105 alreadyEquippedSame = true;
106 }
107 }
108
109 break;
110 }
111
112 if (alreadyEquippedSame)
113 {
114 ((MapViewGameState) Main.getGameState()).printMessage("You have already equipped " + i.getItemName().toLowerCase());
115
116 return false;
117 } else if (alreadyEquipped)
118 {
119 inventory.add(equippedItem);
120 ((MapViewGameState) Main.getGameState()).printMessage("You unequip your " + equippedItem.getItemName().toLowerCase() + " and equip " + i.getItemName().toLowerCase());
121 } else {
122 ((MapViewGameState) Main.getGameState()).printMessage("You equip " + i.getItemName().toLowerCase());
123 }
124
125 switch (i.getItemType())
126 {
127 case Helmet:
128 helmet = i;
129 break;
130
131 case Sword:
132 sword = i;
133 break;
134
135 case Shield:
136 shield = i;
137 break;
138
139 case Ring:
140 ring = i;
141 break;
142
143 case Shoes:
144 shoes = i;
145 break;
146 }
147
148 return true;
149 }
22} 150}
diff --git a/src/com/fourisland/frigidearth/InventoryOverlay.java b/src/com/fourisland/frigidearth/InventoryOverlay.java index 0d7a5ba..70c42c4 100644 --- a/src/com/fourisland/frigidearth/InventoryOverlay.java +++ b/src/com/fourisland/frigidearth/InventoryOverlay.java
@@ -108,10 +108,10 @@ public class InventoryOverlay implements Renderable, Inputable
108 ((MapViewGameState) Main.getGameState()).tick(); 108 ((MapViewGameState) Main.getGameState()).tick();
109 Main.removeRenderable(this); 109 Main.removeRenderable(this);
110 Main.removeInputable(this); 110 Main.removeInputable(this);
111
112 return;
113 } 111 }
114 112
113 return;
114
115 case KeyEvent.VK_D: 115 case KeyEvent.VK_D:
116 ((MapViewGameState) Main.getGameState()).dropItemAtPlayer(Main.currentGame.inventory.get(id)); 116 ((MapViewGameState) Main.getGameState()).dropItemAtPlayer(Main.currentGame.inventory.get(id));
117 Main.currentGame.inventory.remove(id); 117 Main.currentGame.inventory.remove(id);
diff --git a/src/com/fourisland/frigidearth/Item.java b/src/com/fourisland/frigidearth/Item.java index 8881b6c..4527cbe 100644 --- a/src/com/fourisland/frigidearth/Item.java +++ b/src/com/fourisland/frigidearth/Item.java
@@ -70,12 +70,89 @@ public enum Item
70 { 70 {
71 return ItemType.Helmet; 71 return ItemType.Helmet;
72 } 72 }
73 },
74 WoodenSword {
75 public String getItemName()
76 {
77 return "Wooden Sword";
78 }
73 79
74 public boolean useItem() 80 public char getDisplayCharacter()
75 { 81 {
76 // Nope not yet 82 return '/';
77 83 }
78 return true; 84
85 public Color getDisplayColor()
86 {
87 return new Color(128, 42, 42);
88 }
89
90 public ItemType getItemType()
91 {
92 return ItemType.Sword;
93 }
94 },
95 WoodenShield {
96 public String getItemName()
97 {
98 return "Wooden Shield";
99 }
100
101 public char getDisplayCharacter()
102 {
103 return 'O';
104 }
105
106 public Color getDisplayColor()
107 {
108 return new Color(128, 42, 42);
109 }
110
111 public ItemType getItemType()
112 {
113 return ItemType.Shield;
114 }
115 },
116 RingOfRegeneration {
117 public String getItemName()
118 {
119 return "Ring of Regeneration";
120 }
121
122 public char getDisplayCharacter()
123 {
124 return 'o';
125 }
126
127 public Color getDisplayColor()
128 {
129 return Color.YELLOW;
130 }
131
132 public ItemType getItemType()
133 {
134 return ItemType.Ring;
135 }
136 },
137 Crocs {
138 public String getItemName()
139 {
140 return "Crocs";
141 }
142
143 public char getDisplayCharacter()
144 {
145 return 'd';
146 }
147
148 public Color getDisplayColor()
149 {
150 return new Color(128, 42, 42);
151 }
152
153 public ItemType getItemType()
154 {
155 return ItemType.Shoes;
79 } 156 }
80 }, 157 },
81 Key { 158 Key {
@@ -111,7 +188,22 @@ public enum Item
111 public abstract char getDisplayCharacter(); 188 public abstract char getDisplayCharacter();
112 public abstract Color getDisplayColor(); 189 public abstract Color getDisplayColor();
113 public abstract ItemType getItemType(); 190 public abstract ItemType getItemType();
114 public abstract boolean useItem(); 191
192 public boolean useItem()
193 {
194 switch (getItemType())
195 {
196 case Helmet:
197 case Sword:
198 case Shield:
199 case Ring:
200 case Shoes:
201 return Main.currentGame.equipItem(this);
202
203 default:
204 throw new java.lang.AbstractMethodError();
205 }
206 }
115 207
116 public static Item getWeightedRandomItem() 208 public static Item getWeightedRandomItem()
117 { 209 {
diff --git a/src/com/fourisland/frigidearth/ItemType.java b/src/com/fourisland/frigidearth/ItemType.java index f870fc6..0d925f5 100644 --- a/src/com/fourisland/frigidearth/ItemType.java +++ b/src/com/fourisland/frigidearth/ItemType.java
@@ -13,15 +13,39 @@ public enum ItemType
13 Helmet { 13 Helmet {
14 public double getRarity() 14 public double getRarity()
15 { 15 {
16 return 0.75; 16 return 0.2;
17 } 17 }
18 }, 18 },
19 Scroll { 19 Sword {
20 public double getRarity()
21 {
22 return 0.2;
23 }
24 },
25 Shield {
26 public double getRarity()
27 {
28 return 0.2;
29 }
30 },
31 Ring {
32 public double getRarity()
33 {
34 return 0.05;
35 }
36 },
37 Shoes {
20 public double getRarity() 38 public double getRarity()
21 { 39 {
22 return 0.25; 40 return 0.25;
23 } 41 }
24 }, 42 },
43 Scroll {
44 public double getRarity()
45 {
46 return 0.1;
47 }
48 },
25 Special { 49 Special {
26 public double getRarity() 50 public double getRarity()
27 { 51 {
diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index a61d0ee..71f803a 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java
@@ -984,6 +984,12 @@ public class MapViewGameState implements GameState
984 } 984 }
985 } 985 }
986 } 986 }
987
988 // Snow weakens (but doesn't kill) mobs too!
989 if ((grid[mob.x][mob.y] == Tile.Snow) && (heartbeat % 2 == 0))
990 {
991 mob.health--;
992 }
987 } 993 }
988 994
989 // Move snow 995 // Move snow
diff --git a/src/com/fourisland/frigidearth/MessageOverlay.java b/src/com/fourisland/frigidearth/MessageOverlay.java new file mode 100644 index 0000000..2aec2f0 --- /dev/null +++ b/src/com/fourisland/frigidearth/MessageOverlay.java
@@ -0,0 +1,67 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package com.fourisland.frigidearth;
6
7import java.awt.Color;
8import java.awt.Graphics2D;
9import java.util.ArrayList;
10import java.util.List;
11
12/**
13 *
14 * @author hatkirby
15 */
16public class MessageOverlay implements Renderable
17{
18 private final int TILE_WIDTH = 12;
19 private final int TILE_HEIGHT = 12;
20
21 List<String> message;
22 int x;
23 int y;
24 int width;
25
26 public MessageOverlay(String msg, int x, int y, int width)
27 {
28 message = new ArrayList<String>();
29 this.x = x;
30 this.y = y;
31 this.width = width;
32
33 String temp = msg;
34
35 while (temp.length() > width)
36 {
37 String shortm = temp.substring(0, width);
38
39 if ((temp.charAt(width) == ' ') || (shortm.endsWith(" ")))
40 {
41 message.add(shortm);
42 temp = temp.substring(width);
43 } else {
44 int lastSpace = shortm.lastIndexOf(" ");
45 message.add(shortm.substring(0, lastSpace));
46 temp = temp.substring(lastSpace);
47 }
48 }
49
50 message.add(temp);
51 }
52
53 public void render(Graphics2D g)
54 {
55 g.setColor(Color.BLACK);
56 g.fillRect(x*TILE_WIDTH, y*TILE_HEIGHT, (x+width)*TILE_WIDTH, (y+message.size())*TILE_HEIGHT);
57
58 for (int i=0; i<message.size(); i++)
59 {
60 for (int j=0; j<message.get(i).length(); j++)
61 {
62 g.drawImage(SystemFont.getCharacter(message.get(i).charAt(j), Color.WHITE), (x+j)*TILE_WIDTH, (y+i)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null);
63 }
64 }
65 }
66
67}