Results 1 to 14 of 14
Thread: Java RPG problems
- 04-13-2011, 10:13 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
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
- 04-13-2011, 11:07 AM #2
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.
-
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
- 04-13-2011, 11:25 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
Ok, here is the code that should check if the end position is reached:
I'm don't know if you guys will understand it, cause all the names are in Dutch.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; }
Sorry for that
- 04-13-2011, 11:33 AM #5
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 11:35 AM.
- 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.
- 04-13-2011, 11:44 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
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
- 04-13-2011, 11:45 AM #7
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.
- 04-13-2011, 11:54 AM #8
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
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; } }
- 04-13-2011, 11:57 AM #9
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.
- 04-13-2011, 12:03 PM #10
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
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; } }
- 04-13-2011, 12:07 PM #11
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.
- 04-13-2011, 12:10 PM #12
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
Sure, thanks
If it may help you, i can post the entire project to Dropbox or so, so you can take a look
-
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.
- 04-13-2011, 09:14 PM #14
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
-
java problems
By swrta in forum AWT / SwingReplies: 1Last Post: 03-23-2011, 01:32 PM -
Some problems with java
By JeanNoel 53 in forum New To JavaReplies: 1Last Post: 12-30-2010, 11:24 PM -
java problems
By p595285902 in forum New To JavaReplies: 6Last Post: 11-28-2010, 10:55 PM -
Problems with Java 2D example in the book: JAVA 2D Graphics by O'Reilly
By Lil_Aziz1 in forum Java 2DReplies: 2Last Post: 01-16-2010, 04:50 PM -
Java Problems
By xonkie in forum New To JavaReplies: 6Last Post: 12-03-2008, 07:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks