Wednesday, 17 April 2013

Project Complete

Project Complete

I have finally completed the project, all the code and report has been written up. A full listing of the code can be found further down the page.


public class Item {
 Boolean Usable;
 String Name;

 public Item(Boolean Usable, String Name){
 
  this.Usable = Usable;
  this.Name = Name;
 
 }
}



public class Monster {
 int hp;
 int damage;
 String name; 

public Monster(int hp, int damage, String name){
this.hp = hp;
this.damage = damage;
this.name = name;
}
}



public class Room {
 String Name;
 Boolean N;
 Boolean S;
 Boolean E;
 Boolean W;
 Boolean RmClr; 

 public Room(String Name, Boolean N, Boolean S, Boolean E, Boolean W, Boolean RmClr){
  this.Name = Name;
  this.N = N;
  this.S = S;
  this.W = W;
  this.E = E;
  this.RmClr = RmClr;
 }

}


import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;



public class main {
 public static void main(String[] args){
  Room[][] Map = new Room[5][5]; {
   Map[0][0] = new Room("Rm1", true, false, true, false, true);
   Map[0][1] = new Room("Rm2", true, true, true, false, false);
   Map[0][2] = new Room("Rm3", true, true, true, false, false);
   Map[0][3] = new Room("Rm4", true, true, true, false, false);
   Map[0][4] = new Room("Rm5", false, true, true, false, false);
   Map[1][0] = new Room("Rm6", true, false, true, true, false);
   Map[1][1] = new Room("Rm7", true, true, true, true, false);
   Map[1][2] = new Room("Rm8", true, true, true, true, false);
   Map[1][3] = new Room("Rm9", true, true, true, true, false);
   Map[1][4] = new Room("Rm10", false, true, true, true, false);
   Map[2][0] = new Room("Rm11", true, false, true, true, false);
   Map[2][1] = new Room("Rm12", true, true, true, true, false);
   Map[2][2] = new Room("Rm13", true, true, true, true, false);
   Map[2][3] = new Room("Rm14", true, true, true, true, false);
   Map[2][4] = new Room("Rm15", false, true, true, true, false);
   Map[3][0] = new Room("Rm16", true, false, true, true, false);
   Map[3][1] = new Room("Rm17", true, true, true, true, false);
   Map[3][2] = new Room("Rm18", true, true, true, true, false);
   Map[3][3] = new Room("Rm19", true, true, true, true, false);
   Map[3][4] = new Room("Rm20", false, true, true, true, false);
   Map[4][0] = new Room("Rm21", true, false, false, true, false);
   Map[4][1] = new Room("Rm22", true, true, false, true, false);
   Map[4][2] = new Room("Rm23", true, true, false, true, false);
   Map[4][3] = new Room("Rm24", true, true, false, true, false);
   Map[4][4] = new Room("Rm25", false, true, false, true, false);
   }
 
 
 
   Monster[][] MonMap = new Monster[5][5];{
  
   MonMap[0][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[0][1] = new Monster(15, 10, " Evil (Abed) Warlock");
   MonMap[0][2] = new Monster(35, 4, " Flatulant Old One");
   MonMap[0][3] = new Monster(40, 2, " Doppleganger Of Changception");
   MonMap[0][4] = new Monster(50, 9, " Brittanica The Protester");
   MonMap[1][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[1][1] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[1][2] = new Monster(42, 6, " Dean The Dalmatian");
   MonMap[1][3] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[1][4] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[2][0] = new Monster(10, 40, " The Great Rooory Train");
   MonMap[2][1] = new Monster(10, 40, " Hami The Destructive");
   MonMap[2][2] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[2][3] = new Monster(100, 5, " Irregular Mass");
   MonMap[2][4] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[3][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[3][1] = new Monster(150, 20, " Adamus The Destroyer");
   MonMap[3][2] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[3][3] = new Monster(20, 30, " MAD DOG!");
   MonMap[3][4] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[4][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[4][1] = new Monster(40, 10, " D-d-d-d-odds");
   MonMap[4][2] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[4][3] = new Monster(40, 7, " Mac");
   MonMap[4][4] = new Monster(150, 10, " The Dark Destroyer");
}


  Item[][] ItemMap = new Item[5][5];{
  
   ItemMap[0][0] = new Item(true, "Prop");
   ItemMap[0][1] = new Item(false, "Books");
   ItemMap[0][2] = new Item(true, "Hourglass");
   ItemMap[0][3] = new Item(true, "Pen");
   ItemMap[0][4] = new Item(false, "Birdcage");
   ItemMap[1][0] = new Item(true, "Hipflask");
   ItemMap[1][1] = new Item(true, "CD");
   ItemMap[1][2] = new Item(true, "Candle");
   ItemMap[1][3] = new Item(true, "Battery");
   ItemMap[1][4] = new Item(false, "Decorative Sword");
   ItemMap[2][0] = new Item(false, "Gold Ring");
   ItemMap[2][1] = new Item(false, "Diary");
   ItemMap[2][2] = new Item(true, "Pocketwatch");
   ItemMap[2][3] = new Item(false, "Bird Feather");
   ItemMap[2][4] = new Item(true, "Coins");
   ItemMap[3][0] = new Item(false, "Memory Stick");
   ItemMap[3][1] = new Item(false, "DVD");
   ItemMap[3][2] = new Item(false, "Dog Collar");
   ItemMap[3][3] = new Item(false, "Spoon");
   ItemMap[3][4] = new Item(false, "Perfume Bottle");
   ItemMap[4][0] = new Item(false, "Papers");
   ItemMap[4][1] = new Item(false, "Pendant");
   ItemMap[4][2] = new Item(false, "Marbles");
   ItemMap[4][3] = new Item(false, "Crown");
   ItemMap[4][4] = new Item(false, "Warhammer");
  
  
  
  }
 
  Item[] inventory = new Item[5];{
   inventory[0] = new Item(false, "Empty");
   inventory[1] = new Item(false, "Empty");
   inventory[2] = new Item(false, "Empty");
   inventory[3] = new Item(false, "Empty");
   inventory[4] = new Item(false, "Empty");
  }
 
 
  String PName;
  int PHealth = 100;
  int PDam = 10;
  int PScore = 0;
  boolean ItemTaken =false;
  int x = 0;
  int y = 0;
  Scanner input = new Scanner(System.in);
  String UserInput;
 
 
  System.out.print("What is your name ?");
  PName = input.nextLine();

 
  while(true){
   System.out.print("You are in " + Map[x][y].Name);
   System.out.println();
   System.out.print("What would you like to do?");
   if(Map[x][y].RmClr == true){
    System.out.println();
    System.out.print("The room is clear, you may pass through freely.");
   }else{
   System.out.println();
   System.out.print("You must defeat the monster present to pass through the room");
   }  
   UserInput = input.nextLine();
   UserInput = UserInput.toUpperCase();
  
  
   if(UserInput.equals("SAVE")){
    FileOutputStream out; // declare a file output object
                PrintStream p; // declare a print stream object
                try
                {
                        // Create a new file output stream
                        // connected to "myfile.txt"
                        out = new FileOutputStream("Scores.txt");
                        // Connect print stream to the output stream
                        p = new PrintStream( out );
 
                        p.println ("Name: " + PName + " Score: " + PScore);
                        p.close();
                }
                catch (Exception e)
                {
                        System.err.println ("Error writing to file");
                }
   }
  
  
  
  
  
  
   if(UserInput.equals("BATTLE")){
  
     System.out.println(MonMap[x][y].name + " Attacks for " + MonMap[x][y].damage);
     System.out.println("You now have" + PHealth);
   
   Boolean EnemyDefeated = false;
   System.out.print("You are now battling " + MonMap[x][y].name);
   System.out.print("What would you like to do?");
  
   while(EnemyDefeated ==  false){
   UserInput = input.nextLine();
   UserInput = UserInput.toUpperCase();
    if(UserInput.equals("ATTACK")){
     MonMap[x][y].hp = MonMap[x][y].hp - PDam;
     System.out.println("You attack the monster for " + PDam + " points of damage");
     System.out.println();
      if(MonMap[x][y].hp <= 0){
      Map[x][y].RmClr = true;
      EnemyDefeated = true;
      PScore = PScore + 10;
      System.out.print("The enemy has been defeated");
       if(PScore >= 250){
        System.out.println("You have completed the game, well done");
        System.exit(0);
       }
      }
    }
   
    if (UserInput.equals("KILL")){
     MonMap[x][y].hp = 0;
     Map[x][y].RmClr = true;
    }
    if(UserInput.equals("RUN")){
     System.out.print("In which direction would you like to run?");
     UserInput = input.nextLine();
     UserInput = UserInput.toUpperCase();
      if(UserInput.equals("NORTH")){
       y = y + 1;
       EnemyDefeated = true;
      }
      if(UserInput.equals("SOUTH")){
       y = y - 1;
       EnemyDefeated = true;
      }
      if(UserInput.equals("EAST")){
       x= x + 1;
       EnemyDefeated = true;
      }
     
      if(UserInput.equals("WEST")){
       x = x - 1;
       EnemyDefeated = true;
      }
    }
   
     PHealth = PHealth - MonMap[x][y].damage;
      if(PHealth <=0){
       System.out.println("I am afraid you have died, please try again.");
       System.out.println("The game will now return to the beggining");
       for(int i=0;i<=4;i++){
        Map[i][1].RmClr = false;
        Map[i][2].RmClr = false;
        Map[i][3].RmClr = false;
        Map[i][4].RmClr = false;
        PScore = 0;
        x=0;
        y=0;
       }
      }   
}
}
  
   if(UserInput.equals("REST")){
    if((x==0)&(y==0)){
     PHealth = PHealth + (100-PHealth);
     System.out.println();
     System.out.println("You are now fully healed.");
    }else{
     System.out.println();
     System.out.print("You cannot heal here, go to Rm1.");
    }
   }
   if(UserInput.equals("END")){
    System.out.println();
    System.out.print("Thank you for playing, now exiting game");
    System.exit(0);
   }

   if((UserInput.equals("NORTH")) & (Map[x][y].N == true) & (Map[x][y].RmClr == true)){
    System.out.print("You have moved north");
    System.out.println();
    y = y+1;
   }else if((UserInput.equals("NORTH"))&(Map[x][y].N == false)){
    System.out.print("You cannot go that way, it is blocked.");
    System.out.println();
   }
  
  
   if((UserInput.equals("EAST")) & (Map[x][y].E == true)& (Map[x][y].RmClr == true)){
    System.out.print("You have moved east");
    System.out.println();
    x = x+1;

   }else if((UserInput.equals("EAST"))&(Map[x][y].E == false)){
    System.out.print("You cannot go that waym, it is bocked");
    System.out.println();
   }
  
  
   if((UserInput.equals("SOUTH")) & (Map[x][y].S == true)& (Map[x][y].RmClr == true)){
    System.out.print("You have moved south");
    System.out.println();
    y = y-1;
   }else if((UserInput.equals("SOUTH"))&(Map[x][y].S == false)){
    System.out.print("You cannot go that way, it is blocked.");
    System.out.println();
   }
  
  
   if((UserInput.equals("WEST")) & (Map[x][y].W == true)& (Map[x][y].RmClr == true)){
    System.out.print("You have moved west");
    x = x-1;
   }else if((UserInput.equals("WEST"))&(Map[x][y].W == false)){
    System.out.print("You cannot go that way, it is blocked.");
   }
  
  
 
    if(UserInput.equals("INVENTORY")){
    System.out.println();
    System.out.print("Your inventory contains:");
    for(int i = 0; i<=4; i++){
     System.out.println();
     System.out.print(inventory[i].Name);
    }
   }
  
  
   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++;
      }                   
  }
 
 




 }
}
}


Saturday, 23 March 2013

Final Monster, Item and Room Maps.

public static void main(String[] args){
  Room[][] Map = new Room[5][5]; {
   Map[0][0] = new Room("Rm1", true, false, true, false, true);
   Map[0][1] = new Room("Rm2", true, true, true, false, false);
   Map[0][2] = new Room("Rm3", true, true, true, false, false);
   Map[0][3] = new Room("Rm4", true, true, true, false, false);
   Map[0][4] = new Room("Rm5", false, true, true, false, false);
   Map[1][0] = new Room("Rm6", true, false, true, true, false);
   Map[1][1] = new Room("Rm7", true, true, true, true, false);
   Map[1][2] = new Room("Rm8", true, true, true, true, false);
   Map[1][3] = new Room("Rm9", true, true, true, true, false);
   Map[1][4] = new Room("Rm10", false, true, true, true, false);
   Map[2][0] = new Room("Rm11", true, false, true, true, false);
   Map[2][1] = new Room("Rm12", true, true, true, true, false);
   Map[2][2] = new Room("Rm13", true, true, true, true, false);
   Map[2][3] = new Room("Rm14", true, true, true, true, false);
   Map[2][4] = new Room("Rm15", false, true, true, true, false);
   Map[3][0] = new Room("Rm16", true, false, true, true, false);
   Map[3][1] = new Room("Rm17", true, true, true, true, false);
   Map[3][2] = new Room("Rm18", true, true, true, true, false);
   Map[3][3] = new Room("Rm19", true, true, true, true, false);
   Map[3][4] = new Room("Rm20", false, true, true, true, false);
   Map[4][0] = new Room("Rm21", true, false, false, true, false);
   Map[4][1] = new Room("Rm22", true, true, false, true, false);
   Map[4][2] = new Room("Rm23", true, true, false, true, false);
   Map[4][3] = new Room("Rm24", true, true, false, true, false);
   Map[4][4] = new Room("Rm25", false, true, false, true, false);
   }
 
 
 
   Monster[][] MonMap = new Monster[5][5];{
  
   MonMap[0][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[0][1] = new Monster(15, 10, " Evil (Abed) Warlock");
   MonMap[0][2] = new Monster(35, 4, " Flatulant Old One");
   MonMap[0][3] = new Monster(40, 2, " Doppleganger Of Changception");
   MonMap[0][4] = new Monster(50, 9, " Brittanica The Protester");
   MonMap[1][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[1][1] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[1][2] = new Monster(42, 6, " Dean The Dalmatian");
   MonMap[1][3] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[1][4] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[2][0] = new Monster(10, 40, " The Great Rooory Train");
   MonMap[2][1] = new Monster(10, 40, " Hami The Destructive");
   MonMap[2][2] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[2][3] = new Monster(100, 5, " Irregular Mass");
   MonMap[2][4] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[3][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[3][1] = new Monster(150, 20, " Adamus The Destroyer");
   MonMap[3][2] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[3][3] = new Monster(20, 30, " MAD DOG!");
   MonMap[3][4] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[4][0] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[4][1] = new Monster(40, 10, " D-d-d-d-odds");
   MonMap[4][2] = new Monster(30, 5, " Miscellanous Grunt");
   MonMap[4][3] = new Monster(40, 7, " Mac");
   MonMap[4][4] = new Monster(150, 10, " The Dark Destroyer");
}


  Item[][] ItemMap = new Item[5][5];{
  
   ItemMap[0][0] = new Item(true, "Prop");
   ItemMap[0][1] = new Item(false, "Books");
   ItemMap[0][2] = new Item(true, "Hourglass");
   ItemMap[0][3] = new Item(true, "Pen");
   ItemMap[0][4] = new Item(false, "Birdcage");
   ItemMap[1][0] = new Item(true, "Hipflask");
   ItemMap[1][1] = new Item(true, "CD");
   ItemMap[1][2] = new Item(true, "Candle");
   ItemMap[1][3] = new Item(true, "Battery");
   ItemMap[1][4] = new Item(false, "Decorative Sword");
   ItemMap[2][0] = new Item(false, "Gold Ring");
   ItemMap[2][1] = new Item(false, "Diary");
   ItemMap[2][2] = new Item(true, "Pocketwatch");
   ItemMap[2][3] = new Item(false, "Bird Feather");
   ItemMap[2][4] = new Item(true, "Coins");
   ItemMap[3][0] = new Item(false, "Memory Stick");
   ItemMap[3][1] = new Item(false, "DVD");
   ItemMap[3][2] = new Item(false, "Dog Collar");
   ItemMap[3][3] = new Item(false, "Spoon");
   ItemMap[3][4] = new Item(false, "Perfume Bottle");
   ItemMap[4][0] = new Item(false, "Papers");
   ItemMap[4][1] = new Item(false, "Pendant");
   ItemMap[4][2] = new Item(false, "Marbles");
   ItemMap[4][3] = new Item(false, "Crown");
   ItemMap[4][4] = new Item(false, "Warhammer");
  
  
  
  }
 
  Item[] inventory = new Item[5];{
   inventory[0] = new Item(false, "Empty");
   inventory[1] = new Item(false, "Empty");
   inventory[2] = new Item(false, "Empty");
   inventory[3] = new Item(false, "Empty");
   inventory[4] = new Item(false, "Empty");
  }

Friday, 1 March 2013

Battle System

I have finally after a few weeks of testing and iteration come out with a working battle system for the project.

if(UserInput.equals("BATTLE")){
  
     System.out.println(MonMap[x][y].name + " Attacks for " + MonMap[x][y].damage);
     System.out.println("You now have" + PHealth);
   
   Boolean EnemyDefeated = false;
   System.out.print("You are now battling " + MonMap[x][y].name);
   System.out.print("What would you like to do?");
  
   while(EnemyDefeated ==  false){
   UserInput = input.nextLine();
   UserInput = UserInput.toUpperCase();
    if(UserInput.equals("ATTACK")){
     MonMap[x][y].hp = MonMap[x][y].hp - PDam;
     System.out.println("You attack the monster for " + PDam + " points of damage");
     System.out.println();
      if(MonMap[x][y].hp <= 0){
      Map[x][y].RmClr = true;
      EnemyDefeated = true;
      PScore = PScore + 10;
      System.out.print("The enemy has been defeated");
       if(PScore >= 250){
        System.out.println("You have completed the game, well done");
        System.exit(0);
       }
      }
    }
   
    if (UserInput.equals("KILL")){
     MonMap[x][y].hp = 0;
     Map[x][y].RmClr = true;
    }
    if(UserInput.equals("RUN")){
     System.out.print("In which direction would you like to run?");
     UserInput = input.nextLine();
     UserInput = UserInput.toUpperCase();
      if(UserInput.equals("NORTH")){
       y = y + 1;
       EnemyDefeated = true;
      }
      if(UserInput.equals("SOUTH")){
       y = y - 1;
       EnemyDefeated = true;
      }
      if(UserInput.equals("EAST")){
       x= x + 1;
       EnemyDefeated = true;
      }
     
      if(UserInput.equals("WEST")){
       x = x - 1;
       EnemyDefeated = true;
      }
    }
   
     PHealth = PHealth - MonMap[x][y].damage;
      if(PHealth <=0){
       System.out.println("I am afraid you have died, please try again.");
       System.out.println("The game will now return to the beggining");
       for(int i=0;i<=4;i++){
        Map[i][1].RmClr = false;
        Map[i][2].RmClr = false;
        Map[i][3].RmClr = false;
        Map[i][4].RmClr = false;
        PScore = 0;
        x=0;
        y=0;
       }
      }   
}
}

Friday, 8 February 2013

File Handling In Java

File Handling and Saving Score

The following code is used to save the players score to the same folder as the eclipse project called "Scores.txt"

if(UserInput.equals("SAVE")){
    FileOutputStream out; // declare a file output object
                PrintStream p; // declare a print stream object
                try
                {
                        // Create a new file output stream
                        // connected to "myfile.txt"
                        out = new FileOutputStream("Scores.txt");
                        // Connect print stream to the output stream
                        p = new PrintStream( out );
 
                        p.println ("Name: " + PName + " Score: " + PScore);
                        p.close();
                }
                catch (Exception e)
                {
                        System.err.println ("Error writing to file");
                }

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++;
      }                   
  }

Wednesday, 14 November 2012

Filling A 2-D Array with a Self Defined Room Class


I have just filled the 2-D Array that is store my map with different rooms. The rooms are defined in a Room Class which can be seen bellow as well as the code for the filling of the 2-D Array. As of yet I am having trouble accesing the data from these rooms. :(


public class Room {
 int RmNo;
 Boolean North;
 Boolean East;
 Boolean South;
 Boolean West;
 String RmName;

 public Room(int number, Boolean N, Boolean E, Boolean S, Boolean W, String name){

 int RmNo = number;
 Boolean North = N;
 Boolean East = E;
 Boolean South = S;
 Boolean West = W;
 String RmName = name;
 
 }
}



public class GlobalDataStore {
 public static Room[][] Rooms = new Room[5][5];{

 Rooms[1][1] = new Room(1, true, true, false, false, "Entrance Chamber");
 Rooms[1][2] = new Room(2, true, true, false, false, "Main Hall");
 Rooms[1][3] = new Room(3, true, true, false, false, "Pantry");
 Rooms[1][4] = new Room(4, true, true, false, false, "Boudoire");
 Rooms[1][5] = new Room(5, true, true, false, false, "Kitchen");
 Rooms[2][1] = new Room(6, true, true, false, false, "Scullery");
 Rooms[2][2] = new Room(7, true, true, false, false, "Throne Room");
 Rooms[2][3] = new Room(8, true, true, false, false, "Toilet");
 Rooms[2][4] = new Room(9, true, true, false, false, "Trophy Room");
 Rooms[2][5] = new Room(10, true, true, false, false, "Dining Chamber");
 Rooms[3][1] = new Room(11, true, true, false, false, "Bedrooms");
 Rooms[3][2] = new Room(12, true, true, false, false, "Jousting Room");
 Rooms[3][3] = new Room(13, true, true, false, false, "Garden");
 Rooms[3][4] = new Room(14, true, true, false, false, "Fountain");
 Rooms[3][5] = new Room(15, true, true, false, false, "Fishing Hut");
 Rooms[4][1] = new Room(16, true, true, false, false, "Courtyard");
 Rooms[4][2] = new Room(17, true, true, false, false, "Library");
 Rooms[4][3] = new Room(18, true, true, false, false, "Hidden Chamber");
 Rooms[4][4] = new Room(19, true, true, false, false, "Basement");
 Rooms[4][5] = new Room(20, true, true, false, false, "Torture Chamber");
 Rooms[5][1] = new Room(21, true, true, false, false, "Basement 2");
 Rooms[5][2] = new Room(22, true, true, false, false, "Treasure Room");
 Rooms[5][3] = new Room(23, true, true, false, false, "Annex Of Doom");
 Rooms[5][4] = new Room(24, true, true, false, false, "Chamber Of Awakening");
 Rooms[5][5] = new Room(25, true, true, false, false, "End Room");
}
}

Tuesday, 16 October 2012

Project Specification

Just handed in my project specification which includes:
- Scope And Boundaries
- Resources Required   
-Inputs, Processes And Outputs
-Feasability Study
-Comparison Of Programming Environments
- My Proposed User Interface
- A List Of Data Structures
Now going to continue reading Java and planning my code.


Tuesday, 4 September 2012

Project Proposal

Project Proposal


My project will be an adventure game where the player will navigate a series of rooms represented by a 2-D Array. The main objective of the game will to reach the boss room where they will battle a boss like creature (possibly randomly generated). After the boss room there will be a series of 'bonus' rooms sorted according to the difficulty (level) of each monster present in the room (will be randomly generated). The battles will be done via a function or procedure which I will right which will affect variable such as: Player Health, Player Energy, Enemy Health, Enemy Energy etc.

The program will either be presented in a completely text based format e.g. a C++ Console Program, A visual basic Interface where the main output will be in text but there will still be various buttons and GUI elements for the user to interact with or possibly coded in Java with a full GUI with moving sprites and background.