I am kind of lost at the moment. I have several methods and I want to send several things between them. One is who is playing and the other is how many stones there are left. I am also not sure if I am just writing it correctly, for in the main method I put:
Expand|Select|Wrap|Line Numbers
- if (goesFirst == HUMAN)
- {
- DoComputerTurn(left);
- }
- else
- {
- DoHumanTurn(left);
- }
Expand|Select|Wrap|Line Numbers
- import java.util.Scanner;
- import java.util.Random;
- public class Stones
- {
- static int HUMAN = 0;
- static int COMPUTER = 1;
- static int STONES =13;
- static Scanner keyboard = new Scanner(System.in);
- static int choice = 0;
- static int left = 0;
- static Random generator = new Random ();
- public static void main (String[]args)
- {
- ShowInstructions();
- String prompt = "Would you like to play 13 Stones (1 for yes, 2 for no)?";
- while (Again(prompt))
- {
- int goesFirst = GetCoinToss ();
- PlayGame (goesFirst);
- SwitchPlayer (goesFirst);
- if (goesFirst == HUMAN)
- {
- DoComputerTurn(left);
- }
- else
- {
- DoHumanTurn(left);
- }
- }
- }
- public static void ShowInstructions ()
- {
- System.out.println ("Welcome to the 13 Stones game. \nI hope you are ready to play against me. \nThere is 13 stones in front of you. The first player is to remove either 1, 2, or 3 stones. \nThen the next player will remove either 1, 2, or 3 stones. \nThe person to pick up the last stone losses. \nGood luck!");
- }
- public static boolean Again (String prompt)
- {
- System.out.println (prompt);
- choice = keyboard.nextInt();
- return (choice == 1);
- }
- public static int GetCoinToss()
- {
- final int heads = 0;
- final int tails = 1;
- System.out.println ("Call the coin toss...");
- String enter = new String (keyboard.nextLine());
- String call = new String (keyboard.nextLine ());
- int toss = generator.nextInt(2);
- if (((call.equalsIgnoreCase("Heads")) && (toss == heads)) || ((call.equalsIgnoreCase("Tails")) && (toss == tails)))
- {
- System.out.println ("You got lucky. So I guess you go first. Choose the number of stones you want.");
- return HUMAN;
- }
- else
- {
- System.out.println ("Ha! You lost the coin toss! I go first.");
- return COMPUTER;
- }
- }
- public static int PlayGame(int whoseTurn)
- {
- if (whoseTurn == COMPUTER)
- {
- int compTakes = generator.nextInt(3) +1 ;
- int left = STONES - compTakes;
- System.out.println ("I took " + compTakes + " stones. There is " + left + " stones left. Your turn.");
- return COMPUTER;
- }
- else
- {
- int humanTakes = keyboard.nextInt();
- while ((humanTakes> 3) || (humanTakes<0))
- {
- System.out.println ("Trying to cheat, eh? Well, you can't! Try again.");
- humanTakes = keyboard.nextInt ();
- }
- left = STONES - humanTakes;
- System.out.println ("You took " + humanTakes + " stones. There is " + left + " stones left. My turn!");
- return HUMAN;
- }
- }
- public static int SwitchPlayer (int whoseTurn)
- {
- if ( whoseTurn == COMPUTER)
- {
- whoseTurn = HUMAN;
- }
- else
- {
- whoseTurn = COMPUTER;
- }
- return whoseTurn;
- }
- public static int DoHumanTurn (int STONES)
- {
- int stonesPicked = 0;
- System.out.println ("There is " + STONES + " stones left. Please enter the amount of stones you would like to take.");
- stonesPicked = keyboard.nextInt();
- while ((stonesPicked < 1) || (stonesPicked > 0))
- {
- System.out.println ("So you think you can cheat, eh? Well you can't! Enter the number you want to take again.");
- stonesPicked = keyboard.nextInt();
- }
- int stonesRemaining = stonesPicked;
- return stonesRemaining;
- }
- public static int DoComputerTurn (int STONES)
- {
- int compTakes = generator.nextInt(3) +1 ;
- int left = STONES - compTakes;
- System.out.println ("I took " + compTakes + " stones. There is " + left + " stones left. Your turn.");
- }
- }