Instructions for converting from a one file game to a game
that uses a player class
Step 1:
Cut all methods except the instructions and the main method from your game
and put them into a new player class. Ensure your brackets are balanced.
In player class
- Add public class Player { to the top.
- Remove static from all methods.
- Add 2 instance variables: location and name.
- Change every method to use the location from itself instead of from the
input and update the instance variable location.
- Remove any unnecessary inputs.
- Create a constructor that takes in just a name and sets the location to
0.
- Add a getLocation method
- Add a win method
In main:
- Ask the player name and create player1 (when everything is good, you will
ask for player 2 also, but first get 1 working
- change all method calls to call methods on player1 with the correct number
of variables.
Step 2:
- Ask for another player and create it right after the first one.
- Copy everything inside your while loop to repeat the commands for player2.
- Only play for player2 if player1 hasnt won.
- Adjust the Do you want to continue question to work for both
players. (You can just ask if you want to play another round instead of asking
each student.)