I like text games and I am working on one that primarily uses text input (but may have some graphics). I noticed something about your random number generation that I thought I would point out. Here is your code for generating the random number you use:
1 2 3
| public int randomNumber(){ keyen = 1 + (int) (Math.random() * 4.0); return 0;} |
Where
keyen is a field within class. The problem is that you are setting
keyen inside of the function. What if you want a second random number in your game, for instance to determine whether an attack break's the player's weapon? A better way is to write it like this:
1 2 3
| public int randomNumber() { return 1 + (int) (Math.random() *4.0); } |
and then call it like this:
1
| keyen = randomNumber(); |
Now your
randomNumber function generates a value that can be assigned to any variable, not k=just
keyen. Now you can also do something like
keyen2 = randomNumber() and it won't affect
keyen. So this is better there's still a problem. What if sometimes you want to get a random number between 1 and 4 and sometimes between 1 and 6? With how you have things right now you would need a new function. Instead, make the maximum value a parameter.
1 2 3 4 5 6
| public int randomNumber(int maxValue) { return 1 + (int)(Math.random()*(double)maxValue); }
keyen = randomNumber(4); |
Now you can have
keyen2 = randomNumber(6);