HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

help with java anyone?

01-14-2007, 01:54 AM#1
Argo
I'm using Java 1.4.2

I want the variable currentSpaceAllPlayers [1] to be set back to 1 + the remaining rolled number. It will work some times but most of the time goes above 39 and then it will just keep adding on the rolled number.

Code:
Code removed by Argo.
01-14-2007, 01:57 AM#2
Vexorian
please... [code] tags and Programming forum! (not triggers) I am moving it and adding the [code tag

I guess the whole class is a good thing since someone would actually be able to test stuff.

Double post is almost always worse than worse forum, anyways I 'll delete your previous thread
01-14-2007, 02:03 AM#3
shadow1500
Code:
else if (currentSpaceAllPlayers [1] + playersRoll [1] == 40 || playersRoll [1] == 41 || playersRoll [1] == 42 || playersRoll [1] == 43 || playersRoll [1] == 44 || playersRoll [1] == 45 || playersRoll [1] == 46 || playersRoll [1] == 47 || playersRoll [1] == 48 || playersRoll [1] == 49 || playersRoll [1] == 50 || playersRoll [1] == 51)
Can be simplfied to:
Code:
else if (currentSpaceAllPlayers [1] + playersRoll [1] == 40 || (41<=playersRoll[1] && playersRoll[1]<=51))
01-14-2007, 02:05 AM#4
Vexorian
yeah wouldn't be able to notice, this code is confusing as if you were forbidden to use the < and > characters


seems those big if blocks with conditions about if (currentSpaceAllPlayers [1] == 1) and then rect filling also have this issue
Edit: no but there's a lot of repeated code, you should really keep the code that is common to all the coditions outside the if and save a lot of code.

The bugged code simplifies to this:

Code:
            if (currentSpaceAllPlayers [1] == 39)
            {
                currentSpaceAllPlayers [1] = 1;
                playersRoll [1] -= 1;
                currentSpaceAllPlayers [1] = playersRoll [1];
            }
            else if (currentSpaceAllPlayers [1] + playersRoll [1] == 40 || (playersRoll [1] >= 41))
            {
                currentSpaceAllPlayers [1] = playersRoll [1];
            }
            else
            {
                currentSpaceAllPlayers [1] = currentSpaceAllPlayers [1] + playersRoll [1];
            }

I really think that you want a >= 39 there.
01-14-2007, 02:13 AM#5
Argo
does anyone know whats wrong? I really need to finish this ASAP.

EDIT: sorry vex didn't see what you wrote at the bottom there. Well i put in >= 39 now, it is now working but it will go to 41 to about 50 every time. then loop back to 0 + the rolled number.

Code:
if (currentSpaceAllPlayers [1] >= 39)
            {
                currentSpaceAllPlayers [1] = 1;
                playersRoll [1] -= 1;
                currentSpaceAllPlayers [1] = playersRoll [1];
            }
            else if (currentSpaceAllPlayers [1] + playersRoll [1] == 40 || (41 <= playersRoll [1] && playersRoll [1] <= 51))
            {
                currentSpaceAllPlayers [1] = playersRoll [1];
            }
            else if (currentSpaceAllPlayers [1] + playersRoll [1] != 40 && playersRoll [1] != 41 && playersRoll [1] != 42 && playersRoll [1] != 43 && playersRoll [1] != 44 && playersRoll [1] != 45 && playersRoll [1] != 46 && playersRoll [1] != 47 && playersRoll [1] != 48 && playersRoll [1] != 49 && playersRoll [1] != 50 && playersRoll [1] != 51)
            {
                currentSpaceAllPlayers [1] = currentSpaceAllPlayers [1] + playersRoll [1];
            }
01-14-2007, 10:45 AM#6
SeasonsOfLove
First of all:
Code:
die1 = (int) (Math.random () * 5);
die2 = (int) (Math.random () * 5);
Should be:
Code:
die1 = (int)(Math.random() * 6);
die2 = (int)(Math.random() * 6);
So you can get up to 5.

Secondly, can't you just do:
Code:
currentSpaceAllPlayers[1] = currentSpaceAllPlayers % 40;
For all cases. That way, you'll never get above 40. And then number the places on the board 0 to 39 instead of 1 to 40.
01-14-2007, 08:49 PM#7
Naakaloh
He's using integers 0 to 5, rather than 1-6.

Argo, I'm assuming you're taking a class, I'm not sure how far you've gotten, but wouldn't it be wiser, since JAVA is an OOP language to use that to your advantage? I'd imagine it would be easier to keep up with an array of Player or BoardSquare objects with their own member variables for board position or whatever rather than arrays of different variable types?

But anyway, SeasonsOfLove is right, I believe it's the same idea I used with that Monopoly map you asked me to help with a long time ago. ><
01-14-2007, 09:52 PM#8
Argo
Quote:
Originally Posted by Naakaloh
But anyway, SeasonsOfLove is right, I believe it's the same idea I used with that Monopoly map you asked me to help with a long time ago. ><

Oh ya, have you finished that yet?
01-14-2007, 09:55 PM#9
Vexorian
Always comment your code, it was impossible for me to understand what you actually wanted with those formerly bugged lines, or you should have explained what you wanted them to do instead of the vague explanation
01-14-2007, 09:55 PM#10
SeasonsOfLove
Quote:
Originally Posted by Naakaloh
He's using integers 0 to 5, rather than 1-6.

But he's getting integers 0-4, rather than 0-5. Math.random() never equals 1.0, so Math.random()*5 never equals 5, so you cannot get a value of 5 out of it.