Wednesday, September 30, 2009

Home made speaker casing made with lego....





These are the pictures of the speaker case that I made for speaker my uncle was throwing away. I was going to make a dock for 3.5mm jack but ran out of blocks.
PROCEDURE that I FOLLOWED
1.Try to unscrew the speakers and safely conserve the circuit.
2.To closely remodel the plastic I used heated knife.
3. Try to make a strong case for the speakers using lego in preferable shape you want.
4. While making case keep in mind the dimensions of the speaker so that they fit in.
5.I made base broader then the top so that the speakers stay intact.
6. I implanted 2 speakers in 1

rpg_char.java

public class rpg_char
{
private String name = "Default";
private int money = 0;
private int health = 10;
private int maxhealth = 10;
private int exp = 0;
private int nextlevel = 10;
private int level = 1;
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
private int defence = 0;
private int attack = 0;

public rpg_char(String name2, int money2, int exp2, int nextlevel2, int level, int health2, int maxhealth2, int defence2, int attack2)
{
name = name2;
money = money2;
exp = exp2;
nextlevel = nextlevel2;
health = health2;
maxhealth = maxhealth2;
defence = defence2;
attack = attack2;
}
public void set_name(String newname) { name = newname; }
public void set_health(int s_health) { health = s_health; }
public void set_maxhealth(int s_maxhealth) { maxhealth = s_maxhealth; }
public void set_exp(int s_exp) { exp = s_exp; }
public void set_nextlevel(int s_nxtlvl) { nextlevel = s_nxtlvl; }
public void set_money(int s_money) { money = s_money; }
public void set_att(int s_att) { attack = s_att; }
public void set_def(int s_def) { defence = s_def; }
public void update_H(int newMax, int regen_percent)
{
int regen_amount = maxhealth*(regen_percent/100);
maxhealth = newMax;
if( (health + regen_amount) < maxhealth)
{
health += regen_amount;
}
else
{
health = maxhealth;
}
}
public void update_E(int addExp)
{
if( (exp + addExp) < nextlevel)
{
exp += addExp;
}
else
{
addExp = (exp+addExp) - nextlevel;
levelup(addExp);
}
}
public void update_M(int addMoney)
{
money += addMoney;
}
public void update_A(int addAtt)
{
attack += addAtt;
}
public void update_D(int addDef)
{
defence += addDef;
}
public void levelup(int expleft)
{
int statsup1 = (int)(Math.random()*3);
int statsup2 = (int)(Math.random()*3);
if(statsup1 == 3)statsup1 = (int)(Math.random()*3);
if(statsup2 == 3)statsup2 = (int)(Math.random()*3);
attack += statsup1;
defence += statsup2;
update_H( (maxhealth + statsup1), (int)(Math.random()*maxhealth) );
nextlevel += (int)(Math.random()*nextlevel);
update_E(expleft);
}
public String get_name() {return name;}
public int getMoney() {return money;}
public int getHealth() {return health;}
public int getMaxHealth() {return maxhealth;}
public int getExp() {return exp;}
public int getNextLevel() {return nextlevel;}
public int getDef() {return defence;}
public int getAtt() {return attack;}
}

Room.java

import java.util.ArrayList;
public class Room
{
public String name;
public String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ArrayList items = new ArrayList();
public ArrayList exits = new ArrayList();
public ArrayList monsters = new ArrayList();
public Room(String n, String d)
{
name = n;
description = d;
}
public int calc_numExits()
{
int out = 0;
for(int i = 0; i < exits.size(); i++)
{
if(exits.get(i)!=null)
{
out++;
}
}
return out;
}
}

Main_char.java

class Main_char extends rpg_char
{
public Main_char(String name2, int money2, int exp2, int nextlevel2, int level, int health2, int maxhealth2, int defence2, int attack2, Room start)
{
super(name2, money2, exp2, nextlevel2, level, health2, maxhealth2, defence2, attack2);
current[0] = start;
}
public Inventory bag = new Inventory(10);
public Hand Right;
public Hand Left;
public Room[] current = new Room[1];
}

Item.java

import java.util.ArrayList;
enum type {KEY, ARMOR, WEAPON, POTION}
enum armor_type {RING, NECKLACE, MEDDALION, AMULET, GLOVES, LEGGINGS, BODYARMOR}
enum armor_str {NULL, WEAK, OK, DECENT, MEDIUM, GOOD, STRONG}
enum wep_type {DAGGER, CLUB, SWORD, AXE, WARHAMMER, BATTLEAXE}
enum wep_str {NULL, WEAK, OK, DECENT, MEDIUM, GOOD, STRONG}
enum potion_type {NULL, ACID, POISON, HEALTH}
enum potion_str {NULL, WEAK, MEDIUM, STRONG}
enum key_doors {}
public class Item
{

public Item(String n, String d)
{
types.add("key");
types.add("armor");
types.add("weapon");
types.add("potion");
armor_types.add("ring");
armor_types.add("necklace");
armor_types.add("maddalion");
armor_types.add("amulet");
armor_types.add("leggings");
armor_types.add("body armor");
armor_strs.add("zero");
armor_strs.add("weak");
armor_strs.add("ok");
armor_strs.add("decent");
armor_strs.add("medium");
armor_strs.add("good");
armor_strs.add("strong");
weapon_types.add("dagger");
weapon_types.add("club");
weapon_types.add("sword");
weapon_types.add("axe");
weapon_types.add("war hammer");
weapon_types.add("battle axe");
weapon_strs.add("zero");
weapon_strs.add("weak");
weapon_strs.add("ok");
weapon_strs.add("decent");
weapon_strs.add("medium");
weapon_strs.add("good");
weapon_strs.add("strong");
potion_types.add("empty");
potion_types.add("acid");
potion_types.add("poison");
potion_types.add("health");
potion_strs.add("zero");
potion_strs.add("weak");
potion_strs.add("medium");
potion_strs.add("strong");
name = n;
description = d;
}


public type getItemType() {
return itemType;
}


public void setItemType(type itemType) {
this.itemType = itemType;
}


public armor_type getArmorType() {
return armorType;
}


public void setArmorType(armor_type armorType) {
this.armorType = armorType;
}


public armor_str getArmorStr() {
return armorStr;
}


public void setArmorStr(armor_str armorStr) {
this.armorStr = armorStr;
}


public wep_type getWepType() {
return wepType;
}


public void setWepType(wep_type wepType) {
this.wepType = wepType;
}


public wep_str getWepStr() {
return wepStr;
}


public void setWepStr(wep_str wepStr) {
this.wepStr = wepStr;
}


public String getName() {
return name;
}


public String name = "";
public String description = "There is nothing special about this item.";
private type itemType;
private armor_type armorType;
private armor_str armorStr;
private wep_type wepType;
private potion_type potionType;
private potion_str potionStr;
private key_doors location;
private wep_str wepStr;
private int wepDam;
private int armorProtec;
private int potionPow;
public ArrayList types = new ArrayList();
public ArrayList armor_types = new ArrayList();
public ArrayList armor_strs = new ArrayList();
public ArrayList weapon_types = new ArrayList();
public ArrayList weapon_strs = new ArrayList();
public ArrayList potion_types = new ArrayList();
public ArrayList potion_strs = new ArrayList();
public ArrayList doors = new ArrayList();
public boolean canPickup = true;
public ArrayList get_type()
{
ArrayList outTypeInfo = new ArrayList();
outTypeInfo.add(itemType);
switch(itemType)
{
case KEY:
{
outTypeInfo.add(location);
}
case ARMOR:
{
outTypeInfo.add(armorType);
}
case WEAPON:
{
outTypeInfo.add(wepType);
}
case POTION:
{
outTypeInfo.add(potionType);
}
}
return outTypeInfo;
}
public void calc_wepInfo()
{
switch(wepType)
{
case DAGGER:
{
int start = 1;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(wepStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
wepDam = start - variation;
}
case CLUB:
{
int start = 2;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(wepStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
wepDam = start - variation;
}
case SWORD:
{
int start = 4;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(wepStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
wepDam = start - variation;
}
case AXE:
{
int start = 3;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(wepStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
wepDam = start - variation;
}
case WARHAMMER:
{
int start = 5;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(wepStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
wepDam = start - variation;
}
case BATTLEAXE:
{
int start = 5;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(wepStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
wepDam = start - variation;
}
}
if(wepDam < 0)
{
wepDam = 0;
}
}
public void calc_armorInfo()
{
switch(armorType)
{
case RING:
{
int start = 1;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(armorStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
armorProtec = start - variation;
}
case NECKLACE:
{
int start = 2;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(armorStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
armorProtec = start - variation;
}
case MEDDALION:
{
int start = 2;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(armorStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
armorProtec = start - variation;
}
case AMULET:
{
int start = 2;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(armorStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
armorProtec = start - variation;
}
case GLOVES:
{
int start = 3;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(armorStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
armorProtec = start - variation;
}
case LEGGINGS:
{
int start = 4;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(armorStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
armorProtec = start - variation;
}
case BODYARMOR:
{
int start = 5;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*7)) + (Math.random()*(start*7)) )/2) - (int)(Math.random()*3) );
switch(armorStr)
{
case NULL:
{
start *= 0;
}
case WEAK:
{
start *= 1;
}
case OK:
{
start *= 2;
}
case DECENT:
{
start *= 3;
}
case MEDIUM:
{
start *= 4;
}
case GOOD:
{
start *= 5;
}
case STRONG:
{
start *= 6;
}
}
armorProtec = start - variation;
}
}
if(armorProtec < 0)
{
armorProtec = 0;
}
}
public void calc_potionInfo()
{
switch(potionType)
{
case NULL:
{
potionPow = 0;
}
case ACID:
{
int start = 3;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*5)) + (Math.random()*(start*5)) )/2) - (int)(Math.random()*3) );
switch(potionStr)
{
case NULL:
{
potionPow = 0;
}
case WEAK:
{
start*=2;
}
case MEDIUM:
{
start*=5;
}
case STRONG:
{
start*=10;
}
}
potionPow = start - variation;
}
case POISON:
{
int start = 3;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*5)) + (Math.random()*(start*5)) )/2) - (int)(Math.random()*3) );
switch(potionStr)
{
case NULL:
{
potionPow = 0;
}
case WEAK:
{
start*=2;
}
case MEDIUM:
{
start*=5;
}
case STRONG:
{
start*=10;
}
}
potionPow = start - variation;
}
case HEALTH:
{
int start = 1;
int variation = 0;
variation = (int) ( (( (Math.random()*(start*5)) + (Math.random()*(start*5)) )/2) - (int)(Math.random()*3) );
switch(potionStr)
{
case NULL:
{
potionPow = 0;
}
case WEAK:
{
start*=2;
}
case MEDIUM:
{
start*=5;
}
case STRONG:
{
start*=10;
}
}
potionPow = start - variation;
}
}
}
}

Inventory.java

import java.util.ArrayList;
public class Inventory
{
private int size = 10;
private boolean full = false;
private boolean empty = true;
public ArrayList item = new ArrayList();

public Inventory(int s) {size = s;}
public boolean isfull() {space_left(); return full;}
public boolean isEmpty() {space_left(); return empty;}
public int num_held() {return item.size();}
public int max_held() {return size;}
public int space_left()
{
int room = size - item.size();
if(room==0){full = true;}else if(room==size){empty = true;}
return room;
}
public boolean add_item(Item a)
{
if(full){return false;}
//else if(item.size()==size){return false;}
else
{
item.add(a);
space_left();
return true;
}
}
public boolean remove_item(Item a)
{
if(item.size()==0){return false;}
item.remove(a);
space_left();
return true;
}
}

hand.java

public class Hand {
public Item Thumb;
public Item Index;
public Item Middle;
public Item Ring;
public Item Little;
public Item Whole;
boolean both;
}

My main class of Adventure game

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