improved inventory

This commit is contained in:
musilto9 2020-04-14 14:20:29 +02:00
parent 5256dc6c4f
commit c642c196b8
24 changed files with 207 additions and 27 deletions

View File

@ -2,7 +2,7 @@ package ruscz.game.gameOfProd.Cells;
import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Image.ImageCell;
import ruscz.game.gameOfProd.Image.ImageDoor; import ruscz.game.gameOfProd.Inventory.Item;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import java.awt.*; import java.awt.*;
@ -10,14 +10,12 @@ import java.awt.*;
public class DoorCell extends InteractionCell { public class DoorCell extends InteractionCell {
private boolean isOpen; private boolean isOpen;
private boolean isLocked; private boolean isLocked;
private boolean requiresKey;
private boolean directionVert; private boolean directionVert;
public DoorCell(int x, int y, boolean directionVert, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window, boolean requiresKey) { public DoorCell(int x, int y, boolean directionVert, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window) {
super(x, y, message, dialog, imageCell, window, true); super(x, y, message, dialog, imageCell, window, true);
this.isOpen = false; this.isOpen = false;
this.isLocked = true; this.isLocked = true;
this.requiresKey = requiresKey;
this.directionVert = directionVert; this.directionVert = directionVert;
} }
@ -36,6 +34,12 @@ public class DoorCell extends InteractionCell {
(getY() - 1) * getSize(), getSize() * 2, getSize() * 2, null); (getY() - 1) * getSize(), getSize() * 2, getSize() * 2, null);
} }
@Override
public void useItem(Item item) {
isLocked = false;
super.useItem(item);
}
public boolean isOpen() { public boolean isOpen() {
return isOpen; return isOpen;
} }
@ -51,12 +55,4 @@ public class DoorCell extends InteractionCell {
public void setLocked(boolean locked) { public void setLocked(boolean locked) {
isLocked = locked; isLocked = locked;
} }
public boolean isRequiresKey() {
return requiresKey;
}
public void setRequiresKey(boolean requiresKey) {
this.requiresKey = requiresKey;
}
} }

View File

@ -3,6 +3,8 @@ package ruscz.game.gameOfProd.Cells;
import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Image.ImageCell;
import ruscz.game.gameOfProd.Image.ImageDialog; import ruscz.game.gameOfProd.Image.ImageDialog;
import ruscz.game.gameOfProd.Inventory.InventoryManager;
import ruscz.game.gameOfProd.Inventory.Item;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import java.awt.*; import java.awt.*;
@ -88,6 +90,41 @@ public class InteractionCell extends Cell {
break; break;
} }
} }
else if (data.contains("<additem>")) {
String[] dialogInfo = data.split(" ");
Item item;
if (dialogInfo.length == 4) {
item = new Item(dialogInfo[1], Integer.parseInt(dialogInfo[2]), dialogInfo[3]);
}
else {
item = new Item(dialogInfo[1], dialogInfo[2]);
}
InventoryManager.addItem(item);
String name = dialogInfo[1].replace("-", " ");
name = name.substring(0,1).toUpperCase() + name.substring(1);
data = name + " was added to your inventory.";
dialog.hideText();
dialog.setText(data);
dialog.showText();
}
else if (data.contains("<removeitem>")) {
String[] dialogInfo = data.split(" ");
String name = dialogInfo[1].replace("-", " ");
name = name.substring(0,1).toUpperCase() + name.substring(1);
if(InventoryManager.isInInventory(InventoryManager.findItemByName(name))) {
useItem(InventoryManager.findItemByName(name));
data = "You used " + name + ".";
dialog.hideText();
dialog.setText(data);
dialog.showText();
}
else {
data = "You need " + name + " to proceed.";
dialog.hideText();
dialog.setText(data);
dialog.showText();
}
}
else { else {
if (data.contains("<br/>")) if (data.contains("<br/>"))
data = "<html>" + data + "</html>"; data = "<html>" + data + "</html>";
@ -116,6 +153,10 @@ public class InteractionCell extends Cell {
} }
} }
public void useItem(Item item) {
InventoryManager.removeItem(item);
}
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
super.paint(g); super.paint(g);

View File

@ -97,7 +97,7 @@ public class Person extends Cell {
} }
else if (isDoorInFront(x,y,directionSight)) { else if (isDoorInFront(x,y,directionSight)) {
DoorCell door = map.findDoorByXY(x, y, directionSight); DoorCell door = map.findDoorByXY(x, y, directionSight);
if (!door.isLocked()) { if (!door.isLocked() && !isInEvent) {
if (door.isOpen()) if (door.isOpen())
door.setOpen(false); door.setOpen(false);
else else

View File

@ -33,6 +33,22 @@ public class Item extends InteractionCell {
this.isActive = true; this.isActive = true;
} }
public Item(String name, String itemAction) {
super(-1, -1, null, null, null, null, true);
message = parseNameToMessage(name);
this.multiplicity = 1;
setItemActionByName(itemAction);
this.isActive = false;
}
public Item(String name, int multiplicity, String itemAction) {
super(-1, -1, null, null, null, null, true);
message = parseNameToMessage(name);
this.multiplicity = multiplicity;
setItemActionByName(itemAction);
this.isActive = false;
}
@Override @Override
public void startEvent() { public void startEvent() {
WindowOfFreeMove.setCanPersonMove(false); WindowOfFreeMove.setCanPersonMove(false);

View File

@ -116,7 +116,7 @@ public class Map {
if (door.length == 2) if (door.length == 2)
map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(door[1]), map.getImageCell(), window)); map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(door[1]), map.getImageCell(), window));
else else
map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(door[1]), door[2], new Dialog(window.getDialogBar()), map.getImageCell(), window, Boolean.parseBoolean(door[3]))); map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(door[1]), door[2], new Dialog(window.getDialogBar()), map.getImageCell(), window));
} else if (line[x].contains("ITEM")) { } else if (line[x].contains("ITEM")) {
String[] item = line[x].split(","); String[] item = line[x].split(",");
if (item.length == 5) if (item.length == 5)
@ -149,8 +149,8 @@ public class Map {
else if (line[x].contains("DOORTO")) { else if (line[x].contains("DOORTO")) {
String[] doorTo = line[x].split(","); String[] doorTo = line[x].split(",");
if (doorTo[1].equals("locked")) { if (doorTo[1].equals("locked")) {
map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(doorTo[2]), doorTo[3], new Dialog(window.getDialogBar()), map.getImageCell(), window, Boolean.parseBoolean(doorTo[4]))); map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(doorTo[2]), doorTo[3], new Dialog(window.getDialogBar()), map.getImageCell(), window));
map.addMoveToEvent(new EventMoveToCell(Integer.parseInt(doorTo[5]), Integer.parseInt(doorTo[6]), x, y, findMapByName(doorTo[7], window), window, false)); map.addMoveToEvent(new EventMoveToCell(Integer.parseInt(doorTo[4]), Integer.parseInt(doorTo[5]), x, y, findMapByName(doorTo[6], window), window, false));
} }
else { else {
map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(doorTo[1]), map.getImageCell(), window)); map.addInteractionEvent(new DoorCell(x, y, Boolean.parseBoolean(doorTo[1]), map.getImageCell(), window));

View File

@ -114,7 +114,6 @@ public class WindowOfFreeMove extends JLayeredPane {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KEY_ESCAPE){ if (e.getKeyCode() == KEY_ESCAPE){
System.out.println("escape");
game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING)); game.dispatchEvent(new WindowEvent(game, WindowEvent.WINDOW_CLOSING));
return; return;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -0,0 +1,2 @@
<removeitem> blue-key-card
<end>

View File

@ -0,0 +1,4 @@
Just like the trash you are..
You found a Blue key card.
<additem> blue-key-card key
<end>

View File

@ -0,0 +1,2 @@
<removeitem> white-key-card
<end>

View File

@ -6,7 +6,7 @@
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 390 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 390 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

View File

@ -1,6 +1,6 @@
20 13 20 13
BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d
BLOCK BLOCK BLOCK BLOCK DOORTO,true,0,3,boss BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOORTO,true,0,3,boss BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK
@ -8,7 +8,7 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BL
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,openspace EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,openspace EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,openspace EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,openspace EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK inter,trash EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
BLOCK BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK BLOCK BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK
BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK DOORTO,locked,true,white-key-card,2,1,treasure BLOCK BLOCK

View File

@ -9,7 +9,7 @@ BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK DOOR,true BLOCK BLOCK EMPTY
BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block ITEM,white-key-card,19,key block block EMPTY block BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block ITEM,white-key-card,19,key block block EMPTY block
BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK DOOR,true BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK DOOR,true,blue-key-card BLOCK BLOCK BLOCK
BLOCK EMPTY block block EMPTY inter,minecraft inter,minecraft EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY block block EMPTY inter,minecraft inter,minecraft EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY block block EMPTY inter,minecraft inter,minecraft EMPTY BLOCK,u EMPTY EMPTY EMPTY EMPTY EMPTY block EMPTY EMPTY EMPTY block block BLOCK EMPTY block block EMPTY inter,minecraft inter,minecraft EMPTY BLOCK,u EMPTY EMPTY EMPTY EMPTY EMPTY block EMPTY EMPTY EMPTY block block
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY DOOR,false EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY DOOR,false EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block

View File

@ -0,0 +1,11 @@
<tileset> CertificateOfShame.png 650 500 50
0 10 20 30 40 50 60 70 80 90 100 110 120
1 11 21 31 41 51 61 71 81 91 101 111 121
2 12 22 32 42 52 62 72 82 92 102 112 122
3 13 23 33 43 53 63 73 83 93 103 113 123
4 14 24 34 44 54 64 74 84 94 104 114 124
5 15 25 35 45 55 65 75 85 95 105 115 125
6 13 26 36 46 56 66 76 86 96 106 116 126
7 17 27 37 47 57 67 77 87 97 107 117 127
8 18 28 38 48 58 68 78 88 98 108 118 128
9 19 29 39 49 59 69 79 89 99 109 119 129

View File

@ -0,0 +1,11 @@
13 10
block block block block block block moveto,2,3,office block block block block block block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
block block block block block block block block block block block block block

View File

@ -7,3 +7,4 @@ m6
openspace openspace
office office
boss boss
treasure

View File

@ -0,0 +1,75 @@
<map>
<mapName>m1</mapName>
<events>
</events>
</map>
<map>
<mapName>m2</mapName>
<events>
<event>
<x>7</x>
<y>2</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m3</mapName>
<events>
<event>
<x>2</x>
<y>5</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m4</mapName>
<events>
<event>
<x>3</x>
<y>3</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>m5</mapName>
<events>
</events>
</map>
<map>
<mapName>m6</mapName>
<events>
<event>
<x>11</x>
<y>11</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>openspace</mapName>
<events>
</events>
</map>
<map>
<mapName>office</mapName>
<events>
</events>
</map>
<map>
<mapName>boss</mapName>
<events>
<event>
<x>4</x>
<y>18</y>
<active>true</active>
</event>
</events>
</map>
<map>
<mapName>treasure</mapName>
<events>
</events>
</map>

View File

@ -68,3 +68,8 @@
</event> </event>
</events> </events>
</map> </map>
<map>
<mapName>treasure</mapName>
<events>
</events>
</map>

View File

@ -0,0 +1 @@
TODO: Inventory

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -0,0 +1,5 @@
<location>
<map>m1</map>
<x>1</x>
<y>7</y>
</location>

View File

@ -1,5 +1,5 @@
<location> <location>
<map>openspace</map> <map>office</map>
<x>8</x> <x>17</x>
<y>16</y> <y>11</y>
</location> </location>

View File

@ -0,0 +1 @@
TODO: Village