Results 1 to 14 of 14
  1. #1
    Nickmanzz is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Exclamation Java RPG problems

    Hello, I'm working on a project that involves building an RPG game using Java coding and databases.

    It's supposed to act like this:
    When the game starts, you have to roll a dice. The number you get on the dice equals the number of steps you can take. When the caracter reaches the end position, the game ends.

    But this is what happens:
    It ends the game almost instantly because for sole reason it make the start position the end position.

    I would appreciate any help you guys give me to solve this issue

    Thanks in advance
    Nickmanzz

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Unfortunately it sounds like you have StartPos = EndPos; somewhere in your code. I don't know why or where but you must've thought it was a good idea at the time.

    Maybe if you posted your code so we could actually see your problem, we might be able to help you.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    I'd like to second what Dark said. It sounds like the number of steps allowed is somehow becomming the start position. Please post the relevent code in [CODE] /CODE] tags

  4. #4
    Nickmanzz is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Ok, here is the code that should check if the end position is reached:

    Java Code:
    public boolean eindeSpel(Personage huidigPersonage)
    	{
    		//return (huidigPersonage.getOpVak().getXcoordinaat()==getEindeX() && huidigPersonage.getOpVak().getYcoordinaat()==getEindeY());
    		boolean eindespel;
    		if ((huidigPersonage.getOpVak().getXcoordinaat() != getEindeX()) && (huidigPersonage.getOpVak().getYcoordinaat() != getEindeY()))
    			eindespel = true;
    		else
    			eindespel = false;
    
    		return eindespel;
    	}
    I'm don't know if you guys will understand it, cause all the names are in Dutch.
    Sorry for that

  5. #5
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    I won't know what the word means, or what its supposed to mean but anyone looking at it should be able to figure out what each word is supposed to do.

    However, I may be wrong but I don't think the problem lies within that snippet. How are you determining the end coordinates and how do you detect when and how far they move?
    Last edited by Dark; 04-13-2011 at 12:35 PM.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  6. #6
    Nickmanzz is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    the level is devided into sections and they have to roll a dice,
    for instance, the roll a 5 with the dice, then they can move 5 sections

  7. #7
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    I meant show us the code.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  8. #8
    Nickmanzz is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    oh, sorry for that
    ok than here it is, the complete code of the gamebord

    Java Code:
    package domein;
    
    import java.util.ArrayList;
    
    import domein.Vak;
    
    
    public class Spelbord {
    	
    	//ATTRIBUTEN
    	private int aantalkolommen;
    	private int aantalrijen;
    	private Vak spelbord[][];
    	private int eindeX;
    	private int eindeY;
    	private int beginX; 
    	private int beginY;
    	
    	//CONSTRUCTOR	
    	public Spelbord(int aantalkolommen, int aantalrijen, int eindeX, int eindeY, int beginX, int beginY) {
    		this.setAantalkolommen(aantalkolommen);
    		this.setAantalrijen(aantalrijen);
    		this.setEindeX(eindeX);
    		this.setEindeY(eindeY);
    		this.setBeginX(beginX);
    		this.setBeginY(beginY);
    		
    		spelbord = new Vak[aantalkolommen][aantalrijen];
    		for(int x = 0;x < aantalkolommen; x++){
    			for(int y = 0;y < aantalrijen; y++){
    				spelbord[y][x] = new Vak(x,y);
    			}
    		}
    	}
    
    	
    	//ANDERE METHODEN
    	public boolean eindeSpel(Personage huidigPersonage)
    	{
    		//return (huidigPersonage.getOpVak().getXcoordinaat()==getEindeX() && huidigPersonage.getOpVak().getYcoordinaat()==getEindeY());
    		boolean eindespel;
    		if ((huidigPersonage.getOpVak().getXcoordinaat() != getEindeX()) && (huidigPersonage.getOpVak().getYcoordinaat() != getEindeY()))
    			eindespel = true;
    		else
    			eindespel = false;
    
    		return eindespel;
    	}
    
    	public boolean isVakVrij(int xco, int yco)
    	{
    		//return (spelbord[xco][yco].getPersonage() == null && spelbord[xco][yco].getObstakel() == null);
    		if(spelbord[xco][yco].getPersonage() == null && spelbord[xco][yco].getObstakel() == null){
    			return true;
    		} else {
    			return false;
    		}
    	}
    	
    	public void beweegInRichting(char richting, Personage huidigPersonage) {
    		String richt = Character.toString(richting);
    		
    		if (richt.equals("z"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()-1].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);			
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()-1]);
    		}
    		
    		if (richt.equals("q"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()-1][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()-1][huidigPersonage.getOpVak().getYcoordinaat()]);
    		}
    		
    		if (richt.equals("s"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()+1].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()+1]);
    		}
    		
    		if (richt.equals("d"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()+1][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()+1][huidigPersonage.getOpVak().getYcoordinaat()]);
    		}
    		
    			
    	}
    	
    	public ArrayList<Personage> geefBereikbareTegenstander(int xco, int yco){
    		ArrayList<Personage> tegenstanderList = new ArrayList<Personage>();
    		
    
    		if(spelbord[xco][yco - 1].getVijand() !=null){//naar boven is yco -1
    			tegenstanderList.add(spelbord[xco][yco - 1].getVijand());
    		}
    		if(spelbord[xco - 1][yco].getVijand() !=null){//naar links is xco -1
    			tegenstanderList.add(spelbord[xco - 1][yco].getVijand());
    		}
    		if(spelbord[xco][yco + 1].getVijand() !=null){ //naar onder is yco +1
    			tegenstanderList.add(spelbord[xco][yco + 1].getVijand());
    		}
    		if(spelbord[xco + 1][yco].getVijand() !=null){ //naar rechts is xco +1
    			tegenstanderList.add(spelbord[xco + 1][yco].getVijand());
    		}
    		
    		
    		return tegenstanderList;
    	}
    	
    	public void plaatsPersonageOpBord(int xcoordinaat, int ycoordinaat, Personage huidigPersonage)
    	{
    		//huidigpersonage op een vak plaatsen en dit in de array stoppen
    	
    			spelbord[xcoordinaat][ycoordinaat].setPersonage(huidigPersonage);
    			huidigPersonage.setOpVak(spelbord[xcoordinaat][ycoordinaat]);
    		
    	}
    	
    	public void VulObstakelIn(int xcoordinaat, int ycoordinaat, Obstakel obstakel){
    		//object obstakel in de array stoppen
    		spelbord[xcoordinaat][ycoordinaat].setObstakel(obstakel);
    		
    	}
    	
    	public void VulVijandIn(int xcoordinaat, int ycoordinaat, Personage vijand){
    		//object vijand in de array stoppen
    		spelbord[xcoordinaat][ycoordinaat].setVijand(vijand);
    	}
    
    	//GETTERS
    	public int getAantalkolommen() {
    		return aantalkolommen;
    	}
    
    	public int getAantalrijen() {
    		return aantalrijen;
    	}
    
    	public Vak[][] getSpelbord() {
    		//methode die een array van het spelbord weergeeft
    		return spelbord;
    	}
    	
    	public void setVak(Vak hetvak)
    	{
    		spelbord[hetvak.getXcoordinaat()][hetvak.getYcoordinaat()] = hetvak;
    	}
    
    
    	public int getEindeX() {
    		return eindeX;
    	}
    
    
    	public int getEindeY() {
    		return eindeY;
    	}
    
    
    	public int getBeginX() {
    		return beginX;
    	}
    
    
    	public int getBeginY() {
    		return beginY;
    	}
    
    	//SETTERS
    	public void setBeginX(int beginX) {
    		this.beginX = beginX;
    	}
    
    
    	public void setBeginY(int beginY) {
    		this.beginY = beginY;
    	}
    
    	public void setAantalkolommen(int aantalkolommen) {
    		if (aantalkolommen > 0)
    			this.aantalkolommen = aantalkolommen;
    	}
    
    	public void setAantalrijen(int aantalrijen) {
    		if (aantalrijen > 0)
    			this.aantalrijen = aantalrijen;
    	}
    
    	public void setSpelbord(Vak[][] spelbord) {
    		this.spelbord = spelbord;
    	}
    	
    	public void setEindeY(int eindeY) {
    		this.eindeY = eindeY;
    	}
    
    
    	public void setEindeX(int eindeX) {
    		this.eindeX = eindeX;
    	}
    }

  9. #9
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Would you mind pointing out the areas that set your end position, start position and how the player moves?

    I'm pretty lost as to whats going on in that code because its in Dutch.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  10. #10
    Nickmanzz is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    sure no problem:

    the first highlighted part is where I set the begin, end, positions of char
    the second part is how the char moves
    hope this helps

    Java Code:
    package domein;
    
    import java.util.ArrayList;
    
    import domein.Vak;
    
    
    public class Spelbord {
    	
    	//ATTRIBUTEN
    	private int aantalkolommen;
    	private int aantalrijen;
    	private Vak spelbord[][];
    	private int eindeX;
    	private int eindeY;
    	private int beginX; 
    	private int beginY;
    	
    	//CONSTRUCTOR	
    	[B][COLOR="Blue"]public Spelbord(int aantalkolommen, int aantalrijen, int eindeX, int eindeY, int beginX, int beginY) {
    		this.setAantalkolommen(aantalkolommen);
    		this.setAantalrijen(aantalrijen);
    		this.setEindeX(eindeX);
    		this.setEindeY(eindeY);
    		this.setBeginX(beginX);
    		this.setBeginY(beginY);
    		
    		spelbord = new Vak[aantalkolommen][aantalrijen];
    		for(int x = 0;x < aantalkolommen; x++){
    			for(int y = 0;y < aantalrijen; y++){
    				spelbord[y][x] = new Vak(x,y);
    			}
    		}
    	}
    [/COLOR][/B]
    	
    	//ANDERE METHODEN
    	public boolean eindeSpel(Personage huidigPersonage)
    	{
    		//return (huidigPersonage.getOpVak().getXcoordinaat()==getEindeX() && huidigPersonage.getOpVak().getYcoordinaat()==getEindeY());
    		boolean eindespel;
    		if ((huidigPersonage.getOpVak().getXcoordinaat() != getEindeX()) && (huidigPersonage.getOpVak().getYcoordinaat() != getEindeY()))
    			eindespel = true;
    		else
    			eindespel = false;
    
    		return eindespel;
    	}
    
    	public boolean isVakVrij(int xco, int yco)
    	{
    		//return (spelbord[xco][yco].getPersonage() == null && spelbord[xco][yco].getObstakel() == null);
    		if(spelbord[xco][yco].getPersonage() == null && spelbord[xco][yco].getObstakel() == null){
    			return true;
    		} else {
    			return false;
    		}
    	}
    	
    	[B][COLOR="blue"]public void beweegInRichting(char richting, Personage huidigPersonage) {
    		String richt = Character.toString(richting);
    		
    		if (richt.equals("z"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()-1].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);			
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()-1]);
    		}
    		
    		if (richt.equals("q"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()-1][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()-1][huidigPersonage.getOpVak().getYcoordinaat()]);
    		}
    		
    		if (richt.equals("s"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()+1].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()+1]);
    		}
    		
    		if (richt.equals("d"))
    		{
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()+1][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(huidigPersonage);
    			spelbord[huidigPersonage.getOpVak().getXcoordinaat()][huidigPersonage.getOpVak().getYcoordinaat()].setPersonage(null);
    			huidigPersonage.setOpVak(spelbord[huidigPersonage.getOpVak().getXcoordinaat()+1][huidigPersonage.getOpVak().getYcoordinaat()]);
    		}
    		
    			
    	}
    	
    	public ArrayList<Personage> geefBereikbareTegenstander(int xco, int yco){
    		ArrayList<Personage> tegenstanderList = new ArrayList<Personage>();
    		
    
    		if(spelbord[xco][yco - 1].getVijand() !=null){//naar boven is yco -1
    			tegenstanderList.add(spelbord[xco][yco - 1].getVijand());
    		}
    		if(spelbord[xco - 1][yco].getVijand() !=null){//naar links is xco -1
    			tegenstanderList.add(spelbord[xco - 1][yco].getVijand());
    		}
    		if(spelbord[xco][yco + 1].getVijand() !=null){ //naar onder is yco +1
    			tegenstanderList.add(spelbord[xco][yco + 1].getVijand());
    		}
    		if(spelbord[xco + 1][yco].getVijand() !=null){ //naar rechts is xco +1
    			tegenstanderList.add(spelbord[xco + 1][yco].getVijand());
    		}
    		
    		
    		return tegenstanderList;
    	}
    	
    	public void plaatsPersonageOpBord(int xcoordinaat, int ycoordinaat, Personage huidigPersonage)
    	{
    		//huidigpersonage op een vak plaatsen en dit in de array stoppen
    	
    			spelbord[xcoordinaat][ycoordinaat].setPersonage(huidigPersonage);
    			huidigPersonage.setOpVak(spelbord[xcoordinaat][ycoordinaat]);
    		
    	}[/COLOR][/B]
    	
    	public void VulObstakelIn(int xcoordinaat, int ycoordinaat, Obstakel obstakel){
    		//object obstakel in de array stoppen
    		spelbord[xcoordinaat][ycoordinaat].setObstakel(obstakel);
    		
    	}
    	
    	public void VulVijandIn(int xcoordinaat, int ycoordinaat, Personage vijand){
    		//object vijand in de array stoppen
    		spelbord[xcoordinaat][ycoordinaat].setVijand(vijand);
    	}
    
    	//GETTERS
    	public int getAantalkolommen() {
    		return aantalkolommen;
    	}
    
    	public int getAantalrijen() {
    		return aantalrijen;
    	}
    
    	public Vak[][] getSpelbord() {
    		//methode die een array van het spelbord weergeeft
    		return spelbord;
    	}
    	
    	public void setVak(Vak hetvak)
    	{
    		spelbord[hetvak.getXcoordinaat()][hetvak.getYcoordinaat()] = hetvak;
    	}
    
    
    	public int getEindeX() {
    		return eindeX;
    	}
    
    
    	public int getEindeY() {
    		return eindeY;
    	}
    
    
    	public int getBeginX() {
    		return beginX;
    	}
    
    
    	public int getBeginY() {
    		return beginY;
    	}
    
    	//SETTERS
    	public void setBeginX(int beginX) {
    		this.beginX = beginX;
    	}
    
    
    	public void setBeginY(int beginY) {
    		this.beginY = beginY;
    	}
    
    	public void setAantalkolommen(int aantalkolommen) {
    		if (aantalkolommen > 0)
    			this.aantalkolommen = aantalkolommen;
    	}
    
    	public void setAantalrijen(int aantalrijen) {
    		if (aantalrijen > 0)
    			this.aantalrijen = aantalrijen;
    	}
    
    	public void setSpelbord(Vak[][] spelbord) {
    		this.spelbord = spelbord;
    	}
    	
    	public void setEindeY(int eindeY) {
    		this.eindeY = eindeY;
    	}
    
    
    	public void setEindeX(int eindeX) {
    		this.eindeX = eindeX;
    	}
    }

  11. #11
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    That'll give me a starting place to look, but it might take me a while.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  12. #12
    Nickmanzz is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Sure, thanks

    If it may help you, i can post the entire project to Dropbox or so, so you can take a look

  13. #13
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Java Code:
    		boolean eindespel;
    		if ((huidigPersonage.getOpVak().getXcoordinaat() != getEindeX()) && (huidigPersonage.getOpVak().getYcoordinaat() != getEindeY()))
    			eindespel = true;
    		else

    Doesn't this say:
    Java Code:
    If Object.getXCoordinate != endPosition AND Object.getYCoordinate != endPosition
        Then endGame = true;

    Shouldn't it be the other way around? i.e. if its not the endposition, endGame should be false.

  14. #14
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Yep, ozzyman found the error. A quick Google Translate shows "eindespel" means "end game" so if your coordinates don't equal the end coordinates, then "eindespel" should be false ;)

Similar Threads

  1. java problems
    By swrta in forum AWT / Swing
    Replies: 1
    Last Post: 03-23-2011, 02:32 PM
  2. Some problems with java
    By JeanNoel 53 in forum New To Java
    Replies: 1
    Last Post: 12-31-2010, 12:24 AM
  3. java problems
    By p595285902 in forum New To Java
    Replies: 6
    Last Post: 11-28-2010, 11:55 PM
  4. Replies: 2
    Last Post: 01-16-2010, 05:50 PM
  5. Java Problems
    By xonkie in forum New To Java
    Replies: 6
    Last Post: 12-03-2008, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •