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;
}
}
this.hp = hp;
this.damage = damage;
this.name = name;
}
}
public class Room {
String Name;
Boolean N;
Boolean S;
Boolean E;
Boolean W;
Boolean RmClr;
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;
}
}
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;
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");
{
// 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 = new PrintStream( out );
p.println ("Name: " + PName + " Score: " + PScore);
p.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}
}
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("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;
}
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.");
}
}
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);
}
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++;
}
}
}
}
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++;
}
}
}
}
}
No comments:
Post a Comment