Tuesday, 29 January 2013

Most Recent Update

Have completed movement around the map and am working on an inventory system.
Main.Java:
import
java.util.*;
 
 
public
class Main {
public static void main(String[] args){
Item GameItems[][] =
new Item[5][5];{
GameItems[0][0] =
new Item();
GameItems[0][1] =
new Item();
GameItems[0][2] =
new Item();
GameItems[0][3] =
new Item();
GameItems[0][4] =
new Item();
GameItems[1][0] =
new Item();
GameItems[1][1] =
new Item();
GameItems[1][2] =
new Item();
GameItems[1][3] =
new Item();
GameItems[1][4] =
new Item();
GameItems[2][0] =
new Item();
GameItems[2][1] =
new Item();
GameItems[2][2] =
new Item();
GameItems[2][3] =
new Item();
GameItems[2][4] =
new Item();
GameItems[3][0] =
new Item();
GameItems[3][1] =
new Item();
GameItems[3][2] =
new Item();
GameItems[3][3] =
new Item();
GameItems[3][4] =
new Item();
GameItems[4][0] =
new Item();
GameItems[4][1] =
new Item();
GameItems[4][2] =
new Item();
GameItems[4][3] =
new Item();
GameItems[4][4] =
new Item();
}
int x;
int y;
String userinput;
Scanner Input =
new Scanner(System.in);
Boolean moved;
int InventorySpace;
Item Inventory[] =
new Item[10];
Item Blank =
new Item(0, false);
for(int i=0; i< 9 ; i++){
Inventory[i] = Blank;
}
Room[][] Rooms =
new Room[5][5];{
Rooms[0][0] =
new Room(1, true, true, false, false, "The Entrance Chamber");
Rooms[0][1] =
new Room(2, true, true, false, false, "The Main Hall");
Rooms[0][2] =
new Room(3, true, true, false, false, "The Pantry");
Rooms[0][3] =
new Room(4, true, true, false, false, "The Boudoire");
Rooms[0][4] =
new Room(5, true, true, false, false, "The Kitchen");
Rooms[1][0] =
new Room(6, true, true, false, false, "The Scullery");
Rooms[1][1] =
new Room(7, true, true, false, false, "The Throne Room");
Rooms[1][2] =
new Room(8, true, true, false, false, "The Toilet");
Rooms[1][3] =
new Room(9, true, true, false, false, "The Trophy Room");
Rooms[1][4] =
new Room(10, true, true, false, false, "The Dining Chamber");
Rooms[2][0] =
new Room(11, true, true, false, false, "The Bedrooms");
Rooms[2][1] =
new Room(12, true, true, false, false, "The Jousting Room");
Rooms[2][2] =
new Room(13, true, true, false, false, "The Garden");
Rooms[2][3] =
new Room(14, true, true, false, false, "The Fountain");
Rooms[2][4] =
new Room(15, true, true, false, false, "The Fishing Hut");
Rooms[3][0] =
new Room(16, true, true, false, false, "The Courtyard");
Rooms[3][1] =
new Room(17, true, true, false, false, "The Library");
Rooms[3][2] =
new Room(18, true, true, false, false, "The Hidden Chamber");
Rooms[3][3] =
new Room(19, true, true, false, false, "The Basement");
Rooms[3][4] =
new Room(20, true, true, false, false, "The Torture Chamber");
Rooms[4][0] =
new Room(21, true, true, false, false, "The Basement 2");
Rooms[4][1] =
new Room(22, true, true, false, false, "The Treasure Room");
Rooms[4][2] =
new Room(23, true, true, false, false, "The Annex Of Doom");
Rooms[4][3] =
new Room(24, true, true, false, false, "The Chamber Of Awakening");
Rooms[4][4] =
new Room(25, true, true, false, false, "The End Room");
}
 
InventorySpace = 0;
x = 0;
y = 0;
System.
out.print("Press N to move north, W for west, S for South and E for East");
System.
out.println();
System.
out.print("To pickup an Item in the room type in 'pickup'");
System.
out.println();
System.
out.print("At any time press help to display the help message");
while((true)){
moved=
false;
System.
out.println();
System.
out.print("You are currently in " + Rooms[x][y].RmName);
System.
out.println();
userinput = Input.next();
userinput = userinput.toUpperCase();
if(userinput.equals("N")){
if(Rooms[x][y].North == true){
y++;
System.
out.print("Player Moved North");
moved =
true;
}
}
if(userinput.equals("S")){
if(Rooms[x][y].South == true){
y--;
System.
out.print("Player Moved South");
moved =
true;
}
}
if(userinput.equals("W")){
if(Rooms[x][y].West == true){
y++;
System.
out.print("Player Moved North");
moved =
true;
}
}
if(userinput.equals("E")){
if(Rooms[x][y].East == true){
x++;
System.
out.print("Player Moved East");
moved =
true;
}
}
if(moved==false){
System.
out.print("");
System.
out.print("You cannot go that way");
}
}
}
}

Rooms.Java:
public
class Room {
int RmNo;
Boolean
North;
Boolean
East;
Boolean
South;
Boolean
West;
String
RmName;
Item
RmItem;
public Room(int number, Boolean N, Boolean E, Boolean S, Boolean W, String name, Item RmItem){
this.RmNo = number;
this.North = N;
this.South = S;
this.East = E;
this.West = W;
this.RmName = name;
this.RmItem = RmItem;
}
}

Item.Java:
public
class Item {
Boolean
usable;
int weight;
String
name;
public Item(int weight, Boolean usable, String name){
this.usable = usable;
this.weight = weight;
this.name = name;
}
}

Wednesday, 16 January 2013

Inventory

Inventory System Working

I have designed an Algorithim to pick up Items from the game world using an ItemMap similar to the game map but storing Items not rooms.

if(UserInput.equals("PICKUP")){
    int i =0;
     while(ItemTaken == false){
      if(inventory[i].Name.equals("Empty")){
       inventory[i].Name = ItemMap[x][y].Name;
       inventory[i].Usable = ItemMap[x][y].Usable;
       ItemMap[x][y].Name = "Empty";
       ItemMap[x][y].Usable = false;
       ItemTaken = true;
      }else i++;
      }                   
  }