Web Hosting Talk







View Full Version : ~URgent java~ RSP game...


gracie
03-29-2003, 10:36 AM
I got a Game called rsp i ahve added a loop in it
and the game goes for four round displaying a winner fo each round ...

now i want to display a final winner for the overall 4 rounds at the end ...

how do i code it ? someone help plz....

jb4mt
03-29-2003, 11:11 AM
create an array to store the winner from each round, then you should be able to display access each winner such as:

winner[0]
winner[1]
winner[2]
winner[3]

gracie
03-29-2003, 11:17 AM
Sorry I Dun get it .... can u say again ...
what do u mean ... winner [0] etc...
how do i define it in my program , coz ... like i already ahev a variable called winner... if u get me .

jb4mt
03-29-2003, 11:47 AM
You're right I should have read a little better, but still the idea of an array should work. You say you have a 'variable' called winner?! Is this actually an object of class Winner?!

If so you could create your array as such:

Winner [] winners;
winners = new Winner[4];

Now, at the end of each loop you can save the winner object/variable that you already have into this array:

winners[loopNum] = winner;

where loopNum can be 0, 1, 2 or 3.

Then after all the loops finish, you can loop back over the winners, and assuming they have something such as a score attribute, something like:

int highScore = 0;

for (int i=0.....
{
highScore = Math.max(highScore, winners[i].score()); //or whatever method returns the score from the original code
}

Hope this is enough to get you on your way conceptually. Java is not like PHP. You'd better go through a tutorial or get a book if you're going to muck around much with the source.

Better yet, don't modify the original source. Create a new Class, and within you can have your loop for each round.

Now you've got me interested. Where do I find the source for this game? During my time of unemployment I'm thinking of becoming Java certified. A real example is better than the fake stuff in books though ;)

gracie
03-29-2003, 11:56 AM
Thanks Mate. okay let me try to aborb ur code then i see what i can .. I can tell you i'm not good at this stuff...

About the code abt for this gaem its actually in my resource book from University..... I don't know much where thsi coding came about but we were give na site for it ..
it might be helpful to you but i'm not so sure..
check it out and see.... www.worldrps.com

i'm still a beginner on this .. so i have no idea whats a php .. ><

cyansmoker
03-29-2003, 04:09 PM
I am not sure that jb4mt's method would work in your case.
Apparently there are 4 rounds and an arbitrary number of players...?

What I would do is maintain a HashMap. At the end of each round, I'd store/update the winning team's entry with a new Integer value that contains its number of wins.

After running for 4 rounds (or whatever the number) I'd invoke the Math.max(..) method like jb4mt suggested.

cyansmoker
03-29-2003, 04:10 PM
Gracie, PHP is an interpreted language that does wonders for web site builders :)

http://www.php.net

jb4mt
03-29-2003, 05:12 PM
Gracie, I cannot find the game on that Rock-Scissors-Paper site you refered me to. Maybe I'm just blind. Can you perhaps send me the URL where you've navigated deeper into the site?! Or can you post some source code here?