Jump to content


Java Help


10 replies to this topic

#1 DakaSha

DakaSha

    Happy Little Tree-hugger

  • Banned
  • PipPipPipPipPipPipPipPip
  • 2013 posts

Posted 16 September 2006 - 01:10 PM

ok so im 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? :(

Posted Image
For all you artists here... and we have enough. Please draw me something :D Click Here. If possible include your nick. A simple Test. dunno of the PICKLEWAESEL order!!1!2


#2 Qbix

Qbix

    AR-coholic

  • Members
  • PipPipPipPipPipPip
  • 605 posts

Posted 16 September 2006 - 01:27 PM

you may want to start reading here
http://java.sun.com/...books/tutorial/

#3 DakaSha

DakaSha

    Happy Little Tree-hugger

  • Banned
  • PipPipPipPipPipPipPipPip
  • 2013 posts

Posted 16 September 2006 - 01:38 PM

you know thats the exact reason i didnt post in a  programming forum... youll only get a "hey why dont you start reading about the basics n00b!" i was hoping i wouldnt get that here.

i have been reading the tutorials and the code i posted up there is based off of them tutorials. so instead of just giving me a link you could have said what isnt right or what i should read up on.  to me (i havnt been programming my whole life) the code up there looks fine and makes complete sense... just posting a link with 500000 topics isnt going to help


edit:

so ill just ask single questions: going by the code i have up there is the creature object (built using the buildHuman method) in memory? does java recognize the fact that the arm has been created for the creature object human (of course after i have called on the constructor  "Creature human = new Creature(1)") or is the code completly unusable for what i have planned?

Posted Image
For all you artists here... and we have enough. Please draw me something :D Click Here. If possible include your nick. A simple Test. dunno of the PICKLEWAESEL order!!1!2


#4 Qbix

Qbix

    AR-coholic

  • Members
  • PipPipPipPipPipPip
  • 605 posts

Posted 16 September 2006 - 01:51 PM

check the bycicle part of the tutorial
it shows how to create new bycicles and what how to post their contents.

Which is exactly what you asked in your original questiion
As I found this on almost the first page. I send you to tutorial.

#5 DakaSha

DakaSha

    Happy Little Tree-hugger

  • Banned
  • PipPipPipPipPipPipPipPip
  • 2013 posts

Posted 16 September 2006 - 01:52 PM

ok thank you. thats all i wanted to know :( (basically anyways)

edit: and sorry.. it sounded like you were just saying: "ah shut up and read the tuts.. you dont know what your doing anyways"

Posted Image
For all you artists here... and we have enough. Please draw me something :D Click Here. If possible include your nick. A simple Test. dunno of the PICKLEWAESEL order!!1!2


#6 DakaSha

DakaSha

    Happy Little Tree-hugger

  • Banned
  • PipPipPipPipPipPipPipPip
  • 2013 posts

Posted 16 September 2006 - 05:19 PM

ok i made it work. i can create a creature (with different bodyParts).. decide whether its a NPC or PC then print the creatures stats and bodypart stats.

the creature class looks like this:

public class Creature

{
	
	// Misc   
	protected int creatureType;
	
	// Bodypart place holders
	BodyPart bodyPart1;
	BodyPart bodyPart2;
	BodyPart bodyPart3;
	BodyPart bodyPart4;
	BodyPart bodyPart5;
	BodyPart bodyPart6;
	BodyPart bodyPart7;
	BodyPart bodyPart8;
		
	
	/** Creates a new instance of Creature */
	public Creature(int startCreatureType)
	
	{
		
		creatureType = startCreatureType;
		
		
		
		switch(creatureType)
		
		{
			
			case 1: buildHuman(); break;
					
		}
	
		
		
		
	
	}
	
	public void buildHuman()
			
	{
		
		BodyPart head = new BodyPart("Head", 6);
		BodyPart eyes = new BodyPart("Eyes", 2);
		BodyPart torso = new BodyPart("Torso", 30);
		BodyPart leftArm = new BodyPart("L. Arm", 10);
		BodyPart rightArm = new BodyPart("R. Arm", 10);
		BodyPart groin = new BodyPart("Groin", 4);
		BodyPart leftLeg = new BodyPart("L. Leg", 10);
		BodyPart rightLeg = new BodyPart("R. Leg", 10);
		 
		bodyPart1 = head;
		bodyPart2 = eyes;
		bodyPart3 = torso;
		bodyPart4 = leftArm;   
		bodyPart5 = rightArm;
		bodyPart6 = groin;
		bodyPart7 = leftLeg;
		bodyPart8 = rightLeg;
	
	
	
	}
	

}


question: is there another way of doing the buildHuman method that is more efficient? i mean without using "placeholders" (a friend said something about a hashmap) also when calling a constructor it always reads the entred numbers as integers even though the constructor isnt "configured" that way

example:

'public BodyPart(String startBodyPartName, byte startBodyPartSize)'

so i changed  startBodyPartSize to an integer but thats using uneeded memory i guess. so how do i get the called constructor to take the needed number as a byte?

edit: another thing: would it be better to learn how to use XML for callling data? like having all items and such stored in a XML file? is it just a matter of preference? is it slower/faster?

Posted Image
For all you artists here... and we have enough. Please draw me something :D Click Here. If possible include your nick. A simple Test. dunno of the PICKLEWAESEL order!!1!2


#7 MdaG

MdaG

    AR-coholic

  • Validating
  • PipPipPipPipPipPip
  • 932 posts

Posted 17 September 2006 - 01:15 PM

The only benefit of storing data on the HD instead of RAM is that you'll spare computers from running out of RAM when you play. However data access is far slower (like 1000 times) on the HD than RAM. Just use the necessary data in RAM and leave the rest on the HD for access when it is needed.

Having a lot of variables named bodyPartX (X = number) might be reason enough to just use an Array instead. That way you make it possible to loop over it should you want to.

Concering how you set up your object orientation. Why do you want a switch creature type function ? Isn't it easier to have a parent class Character and let NPCs and Player inherit from it?

#8 DakaSha

DakaSha

    Happy Little Tree-hugger

  • Banned
  • PipPipPipPipPipPipPipPip
  • 2013 posts

Posted 17 September 2006 - 01:29 PM

View PostMdaG, on Sep 17 2006, 01:15 PM, said:

Concering how you set up your object orientation. Why do you want a switch creature type function ? Isn't it easier to have a parent class Character and let NPCs and Player inherit from it?

as far as i can tell thats what im doing:

i have a class NPC:

'public class NPC extends Creature'

NPC's will use AI and PC will use the implemented player interface.

so if i want to place a NPC human on the map i call NPC(1) and give the human a class and level... mabye other little things to make single creatures more indevidual


i prob dont get what you mean though. why shouldnt i use switch?

Posted Image
For all you artists here... and we have enough. Please draw me something :D Click Here. If possible include your nick. A simple Test. dunno of the PICKLEWAESEL order!!1!2


#9 MdaG

MdaG

    AR-coholic

  • Validating
  • PipPipPipPipPipPip
  • 932 posts

Posted 17 September 2006 - 01:44 PM

View PostDakaSha, on Sep 17 2006, 03:29 PM, said:

i prob dont get what you mean though. why shouldnt i use switch?
No particular reason, I probably just fail to see the point/purpose of it.

#10 DakaSha

DakaSha

    Happy Little Tree-hugger

  • Banned
  • PipPipPipPipPipPipPipPip
  • 2013 posts

Posted 19 September 2006 - 07:27 PM

View PostMdaG, on Sep 17 2006, 01:15 PM, said:

The only benefit of storing data on the HD instead of RAM is that you'll spare computers from running out of RAM when you play. However data access is far slower (like 1000 times) on the HD than RAM. Just use the necessary data in RAM and leave the rest on the HD for access when it is needed.

so are you saying i should or i shouldnt use XML for items, monsters, quests and so on?

i mean it doesnt have to be in memory the whole time and its probably easier to create XML templates and add the needed info.

i would rather use XML... but am i going to notice a big decrease in speed? i know that might sound stupid considering this is a roguelike but ive played some very slow *money-maker* roguelikes in the past and id also like to make it playable for people using older pcs. also my compulsiveness just forces me to optimize this as much as i possibly can

Posted Image
For all you artists here... and we have enough. Please draw me something :D Click Here. If possible include your nick. A simple Test. dunno of the PICKLEWAESEL order!!1!2


#11 MdaG

MdaG

    AR-coholic

  • Validating
  • PipPipPipPipPipPip
  • 932 posts

Posted 20 September 2006 - 01:00 PM

View PostDakaSha, on Sep 19 2006, 09:27 PM, said:

View PostMdaG, on Sep 17 2006, 01:15 PM, said:

The only benefit of storing data on the HD instead of RAM is that you'll spare computers from running out of RAM when you play. However data access is far slower (like 1000 times) on the HD than RAM. Just use the necessary data in RAM and leave the rest on the HD for access when it is needed.

so are you saying i should or i shouldnt use XML for items, monsters, quests and so on?

i mean it doesnt have to be in memory the whole time and its probably easier to create XML templates and add the needed info.

i would rather use XML... but am i going to notice a big decrease in speed? i know that might sound stupid considering this is a roguelike but ive played some very slow *money-maker* roguelikes in the past and id also like to make it playable for people using older pcs. also my compulsiveness just forces me to optimize this as much as i possibly can

I think it might be a good idea (like you said) to store whatever is on the current level in RAM and leave the rest on the hardrive for access between levels. I might be wrong, but with the HD we're talking ~0.001 of a second for access time and RAM ~0.000001 of a second. Hence you probably won't notice a difference at all. It all depends on how often you need to access the data.




Reply to this topic



  


Skin Designed By Evanescence at IBSkin.com