Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I believe this is Java but I need it to be Python? Is it possibile? Game.class package hw 1 ; public class Game { /
I believe this is Java but I need it to be Python? Is it possibile? Game.class
package hw;
public class Game
constants
public static final int FINALPOSITION ;
public static final int INITIALPOSITION ;
public static final int NUMPLAYERS ;
public static final String BLUE "BLUE";
public static final String GREEN "GREEN";
public static final String ORANGE "ORANGE";
public static final String PURPLE "PURPLE";
public static final String RED "RED";
public static final String YELLOW "YELLOW";
public static final String COLORS BLUE, GREEN, ORANGE, PURPLE, RED,
YELLOW ;
public static final int NUMCOLORS ;
names of special characters marking specific spaces on the board
public static final String PLUMPY "PLUMPY";
public static final String MRMINT MR MINT";
public static final String JOLLY "JOLLY";
A partial board for Candyland
based on the picture at: http:wwwlscheffer.comCandyLandbig.jpg
String board RED, PURPLE, YELLOW, BLUE, ORANGE, GREEN, RED, PURPLE,
PLUMPY, YELLOW, BLUE, ORANGE, GREEN, RED, PURPLE, YELLOW, BLUE,
MRMINT, ORANGE, GREEN, RED, PURPLE, YELLOW, BLUE, ORANGE, GREEN,
RED, PURPLE, YELLOW, BLUE, ORANGE, GREEN, RED, PURPLE, YELLOW,
BLUE, ORANGE, GREEN, RED, PURPLE, YELLOW, BLUE, JOLLY, ORANGE
;
public int positions new intNUMPLAYERS;
set all elements of the positions array to INITIALPOSITION
Parameters: positions will store where the players are
numPlayers how many there are
void initializeint positions int numPlayers
for int player ; player numPlayers; player
positionsplayer INITIALPOSITION;
Description: Test if String is a valid color in the game
Parameter: str String to test
Returns: true if it is a color in the game, false if not
boolean isColorString str
for int color ; color NUMCOLORS; color
if str COLORScolor
return true;
return false;
Description: Starting after indicated position search forward on board to
find the color
Parameters: startPos index of current space of player start looking
after this space
color find the next space with this color
Returns: index of next space of chosen color
int findColorint startPos, String color
for int pos startPos ; pos FINALPOSITION; pos
if boardpos color
return pos;
return FINALPOSITION;
Description: find position of indicated person
Parameters: name name of person to look for
Returns: index of space for this name
public int findPersonString name
try
if name PLUMPY
return ;
if name MRMINT
return ;
if name JOLLY
return ;
catch Exception e
System.out.printlnno such person in the game";
should not get here just here to get program to stop
return FINALPOSITION;
Description: Move a player
Parameters: player index of player to move
card indicates where to move
repeat true if card is a "double" color, false if not
positions where the players are
Returns: new position of player after move
public int moveint player, String card, boolean repeat, int positions
int nextPos positionsplayer;
if isColorcard
nextPos findColorpositionsplayer card;
if repeat
nextPos findColornextPos card;
return nextPos;
else
return findPersoncard;
Description: Check for a winner
Parameters: positions where the players are
numPlayers how many there are
Returns: true if there are no winners yet
false if anyone has won
public boolean nowinnerint positions int numPlayers
for int player ; player NUMPLAYERS; player
if positionsplayer FINALPOSITION reached the end
return false;
return true;
Description: Display welcome String
void printIntro
System.out.printlnThis is a crude version of Candyland";
Generate the next value "drawn"
Returns: the value of the next card drawn. Returning the empty String
indicates
there are no more values
String draw
String testRolls PLUMPY, YELLOW, RED, YELLOW, GREEN, MRMINT,
JOLLY, RED, GREEN ;
int NUMCARDS ;
int next ;
if next NUMCARDS
return ;
return testRollsnext;
Indicate if this card is a "double" color
Returns: true if the color is a double, false if not.
NOTE: This is a very bad way to do this but it does help to motivate
structures
boolean drawRepeat
boolean testRollsRepeat false, true, false, true, false, false,
false, false, false ;
int NUMCARDS ;
int next ;
if next NUMCARDS
return false;
return testRollsRepeatnext;
Print the identity of the winner, if any.
If there are no winners, do nothing.
Parameters:
positions the array indicating where the players are located
numPlayers
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started