The Student Room Group

the game "nim" on java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class PlayerMove

{
public int PlayerMove(int marbles) throws IOException
{
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
System.out.println("It is now your turn, currently there are "+ marbles );
boolean ok;
String inputLine;
int num;
ok = false;
do
{
System.out.println("how many would you like to remove?");
inputLine = console.readLine();
num = Integer.parseInt(inputLine);

if (num == 0)
{
ok = false;
}
else if ( num < ((marbles /2)+1))
{
ok = true;
}
else
{
ok = false;
}
} while (ok == false);
marbles = marbles - num;
return marbles;

}
}



does this look correct. What i'm also trying to do/add is

1. allow the user to choose how many rows he'd want
2. allow the player to play against another player.

any ideas?
Reply 1
Consider putting it on Pastebin with syntax highlighting and indentation as appropriate.
Reply 2
not sure how to onTSR

Latest

Trending

Trending