Project #2 Nim
Code
///Name: Ian Grant
///Period:5
///Project Name: Nim
///File Name:Nim.java
///02/03/16
import java.util.Scanner;
public class Nim
{
public static void main (String [] args)
{
String name1,name2,pile;
int a=5,b=4,c=6,rem=0;
Scanner stuff= new Scanner(System.in);
System.out.println("Player 1 enter your name: ");
name1= stuff.next();
System.out.println("Player 2 enter your name: ");
name2= stuff.next();
do
{
System.out.println("\t a: "+a+"\t b: "+b+"\t c: "+c);
System.out.println(name1+", choose a pile: ");
pile= stuff.next();
System.out.println("How many to remove frome pile "+pile+": ");
rem= stuff.nextInt();
if (pile.equals("a"))
{
a=a-rem;
}
else if (pile.equals("b"))
{
b=b-rem;
}
else if (pile.equals("c"))
{
c=c-rem;
}
if (a+b+c>0)
{
System.out.println("\t a: "+a+"\t b: "+b+"\t c: "+c);
System.out.println(name2+", choose a pile: ");
pile= stuff.next();
System.out.println("How many to remove frome pile "+pile+": ");
rem= stuff.nextInt();
if (pile.equals("a"))
a=a-rem;
else if (pile.equals("b"))
b=b-rem;
else if (pile.equals("c"))
c=c-rem;
if (a+b+c==0)
{
System.out.println(name2+" loeses!!!");
System.out.println(name1+" wins!!!");
}
}
else
{
System.out.println(name1+" loeses!!!");
System.out.println(name2+" wins!!!");
}
}while (a+b+c>0);
}
}
Output