Created
November 1, 2013 17:36
-
-
Save joeyv/7268949 to your computer and use it in GitHub Desktop.
Sticks game not done lol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Sticks{ | |
public static void main(String []args){ | |
int sticks, maxStick = 0; | |
int userStick = 0, compStick = 0; | |
Scanner scan = new Scanner(System.in); | |
Random generator = new Random(); | |
sticks = generator.nextInt(80) + 20; | |
if (sticks >= 51){ | |
maxStick = 5; | |
} else if (40 < sticks && sticks <= 50){ | |
maxStick = 4; | |
} else if (30 < sticks && sticks <= 40){ | |
maxStick = 3; | |
} else if (19 < sticks && sticks <= 30){ | |
maxStick = 2; | |
} | |
while (sticks >= 0){ | |
System.out.println ("There is " + sticks + " sticks in the pile."); | |
System.out.println ("Take out 1 - " + "" + maxStick + ":"); | |
userStick = scan.nextInt(); | |
if (maxStick == 5){ | |
compStick = generator.nextInt(5) + 1; | |
} else if (maxStick == 4){ | |
compStick = generator.nextInt(4) + 1; | |
} else if (maxStick == 3){ | |
compStick = generator.nextInt(3) + 1; | |
} else if (maxStick == 2){ | |
compStick = generator.nextInt(2) + 1; | |
} | |
if (userStick > maxStick){ | |
System.out.println ("Please pick a number 1 - " + "" + maxStick); | |
}else { | |
continue; | |
} | |
if (sticks == maxStick){ | |
compStick -= 1; | |
} | |
if (sticks == 2){ | |
compStick = 1; | |
} else { | |
sticks -= userStick; | |
sticks -= compStick; | |
} | |
if ( compStick == userStick){ | |
sticks /= 2; | |
} else { | |
sticks -= userStick; | |
sticks -= compStick; | |
} | |
System.out.println ((userStick) + " " + (compStick)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment