BleepingComputer.com: JAVA Problem ...

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

JAVA Problem ...

#1 User is offline   denny8569 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 3
  • Joined: 12-February 10

  Posted 12 February 2010 - 11:08 PM

ok,
so i'm working on my first large project the roguelike. i really am in no way experienced enough but im just going to learn along the way. right now im not worrying about the map and so on and im focusing on the actors (NPC's and the PC) my first goal is to finish character generation so that you can create a character and look at his/her character sheet.

so far i have the class BodyPart which holds all flags and stats that a bodypart needs...


public class BodyPart

{
  
	// Container Flags
	public boolean canWield;
		
			
	/** Creates a new instance of BodyPart */
	public BodyPart(boolean startCanWield)
	
	{
	
	canWield = startCanWield;
	
	}

}

i use class creature to put together creatures
public class Creature

{
	
	protected int creatureType;
	
	  
	/** Creates a new instance of Creature */
	public Creature(int startCreatureType)
	
	{
		
		creatureType = startCreatureType;
		
		switch(creatureType)
		
		{
			
			case 1: buildHuman(); break;
					
		}
	
	
	
	}
	
	public void buildHuman()
			
	{
	  
		BodyPart leftArm = new BodyPart(true);
		leftArm = new BodyPart(true);
			  
	}

}


then i have 2 subclasses of creature "NPC" and "PC" which are basically the same thing accept that NPC's will use AI of course.

now what i want to know is first off: does this even make sense?

and second: if it does then how do i see the information stored in an object? i have a main class as a test... i want to tell java to create a NPC and then print whether or not canWield is true or not but i dont see how. i am putting the creature object into memory with a left arm right?



i may just be doing everything wrong so bear with me on this ok?

#2 User is offline   flyingduck15 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 34
  • Joined: 14-February 10

Posted 16 February 2010 - 06:00 PM

Hi,

I am not an expert myself but I'll try to answer your question the best as I can, perhaps I can learn something too.

I think the easiest way to test would be to have BodyPart leftarm as a global attribute in the Creature class. And have a method in BodyPart and in Creature to return boolean value of canWield. So it would be something like:

in BodyPart class:

public boolean getCanWield () {
return canWield;
}

-----

in Creature class:

private BodyPart leftarm;

.....

public void buildHuman () {

....

}

public boolean getCanWield () {
return leftarm.getCanWield();
}

-----

Hope that helps.

This post has been edited by flyingduck15: 16 February 2010 - 06:07 PM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users