import java.util.ArrayList;
import java.util.Scanner;
public class Main
{
/**
* This the main class of my game. I didnt have time to comment the whole program because I had to make this in 5days
*/
//terms
final static int NORTH = 0;
final static int SOUTH = 1;
final static int WEST = 2;
final static int EAST = 3;
//end terms
public static Main_char player = new Main_char("Player", 0, 0, 10, 0, 15, 15, 1, 1, null);
public static rpg_char Monster_1 = new rpg_char("Beast", 10, 10, 100, 1, 10, 10, 1, 1);
public static Room cave_entry = new Room("Cave Entance","You are at the entrance to a cave.");
public static Room cave_tunnel_1 = new Room("Cave Tunnel","You are in an underground tunnel.");
public static Room cave_tunnel_2 = new Room("Cave Tunnel","You are in an underground tunnel.");
public static Room cave_tunnel_3 = new Room("Cave Tunnel","You are in an underground tunnel.");
public static Room cave_tunnel_4 = new Room("Cave Tunnel","You are in an underground tunnel.");
public static Room cave_deadend_1 = new Room("A Dead End","You are at a dead end in an underground tunnel.");
public static Room cave_deadend_2 = new Room("A Dead End","You are at a dead end in an underground tunnel.");
public static Item knife_1 = new Item("knife","It's a very rusty knife.");
public static void main(String[] args)
{
System.out.print("Enter Your Name: ");
String n = new Scanner(System.in).nextLine();
player.set_name(n);
knife_1.canPickup = true;
knife_1.setWepType(wep_type.DAGGER);
knife_1.setWepStr(wep_str.WEAK);
knife_1.calc_wepInfo();
cave_entry.exits.add(NORTH, cave_tunnel_1);
cave_entry.exits.add(SOUTH, null);
cave_entry.exits.add(WEST, null);
cave_entry.exits.add(EAST, null);
cave_entry.items.add(knife_1);
player.current[0] = cave_entry;
cave_tunnel_1.exits.add(NORTH, cave_tunnel_2);
cave_tunnel_1.exits.add(SOUTH, cave_entry);
cave_tunnel_1.exits.add(WEST, null);
cave_tunnel_1.exits.add(EAST, null);
cave_tunnel_2.exits.add(NORTH, null);
cave_tunnel_2.exits.add(SOUTH, cave_tunnel_1);
cave_tunnel_2.exits.add(WEST, cave_tunnel_3);
cave_tunnel_2.exits.add(EAST, cave_tunnel_4);
cave_tunnel_3.exits.add(NORTH, null);
cave_tunnel_3.exits.add(SOUTH, null);
cave_tunnel_3.exits.add(WEST, cave_deadend_1);
cave_tunnel_3.exits.add(EAST, cave_tunnel_2);
cave_tunnel_4.exits.add(NORTH, null);
cave_tunnel_4.exits.add(SOUTH, null);
cave_tunnel_4.exits.add(WEST, cave_tunnel_2);
cave_tunnel_4.exits.add(EAST, cave_deadend_2);
cave_deadend_1.exits.add(NORTH, null);
cave_deadend_1.exits.add(SOUTH, null);
cave_deadend_1.exits.add(WEST, null);
cave_deadend_1.exits.add(EAST, cave_tunnel_3);
cave_deadend_2.exits.add(NORTH, null);
cave_deadend_2.exits.add(SOUTH, null);
cave_deadend_2.exits.add(WEST, cave_tunnel_4);
cave_deadend_2.exits.add(EAST, null);
cave_deadend_2.monsters.add(Monster_1);
look();
while(true)
{
String input = new Scanner(System.in).nextLine();
parseIn(input);
}
}
public static ArrayList
str_div(String input, char divide)
{
ArrayList Words = new ArrayList();
String temp = "";
int tmp = 0;
for(int i = 0; i < input.length(); i++)
{
if(input.charAt(i)!=divide)
{
temp += input.charAt(i);
}
else
{
tmp=i;
Words.add(temp);
temp = "";
}
}
if(tmp!=0)
{
Words.add(input.substring(tmp + 1, input.length()));
}
else
{
Words.add(input.substring(tmp, input.length()));
}
return Words;
}
public static boolean move(int direction)
{
switch(direction)
{
case NORTH:
{
if(player.current[0].exits.get(NORTH) != null)
{
player.current[0] = player.current[0].exits.get(NORTH);
look();
return true;
}
else
{
return false;
}
}
case SOUTH:
{
if(player.current[0].exits.get(SOUTH) != null)
{
player.current[0] = player.current[0].exits.get(SOUTH);
look();
return true;
}
else
{
return false;
}
}
case WEST:
{
if(player.current[0].exits.get(WEST) != null)
{
player.current[0] = player.current[0].exits.get(WEST);
look();
return true;
}
else
{
return false;
}
}
case EAST:
{
if(player.current[0].exits.get(EAST) != null)
{
player.current[0] = player.current[0].exits.get(EAST);
look();
return true;
}
else
{
return false;
}
}
default:
{
return false;
}
}
}
public static void look()
{
System.out.println(player.current[0].name);
System.out.println(player.current[0].description);
String exits = "";
switch(player.current[0].calc_numExits())
{
case 1:
{
exits = "You can go to the ";
if( player.current[0].exits.get(NORTH) != null)
{
exits+="north.";
}
else if( player.current[0].exits.get(SOUTH) != null)
{
exits+="south.";
}
else if( player.current[0].exits.get(EAST) != null)
{
exits+="east.";
}
else if( player.current[0].exits.get(WEST) != null)
{
exits+="west.";
}
break;
}
case 2:
{
exits = "You can go to the ";
if( player.current[0].exits.get(NORTH) != null)
{
exits+="north and ";
if( player.current[0].exits.get(SOUTH) != null)
{
exits+="south.";
}
else if( player.current[0].exits.get(EAST) != null)
{
exits+="east.";
}
else if( player.current[0].exits.get(WEST) != null)
{
exits+="west.";
}
}
else if( player.current[0].exits.get(SOUTH) != null)
{
exits+="south and ";
if( player.current[0].exits.get(EAST) != null)
{
exits+="east.";
}
else if( player.current[0].exits.get(WEST) != null)
{
exits+="west.";
}
}
else if( player.current[0].exits.get(EAST) != null)
{
exits+="east and west.";
}
break;
}
case 3:
{
exits = "You can go to the ";
if( player.current[0].exits.get(NORTH) != null)
{
exits+="north, ";
if( player.current[0].exits.get(SOUTH) != null)
{
exits+="south, and ";
if( player.current[0].exits.get(EAST) != null)
{
exits+="east.";
}
else if( player.current[0].exits.get(WEST) != null)
{
exits+="west.";
}
}
else if( player.current[0].exits.get(EAST) != null)
{
exits+="east, and west";
}
}
else if( player.current[0].exits.get(SOUTH) != null)
{
exits+="south, east, and west.";
}
break;
}
case 4:
{
exits = "You can go to the north, south, east, and west.";
break;
}
}
System.out.println(exits);
String curitem = "You see ";
if(player.current[0].items.size()>1)
{
for(int i = 0; i < player.current[0].items.size()-1; i++)
{
curitem += "a " + player.current[0].items.get(i).name + ", ";
}
curitem += "and a " + player.current[0].items.get(player.current[0].items.size()-1).name + " here.";
}
else if(player.current[0].items.size()==1)
{
curitem += "a " + player.current[0].items.get(0).name + " here.";
}
else
{
curitem = "There are no items here.";
}
System.out.println(curitem);
String curmon = "You see ";
if(player.current[0].monsters.size()>1)
{
for(int i = 0; i < player.current[0].monsters.size()-1; i++)
{
curmon += "a " + player.current[0].monsters.get(i).get_name() + ", ";
}
curmon += "and a " + player.current[0].monsters.get(player.current[0].monsters.size()-1).get_name() + " here.";
System.out.println(curmon);
}
else if(player.current[0].monsters.size()==1)
{
curmon += "a " + player.current[0].monsters.get(0).get_name() + " here.";
System.out.println(curmon);
}
}
public static void lookAt(String itemName)
{
int itemIndex = 0;
boolean hasItem = false;
for(int i = 0; i < player.current[0].items.size(); i++)
{
if(player.current[0].items.get(i).name.equals(itemName))
{
itemIndex = i;
hasItem = true;
break;
}
}
if(hasItem==false)
{
for(int i = 0; i < player.bag.item.size(); i++)
{
if(player.bag.item.get(i).name.equals(itemName))
{
itemIndex = i;
break;
}
}
if(hasItem==false)
{
System.out.println("You cannot look at a nonexistant item.");
}
else
{
System.out.println(player.current[0].items.get(itemIndex).description);
}
}
else
{
System.out.println(player.current[0].items.get(itemIndex).description);
}
}
public static void parseIn(String input)
{
ArrayList parseMe = str_div(input, ' ');
if(parseMe.get(0).equalsIgnoreCase("GO"))
{
if(parseMe.size()>1)
{
if(parseMe.get(1).equalsIgnoreCase("NORTH") || parseMe.get(1).equalsIgnoreCase("N"))
{
if(!move(NORTH))
{
System.out.println("You cannot go north.");
}
}
else if(parseMe.get(1).equalsIgnoreCase("SOUTH") || parseMe.get(1).equalsIgnoreCase("S"))
{
if(!move(SOUTH))
{
System.out.println("You cannot go south.");
}
}
else if(parseMe.get(1).equalsIgnoreCase("EAST") || parseMe.get(1).equalsIgnoreCase("E"))
{
if(!move(EAST))
{
System.out.println("You cannot go east.");
}
}
else if(parseMe.get(1).equalsIgnoreCase("WEST") || parseMe.get(1).equalsIgnoreCase("W"))
{
if(!move(WEST))
{
System.out.println("You cannot go west.");
}
}
}
else
{
System.out.println("I don't know which direction you would like to go in.\nI don't read minds you know.");
}
}
else if(parseMe.get(0).equalsIgnoreCase("LOOK"))
{
if(parseMe.size()>1)
{
if(parseMe.get(1).equalsIgnoreCase("AT"))
{
if(parseMe.size()>2)
{
lookAt(parseMe.get(2));
}
else
{
System.out.println("I don't have any idea of what you would like to look at.\nI don't read minds you know.");
}
}
else
{
System.out.println("I do not understand your gibberish.");
}
}
else
{
look();
}
}
else if(parseMe.get(0).equalsIgnoreCase("INVENTORY") || parseMe.get(0).equalsIgnoreCase("INV"))
{
player.bag.space_left();
if(player.bag.isEmpty())
{
System.out.println("Your inventory is empty.");
System.out.println("You have " + player.bag.space_left() + " spaces left");
}
else
{
for(int i = 0; i < player.bag.item.size(); i++)
{
System.out.println(player.bag.item.get(i).name);
}
System.out.println("You have " + player.bag.space_left() + " spaces left");
}
}
else if(parseMe.get(0).equalsIgnoreCase("TAKE"))
{
int itemIndex = 0;
boolean hasItem = false;
player.bag.space_left();
if(parseMe.size()>1)
{
for(int i = 0; i < player.current[0].items.size(); i++)
{
if(player.current[0].items.get(i).name.equalsIgnoreCase(parseMe.get(1)))
{
itemIndex = i;
hasItem = true;
break;
}
}
if(hasItem==false)
{
for(int i = 0; i < player.bag.item.size(); i++)
{
if(player.bag.item.get(i).name.equalsIgnoreCase(parseMe.get(1)))
{
itemIndex = i;
hasItem = true;
break;
}
}
if(hasItem==false)
{
System.out.println("You cannot take a nonexistant item.");
}
else
{
System.out.println("You already have the " + player.bag.item.get(itemIndex).name);
}
}
else
{
player.bag.add_item(player.current[0].items.get(itemIndex));
player.current[0].items.remove(itemIndex);
System.out.println("You took the " + parseMe.get(1));
}
}
else
{
System.out.println("I don't have any idea of what you would like to take.\nI don't read minds you know.");
}
}
else if(parseMe.get(0).equalsIgnoreCase("DROP"))
{
int itemIndex = 0;
boolean hasItem = false;
player.bag.space_left();
if(parseMe.size()>1)
{
for(int i = 0; i < player.bag.item.size(); i++)
{
if(player.bag.item.get(i).name.equals(parseMe.get(1)))
{
itemIndex = i;
hasItem = true;
break;
}
}
if(hasItem==false)
{
for(int i = 0; i < player.current[0].items.size(); i++)
{
if(player.current[0].items.get(i).name.equals(parseMe.get(1)))
{
itemIndex = i;
break;
}
}
if(hasItem==false)
{
System.out.println("You cannot drop a nonexistant item.");
}
else
{
System.out.println("You do not have the " + player.bag.item.get(itemIndex).name);
}
}
else
{
player.current[0].items.add(player.bag.item.get(itemIndex));
player.bag.remove_item(player.bag.item.get(itemIndex));
System.out.println("You dropped the " + parseMe.get(1));
}
}
else
{
System.out.println("I don't have any idea of what you would like to drop.\nI don't read minds you know.");
}
}
else if(parseMe.get(0).equalsIgnoreCase("FIGHT") || parseMe.get(0).equalsIgnoreCase("ATTACK"))
{
if(parseMe.size() > 1)
{
fight(parseMe.get(1));
}
else
{
System.out.println("What in the world did you want to attack.\nPlease be more specific next time.");
}
}
else if(parseMe.get(0).equalsIgnoreCase("HELP") || parseMe.get(0).equals("?"))
{
help();
}
else if(parseMe.get(0).equalsIgnoreCase("EXIT") || parseMe.get(0).equalsIgnoreCase("QUIT"))
{
System.out.println("Good Bye!");
System.exit(0);
}
else
{
System.out.println("I do not know the command " + parseMe.get(0) + ".");
}
}
public static void help()
{
ArrayList cmds = new ArrayList();
ArrayList cmds2 = new ArrayList();
cmds.add("go ");
cmds2.add("moves you in direction");
cmds.add("look");
cmds2.add("prints a description of where you are");
cmds.add("look at - ");
cmds2.add("prints a description of - ");
cmds.add("inventory");
cmds2.add("tells you what you are carrying");
cmds.add("take");
cmds2.add("takes an item from the room and adds it to your inventory");
cmds.add("drop");
cmds2.add("drops an item from your inventory in the room");
cmds.add("help");
cmds2.add("prints this list out");
cmds.add("exit");
cmds2.add("leaves the game");
cmds.add("quit");
cmds2.add("same as exit");
for(int i = 0; i < cmds.size(); i++)
{
System.out.println(cmds.get(i));
System.out.println(cmds2.get(i) + ".\n");
}
}
public static void fight(String monster)
{
rpg_char[] Monster = new rpg_char[1];
boolean found = false;
int monsterIndex = 0;
for(int i = 0; i < player.current[0].monsters.size(); i++)
{
if(player.current[0].monsters.get(i).get_name().equalsIgnoreCase(monster))
{
Monster[0] = player.current[0].monsters.get(i);
found = true;
monsterIndex = i;
break;
}
}
if(found == false)
{
System.out.println("The monster " + monster + " could not be found.");
return;
}
while(Monster[0].getHealth()>0 && player.getHealth()>0)
{
System.out.println(Monster[0].get_name() + " lvl: " + Monster[0].getLevel() + "\n Att: " + Monster[0].getAtt() + " Def: " + Monster[0].getDef() + " Health: " + Monster[0].getHealth());
System.out.println(player.get_name() + " lvl: " + player.getLevel() + "\n Att: " + player.getAtt() + " Def: " + player.getDef() + " Health: " + player.getHealth());
System.out.println("You can attack or run.");
String input = new Scanner(System.in).nextLine();
int intdata = parseIn_F(input);
if(intdata == 0)
{
int val1 = (int)(player.getAtt()*(Math.random()*3));
int val2 = (int)(Monster[0].getAtt()*(Math.random()*3));
val1 -= Monster[0].getDef();
val2 -= player.getDef();
if(val1 < 0) {val1 = 0;}
if(val2 < 0) {val2 = 0;}
player.set_health((player.getHealth() - val2));
Monster[0].set_health((Monster[0].getHealth() - val1));
}
else if(intdata == 1)
{
break;
}
else
{
System.out.println("Invalid Input");
}
System.out.println();
}
if(player.getHealth() > 0 && Monster[0].getHealth() > 0)
{
System.out.println("You run away.");
}
else if(player.getHealth() > 0)
{
System.out.println("You beat the " + Monster[0].get_name());
//player.current[0].monsters.remove(monsterIndex);
player.current[0].monsters.get(monsterIndex).set_health(player.current[0].monsters.get(monsterIndex).getMaxHealth());
look();
player.update_E(Monster[0].getExp());
player.update_M(Monster[0].getMoney());
}
else
{
System.out.println("You got beaten by the " + Monster[0].get_name() + ".\nYou awaken outside the cave.");
player.current[0] = cave_entry;
player.set_health(player.getMaxHealth());
look();
Monster[0].update_E(player.getExp());
Monster[0].update_M(player.getMoney());
}
}
public static int parseIn_F(String input)
{
ArrayList parseMe = str_div(input, ' ');
if(parseMe.get(0).equalsIgnoreCase("fight") || parseMe.get(0).equalsIgnoreCase("attack"))
{
return 0;
}
else if(parseMe.get(0).equalsIgnoreCase("run"))
{
return 1;
}
else
{
return 2;
}
}
}