Archived

This topic is now archived and is closed to further replies.

RonanHayes

[java] Dice Game: Need help finishing

Recommended Posts

Hey all Im not a big fan of Java but I was given this to do so I had to. Anyway its nearly finished or so I think anyway, basically all I need to do now is validate and ensure that if the user is outside the top 10 then they dont get to enter into the scoreboard. so I''ve created an if statement within a for loop for (int i=0; i<10 && i< scores.size(); i++) { if(total > ((LeaderBoard)scores.get(i)).getScore()) { enterName(); } else scoreBoard(); } Basically it has database access, to store the scores and well since I dont really know much about vectors, Im pretty stuck, I know the basics any help would be fantastic. full source is located @ http://www.weclome.ie/ronan/DiceGame.zip if you could take a look and let me know what I need to improve I still have to tidy the whole thing up, but this is something that has been bugging me for sometime. this particular snip of code is located in the DiceGame.java in the method actionPerformed. Any help would be great Ronan

Share this post


Link to post
Share on other sites
The way it is now the player is left to go to the writeName method for each rank which he beat ie if he got in first place he would have to enter his name for 1st,2nd,3rd...10th

To get away from this try this


boolean check=false;
for (int i=0; i<10 && i< scores.size(); i++)
{
if(total > ((LeaderBoard)scores.get(i)).getScore())
{
check=true;
}
}
if (check) {
enterName();
}
else
scoreBoard();

BTW you might want to but a break in the for loop so that the i value is preserved and then send it as a parameter to the entername method...just a little tip to make things easier...or just complicate things


BTW2: I couln''t access the address you gave......

Share this post


Link to post
Share on other sites