Welcome to Dream.In.Code
Getting Help is Easy!

Join 95,475 Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 966 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert

Register to Make This Box Go Away!


JAVA: text based rpg created...

 
Reply to this topicStart new topic

JAVA: text based rpg created..., tell me what I did right and wrong.. :)

crazyskateface
post 7 May, 2008 - 08:49 PM
Post #1


New D.I.C Head

*
Joined: 5 Feb, 2008
Posts: 9


My Contributions


This isn't homework its just what I wanted to do to start out programming in games and what not.

I created this text based RPG type game and it seems to work fairly well, I was in the middle of testing other things so it might have some holes I didn't patch up yet and its taken me around 2 weeks to write between college, girlfriend, and everything. Still not done tho

but what I wanna know or be shown is what I can do to better my code and/or other ways of coding that might work better than what I've got here...

I'll post the Main code because its really all the complexity that I've written the other classes I'll just link because they just have constructors, getters,and setters and so on.

Basically what the game is, is a menu and you press 1 through whatever and it either fights or goes into other menus(while loops) for the shop, inventory, and the inn. all seem to work pretty well and also it doesn't have that great of a story line...i was just trying to get the basics down...

lemme know whatcha think!?

CODE

import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
public class Main {

    /**
     * @param args
     */
    
    private static Scanner key = new Scanner(System.in);
    private static Random rand = new Random();
    private static int monster;
    private static String Owned[] ={"Worm","Rat","Weasle with Sword!","Skeleton","Ghoul","Goblin","Ghost","Mummy","Dark Soldier","Floating Sword","Poison Flower","Giant Deadly Basilisk","Hunter","Magician","Wizard","Nightstalker","SabreTooth","Samurai","Ninja","Warlord",
        "Jokester","Ultros","DoomLord","DoomGuard","Zombie","BrainEater","Naga","Demon posessed Dog","VoidWalker","Large Ogre","Welpling","Fire DragonKin","DragonKid","Scrunt","Green Imp","FelHunter","Blood Elf","Battle Orc","Black Troll","CutPurse","Bandit","Tauren","T-rex",
        "Raptor","SeaMan","Pirate Floor Scrubber","Pirate","Pirate Captain","Mutated Pirate Monster!","Crocodile","Pikachu!","Charizard: The fire dragon","Ho-oh","Mewtwo","Link","Zelda","Darkling","Marlboro","Death Adder","Ramuh","Ifrit","Shiva","Fenrir","Alexander","Cecil",
        "Terra","Sabin","Locke","Edgar","Shadow","Kefka","Cloud","Sephiroth","Squall","Seifer","Zidane","Vivi","Tidus","Phil of the future","Dragon King of the Underworld"};
    

    
    
    private static int[] exp = new int[100];
    private static int expnum = 102;
    
    private static int weapnum;
    private static int win, gold,shopnumber, num;
    private static String pause;
    
    
    //items (parallel arrays)
    private static ArrayList<item> Items = new ArrayList<item>();
    private static ArrayList<item> Inventory = new ArrayList<item>();                                                                          
    
    private static String shop[] ={"Potion","ether","Elixer","stick","bat","antidote","eyedrop","rusty sword",
        "remedy","long sword",    "Tent","glowing magic sword","fire sword","scimitar","prince's rapier",
        "Knights goliath royal buster blade","Dark Sabre","Omega Weapon","Blacksmith's legendary ancient war sword",
        "Ultima Sword","Sword of beasts","Holy Light Sword","??????????"};
    
    private static String descrip[]={"Heal life by ","Regenerate mana by ", "Heal life and mana by ","Level 1 wep",
        "Level 2 wep","Heal Poison status"," Heal blind status","Level 3 wep","Heal all imperfections","Level 4 wep",
        "Stay the night outside and Heal all","Level 5 wep","Level 6 wep","Level 7 wep","Level 8 wep","Level 9 wep",
        "Level 10 wep","Level 11 wep","Level 12 wep","Level 13 wep","Level 14 wep","Level 15 wep","??????????" };
    
    private static int amount[] ={100, 50, 500, 10, 20, 0, 0,30,0,40, 100, 50, 60,70,80,90,100,110,120,130,140,1500,150000};
    private static int prices[]= {100,50,500,10,200,50,90,300,500,900,1000,5000,6000,7000,8000,9000,10000,11000,1
2500,13000,14000,150000,1};
    private static boolean use_able[] = {true,true,true,false,false,true,true,false,true,false,true,false,false,false,fa
lse,false,false,false,false,false,false,false,true};
    
    private static int shopnum[]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
    
    private static int j =90;
    
    //character
    private static Player dude = new Player(null, 1, 107, 59, 5, 0, 1000000);
    
    
    
    public static void main(String[] args) {
        
        
        //create items
        
        for(int i=0; i<shop.length;i++){
            item newitem = new item(shop[i],descrip[i],amount[i],prices[i],use_able[i]);
            Items.add(newitem);
            
        }
        /**
         * all items
         *
         *
        System.out.println("All items in game for now:");
        Iterator<item> it = Items.iterator ();
          while (it.hasNext ()) {
            Object o = it.next ();
            System.out.println(o);
          }
        **/
        
        //exp
        for(int i=0;i<100;i++){
            exp[i] = expnum*i;
        }
        
        
        
    
        
        
            
        //String name = JOptionPane.showInputDialog("What's your name?");
        System.out.println("Whats your name?");
        String name =key.next();
        System.out.println("Crazy Game of Death (Title Menu)\n if you want to load a game enter ::yes:: if you want to \n create a new game enter ::no::, else closes.");
        String answer = key.next();
        if(answer == "yes"){
            
        }
        else if(answer == "no");
        
        
        
        
        //start
        
        
        
        System.out.println("Welcome young adventurer, your quest to become a great warrior begins now! WAKE UP!");
        
        System.out.println("You wake up and find everyone gone, and a crashing noise outside,");
        
        
        
        dude.setName(name);
        dude.SetMaxStats();
        
        
        System.out.println("Hey " + dude.getName() + "  lets get ready for some fighting! Now you need a weapon.. oh wait i got one for ya, use this...");
        
        System.out.println("Received new weapon:  / " + shop[3]);
        Inventory.add(Items.get(3));
        equip(Items.get(3));
        
        
        
        do{
            if(j==90){
        story(dude);
        
        
        if(j==1){    
            
            
           fight();
            
            
            
        }
        if(j==2){
            shop();
            
        }
        if(j==3){
            Inventory();
            
        }
        if(j==4){
            Inn();
            
        }
        
            }
        }while(!(j==0));
        
        
        
        
        
        
        
        
        //end of code
        
        }//end main
    
    
    
    
    public static void story(Player dude){
        
        if(dude.getLevel() < 2){
            System.out.println(dude.toString());    
            System.out.println("\n You are a level "+ dude.getLevel() + " warrior. What would you like to do?");
            System.out.println("1) Fight! \n2) Shop \n3) Inventory \n4) Inn");
            j= key.nextInt();
        }
        if(dude.getLevel()>1 && dude.getLevel() <=9 || dude.getLevel()>10){
            System.out.println(dude.toString());
            System.out.println("Dude you're makin it in the village...keep it up!");
            System.out.println("1) Fight! \n2) Shop \n3) Inventory \n4) Inn");
            j= key.nextInt();
        }
        if(dude.getLevel()==10){
            System.out.println(dude.toString());
            System.out.println("You're a fierce warrior..but many battles await.." +
                    "" +
                    "\nYou go to the Inn to rest, but right before you get all cozy the Innkeeper comes upstairs with grave news" +
                    "\nInnkeeper:OH its HORRIBLE! A Giant Deadly Basilisk has breached the village doors! Please help us!!");
            int nii = key.nextInt();
            fightboss();
            System.out.println("1) Fight! \n2) Shop \n3) Inventory \n4) Inn");
            j= key.nextInt();
        }
        else if(dude.getLevel() == 9){
            System.out.println("You suck..");
            j= key.nextInt();
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /**
     *
     *
     *
     * FIGHT
     *
     *
     *
     */
    public static void fight(){

        int a =0;
        int monlvl = rand.nextInt(10);
        monster = rand.nextInt((dude.getLevel() +1)+ monlvl);
        
        
        System.out.println("You've encountered a monster! ");
        int monsterlife=monster*monster*3+10;
        int monsterdmg=monster+(monster*monster);
        int monsterexp=(monster)*3+13;                                        
        int monstergold=(monster*100)+10;
        
        Monster mon = new Monster(Owned[monster],monster,monsterlife,monsterdmg,monsterexp,monstergold);
        System.out.println("It's a Level "+mon.getLevel()+" " + mon.getName()+"!");
        
        
        
        int count = 0;
        
        
        do{
            mon.toString();
            System.out.println(dude.toString());
            System.out.println("1)Attack \n2)Heal \n3)Run");
            a = key.nextInt();
            
            //Attack
            if(a ==1){
                
                
                int hit = rand.nextInt(20);
                if(hit > 2){
                    int dmgint = rand.nextInt(10);
                    int dmg = (dude.getstr()) + dmgint;
                    
                    System.out.println("You swing and strike " + mon.getName() + " for " + dmg + " damage!");
                    mon.hit(dmg);
                    if(mon.getlife()<= 0)
                        break;
                    
                }
                
                
                
                else if(hit > 17){
                    int dmgint = rand.nextInt(10);
                    int dmg = dude.getstr() + dmgint;
                    dmg = dmg *2;
                    
                    System.out.println("You swing and strike " + mon.getName() + " for " + dmg + " damage! \nCritical hit!!!");
                    mon.hit(dmg);
                    if(mon.getlife()<= 0)
                        break;
                    
                }
                
                
                else if(hit <=2)
                    System.out.println("You Miss! and faceplant into the ground...loser...");
                
                
                
                
                
                int monstermiss = rand.nextInt(10);
                int gethit = mon.getdamg();
                if(monstermiss > 5){
                    System.out.println(mon.getName() + " attacks you for " + gethit + "damage!");
                    int mondmgint = rand.nextInt(mon.getdamg());
                    dude.loseLife(mon.getdamg()+ mondmgint);
                    if(dude.getLife()<=0)
                        break;
                }
                else if(monstermiss <= 5){
                    System.out.println(mon.getName() + " swings at you with hatred and misses!");
                }
            }
            
            if(a==2){
                System.out.println("Bag: ");
                int i=0;
                Iterator<item> it = Inventory.iterator ();
                  while (it.hasNext ()) {
                    Object o = it.next ();
                     System.out.println(i+")"+o);
                     i++;
                  }
                  System.out.println("Type the number of the item to use");
                  int itemuse=key.nextInt();
                  use(itemuse);
            }
            
            
            
            if(a==3){
                System.out.println("You gain "+count+" xp for your "+count+" attacks");
                
                dude.gainexp(count);
                if(dude.getexp()>= (exp[dude.getLevel()])){
                    levelgain();
                
                mon.hit(mon.getlife());
                break;
                
            }
            
            
            }//end for loop for fight
        }while(true);
        
        System.out.println(mon.toString());
        //won the fight
        if(mon.getlife()<=0){
            System.out.println("Dude you won...congrats n' stuff! You gained " + mon.getexp() +"xp!");
            
            dude.gainexp(mon.getexp());
            
            
            //gain lvl
            if(dude.getexp()>= ((exp[dude.getLevel()])+9) ){
                levelgain();
            }
            else{
            ;
            }
            
            
            dude.obtaingold(mon.getgold());
            System.out.println("You received " + mon.getgold() + " gold!!!\n");
            int drop = rand.nextInt(10);
            if(drop <3){
                
                int dropnumber = key.nextInt(shop.length);
                System.out.println(mon.getName()+" dropped a "+
                    shop[dropnumber]+ ". "+shop[dropnumber]+ " was added to your [bag].");
                
                Inventory.add(Items.get(dropnumber));
            }
            else
                j=90;
        }
        else if(dude.getLife() <= 0){
            dude.setLife(0);
            System.out.println("Your Life has depleted.. you are.. \nAnnihilated...");dude.setLife(1);
            System.out.println("The townspeople have found you and healed your wounds, you now have " + dude.getLife() + " Life left ");
            int nni = key.nextInt();
            
        
        }
        else if(a==3){
            System.out.println("Sucessfully escaped!");
        }
        j=90;
    }
    
    
    
    /**
     *
     *
     *
     * BOSS FIGHT
     *
     *
     *
     */
    
    
    
    
    
    public static void fightboss(){
        int a =0;
        monster = 11;
        
        
        System.out.println("You've encountered a BOSS! ");
        int monsterlife=monster*dude.getLevel()*3+10+75;
        int mondmg = rand.nextInt(50);
        int monsterdmg=(dude.getLevel()+(dude.getLevel()*dude.getLevel())+mondmg);
        int monsterexp=(dude.getLevel())*30+13;                                        
        int monstergold=(monster*100)+10;
        
        Monster mon = new Monster(Owned[monster],monster,monsterlife,monsterdmg,monsterexp,monstergold);
        System.out.println("It's a Level "+mon.getLevel()+" " + mon.getName()+"!");
        
        
        
        int count = 0;
        
        
        do{
            mon.toString();
            System.out.println(dude.toString());
            System.out.println("1)Attack \n2)Heal \n3)item");
            a = key.nextInt();
            
            //Attack
            if(a ==1){
                
                
                int hit = rand.nextInt(20);
                if(hit > 2){
                    int dmgint = rand.nextInt(10);
                    int dmg = (dude.getstr()) + dmgint;
                    
                    System.out.println("You swing and strike " + mon.getName() + " for " + dmg + " damage!");
                    mon.hit(dmg);
                    if(mon.getlife()<= 0)
                        break;
                    
                }
                
                
                
                else if(hit > 17){
                    int dmgint = rand.nextInt(10);
                    int dmg = dude.getstr() + dmgint;
                    dmg = dmg *2;
                    
                    System.out.println("You swing and strike " + mon.getName() + " for " + dmg + " damage! \nCritical hit!!!");
                    mon.hit(dmg);
                    if(mon.getlife()<= 0)
                        break;
                    
                }
                
                
                else if(hit <=2)
                    System.out.println("You Miss! and faceplant into the ground...loser...");
                
                
                
                
                
                int monstermiss = rand.nextInt(10);
                int gethit = mon.getdamg();
                if(monstermiss > 4){
                    System.out.println(mon.getName() + " attacks you for " + gethit + "damage!");
                    int mondmgint = rand.nextInt(mon.getdamg());
                    dude.loseLife(mon.getdamg()+ mondmgint);
                    if(dude.getLife()<=0)
                        break;
                }
                else if(monstermiss <= 4){
                    System.out.println(mon.getName() + " swings at you with hatred and misses!");
                }
            }
            
            if(a==3){
                //use item
                
            }
            
            
            
        }while(true);
        
        System.out.println(mon.toString());
        //won the fight
        if(mon.getlife()<=0){
            System.out.println("Dude you won...congrats n' stuff! You gained " + mon.getexp() +"xp!");
            
            dude.gainexp(mon.getexp()*2);
            
            
            //gain lvl
            
            while(dude.getexp()>= ((exp[dude.getLevel()] ))){
                levelgain();
            }
            
            
            
            dude.obtaingold(mon.getgold());
            System.out.println("You received " + mon.getgold() + " gold!!!\n");
            int drop = rand.nextInt(10);
            if(drop <3){
                System.out.println(mon.getName()+" dropped a "+
                    shop[mon.getLevel()]+ ". "+shop[mon.getLevel()]+ " was added to your [bag].");
                
                Inventory.add(Items.get(mon.getLevel()));
            }
        }
        else if(dude.getLife() <= 0){
            dude.setLife(0);
            System.out.println("Your Life has depleted.. you are.. \nAnnihilated...");dude.setLife(1);
            System.out.println("The townspeople have found you and healed your wounds, you now have " + dude.getLife() + " Life left ");
            int nni = key.nextInt();
            
        }
        
        j=90;
    }
    
    /**
     *
     *
     *
     * SHOP
     *
     *
     *
     */
    

    
    public static void shop(){
        System.out.println("1)buy \n2)Sell");
        int buy = key.nextInt();
            
        if(buy==1){
        System.out.println("Welcome to the shop! We have quite a selection,\nchoose one, making you better feeling!\n Gold:" + dude.getgold() + "\n" +
                "0) " + shop[0] +"    $"+prices[0]+" \n1) " + shop[1] + "    $"+prices[1]+"\n2) " + shop[2] + "    $"+prices[2]+"\n3) " + shop[3] + "    $"+prices[3]);
        shopnumber= key.nextInt();
        if(dude.getgold() < prices[shopnumber]){
            System.out.println("You don't seem to have enough, come on back later buddy!");
        }
        else{
            System.out.println("How many ya need Partner?");
            int num = key.nextInt();
            for(int i=0;i<num;i++){
                dude.buyitem(prices[shopnumber]);
                Inventory.add(Items.get(shopnumber));
            }
            
        
        System.out.println("Added "+num+" " + shop[shopnumber] + " to your (Bag)!");
        }
        j=90;
        }
        
        
        //sell
        if(buy ==2){
            while(true){
            System.out.println("Enter the number of the item to sell");
            System.out.println("Bag: ");
            Iterator<item> it = Inventory.iterator ();
            int i =0;
              while (it.hasNext ()) {
                Object o = it.next ();
                 System.out.println(i +")" +o);
                 i++;
              }
              int sell = key.nextInt();
              if(sell > Inventory.size()){
                  System.out.println("dude you dont have that many items you douche ");
              }
              else if(sell <= Inventory.size()){
              int sellvalue = ((-1)*prices[sell])/2;
              dude.buyitem(sellvalue);
              System.out.println("Sold "+ Inventory.get(sell).getname() + " for $" + sellvalue);
              Inventory.remove(sell);
              break;
              }
            }
        j=90;
        }
    }
    
    
    /**
     *
     *
     *
     * INVENTORY
     *
     *
     *
     */
    
    
    
    
    public static void Inventory(){
        System.out.println("Bag: ");
        int i=0;
        Iterator<item> it = Inventory.iterator ();
          while (it.hasNext ()) {
            Object o = it.next ();
             System.out.println(i+")"+o);
             i++;
          }
          System.out.println("1)use 2)equip \n     3)Back");
          int useitem = key.nextInt();
          if(useitem ==1){
              System.out.println("Type the number of the item to use");
              int itemuse=key.nextInt();
              use(itemuse);
          }
          else if(useitem ==2){
              System.out.println("Which item will you equip?");
              int itemequip = key.nextInt();
              equip(Inventory.get(itemequip));
          }
          else
             ;
          
          
          
          
          
          
          System.out.println();
          System.out.println("enter 1 to cont.");
          String iin= key.next();
          j=90;
    }
    
    
    
    /**
     *
     *
     *
     * INN
     *
     *
     *
     */
    
    
    
    
    public static void Inn(){
        int inngold = (dude.getexp()*3)+ 7;
        System.out.println("Welcome to the Inn.. it's " + inngold + " gold for one night.");
        System.out.println("Stay?\n     y or n ?");
        char stay = key.next().charAt(0);
        if(stay == 'y' || stay == 'Y'){


--------------------
JAVA == AWESOMENESS :)
User is offlineProfile CardPM

Go to the top of the page


Martyr2
post 7 May, 2008 - 09:54 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 3,826



Thanked 25 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Well my first recommendation would be to try and get whatever variables you can out of being static in main that doesn't need to be there. The idea of main in a game is essentially an index of a book. It should contain the main game loop and should only be calling functions for the most part. Call a function like initializegame() to setup your money or experience or character stats and perhaps a function like initializeItems() which sets up your arrays and builds your Item instances. Things you might want to consider moving to a more local scope are variables like "expnum, gold, weaponnum, j, shopnumber, num etc.... new class called character perhaps?)

My second recommendation would be to do something with...

java

if(answer == "yes"){

}
else if(answer == "no");


Obviously it isn't doing anything (I assume you haven't finished it yet).

Third recommendation would be to use a switch statement for....

java

if(j==90){
story(dude);


if(j==1){


fight();



}
if(j==2){
shop();

}
if(j==3){
Inventory();

}
if(j==4){
Inn();

}

}


If you find yourself making multiple if statements and testing the same variable for multiple values, it is a classic red flag you might want to use a switch. Also make sure you change the value of j every time or you could end up in an infinite while loop.

Another recommendation I always suggest to people is use parenthesis when doing calculations. Never rely on the compiler to do the order of operations, put them in for yourself, the compiler and future programmers who may see the code. It is a great habit and it will prevent you from making silly errors in calculations just because you didn't take into account how it might be evaluated. Force the evaluation order using the parenthesis.

You are going to have a problem here....

java

if(hit > 2){
int dmgint = rand.nextInt(10);
int dmg = (dude.getstr()) + dmgint;

System.out.println("You swing and strike " + mon.getName() + " for " + dmg + " damage!");
mon.hit(dmg);
if(mon.getlife()<= 0)
break;

}

else if(hit > 17){
int dmgint = rand.nextInt(10);
int dmg = dude.getstr() + dmgint;
dmg = dmg *2;



You will never reach the else if hit > 17 because if it is greater than 17 it also means it is greater than 2 so it will always trigger the first if, never the else if (hit > 17). You can correct this by switching the tests around and test if it is greater than 17 first, then test if it is greater than 2 and then test if it is less than or equal to 2.

I see a lot of this is not finished. I would suggest filling more of it out and then coming back and I am sure we can tell you more on how to optimize it.

Good luck! smile.gif


--------------------
IPB Image
App Developer | "I was put on this planet to code" | My Blog
User is offlineProfile CardPM

Go to the top of the page

baavgai
post 8 May, 2008 - 08:49 AM
Post #3


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,283



Thanked 26 times

Dream Kudos: 300

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


"//items (parallel arrays)"

Parallel arrays are on par with goto when it comes to programming evil. I see you start loading them into an "item" class, but I don't see it defined. Avoid the arrays, load it up directly. Also, style advice, always makes class proper case; it's pretty standard and just easier to read.

In your item list, you seem to have toyed with the idea of amount, be never used it. As a result, all items in the game can only be seen once.


Here's some code that may help:
java
 

import java.util.*;

class Item {
// the name of the item will be unique
public String name;
public String descrip;
public int price;
public boolean use_able;

public Item(String name, String descrip, int price, boolean use_able) {
this.name = name;
this.descrip = descrip;
this.price = price;
this.use_able = use_able;
}
}


class InventoryItem {
public Item item;
public int amount;

public InventoryItem(Item item, int amount) {
this.item = item;
this.amount = amount;
}
}

// for shops, people, rooms, etc.
// keep amounts correct
class Inventory extends ArrayList<InventoryItem> {
private InventoryItem findItem(String itemName) {
for(InventoryItem invItem : this) {
if (invItem.item.name.equals(itemName)) {
return invItem;
}
}
return null;
}

private InventoryItem findItem(Item item) {
return findItem(item.name);
}

public int getItemCount(Item item) {
InventoryItem invItem = findItem(item);
if (invItem==null) { return 0; }
return invItem.amount;
}

public Item takeItem(Item item) {
InventoryItem invItem = findItem(item);
if (invItem==null) { return null; }
invItem.amount--;
if (invItem.amount==0) { this.remove(invItem); }
return item;
}

public int receiveItem(Item item) {
InventoryItem invItem = findItem(item);
if (invItem==null) {
this.add( new InventoryItem(item, 1) );
return 1;
} else {
invItem.amount++;
return invItem.amount;
}
}

}

public class Rpg {
private Inventory shop;

public Rpg() {
this.shop = new Inventory();
this.loadAllItems(shop);
}

private void addNewItem(Inventory inv, String name, String descrip, int price, boolean use_able, int amount) {
inv.add( new InventoryItem(new Item(name, descrip, price, use_able), amount) );
}

private void loadAllItems(Inventory inv) {
addNewItem(inv, "Potion", "Heal life by ", 100, true, 100);
addNewItem(inv, "ether", "Regenerate mana by ", 50, true, 50);
//..
}

public static void main(String[] args) {
Rpg pgm = new Rpg();

}

}


The item class itself can be extended and probably should. You can have a Weapon class, for example. You have a Player class. The Player could extend the Npc class. The Npc class ( player ) can have their own Inventory. So, when you kill a critter, you get it's stuff. Inventory could also contain the money amounts.

As Martyr2 notes, static are an issue. You only need one static method, ever. With that in mind, if you can excise them you'll be much better off. In the code you use Iterator. I don't believe I've ever seen the iterator actually used in Java, there's probably a reason. In most places you'll have a better time with for.


This is only what I'd to to make it easier for me. Hopefully it will make it easier for you. If not, ignore me. Most importantly, have fun. biggrin.gif


--------------------
IPB Image
User is offlineProfile CardPM

Go to the top of the page

crazyskateface
post 8 May, 2008 - 02:24 PM
Post #4


New D.I.C Head

*
Joined: 5 Feb, 2008
Posts: 9


My Contributions


wow yea thanks for helping me out, it seems to want to work a lot better now!


--------------------
JAVA == AWESOMENESS :)
User is offlineProfile CardPM

Go to the top of the page

Steven Smith
post 11 May, 2008 - 09:48 AM
Post #5


New D.I.C Head

*
Joined: 17 Mar, 2008
Posts: 24


My Contributions


My point has been made already by Martyr, but modularization of code is important.

If you wanted to up the ante a little bit. I would recommend creating a more editable document file for things like your list of items, your prices etc, and have your Java program load that. This isn't paramount for your particular application, but if you are using this as a learning tool for future projects, separating your content from the code really helps you generate new content more quickly and tweak old content for balancing.

Finally, KUDOS! Maybe 1 in 10 new topics about game development have code associated with them. I always like to see people asking for help after they have tried and not before.

Steven

This post has been edited by Steven Smith: 11 May, 2008 - 09:48 AM
User is offlineProfile CardPM

Go to the top of the page

yanom
post 16 May, 2008 - 05:56 PM
Post #6


New D.I.C Head

*
Joined: 5 Apr, 2008
Posts: 37


My Contributions


nice rpg. Mabye make a graphical version? Kinda like KQ?


--------------------
Windows shares 98% of it's code with a virus
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Display Mode: