Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

JAVA Problem ...


  • Please log in to reply
1 reply to this topic

#1 denny8569

denny8569

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:05:11 PM

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?

BC AdBot (Login to Remove)

 


#2 flyingduck15

flyingduck15

  • Members
  • 34 posts
  • OFFLINE
  •  
  • Local time:05:11 PM

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.

Edited by flyingduck15, 16 February 2010 - 06:07 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users