[java] Just starting out, my first game program...

Started by
0 comments, last by ppgamedev 13 years, 11 months ago
is kinda messed up. http://pastebin.com/rN3Ut6q5 like, when i try to play it, the computers choice is always higher than 1-3 does anyone know how i could fix that?



Advertisement
It is not that the computer's choice is always higher than 1-3, it is yours the one that is higher than 3.

You can check it:
System.out.println("choice: " + choice);
System.out.println("cc: " + cc);
System.out.println("test fuck up?");

The quick solution is:
choice = Character.getNumericValue(bufRead.read());

The reason is that what you are getting with read() is the Unicode value.
In short: every symbol has a number associated with it,
e.g:
a=97
b=98
...
A=65
B=66
...
0=48
1=49
...
etc..
So when you choose 1, what you are putting in choice var is the number 49, you need to "translate" it with Character.getNumericValue

This topic is closed to new replies.

Advertisement