Due: Thursday, Nov 14 - 11:59pm
15 points
Use the starter world here
We have already setup the game for you. There are three cedarPoles setup from left to right named cedarPole, cedarPole2, and cedarPole3. In the front of each one is a sunFace named from left to right sunFace, sunFace2, and sunFace3. There is a navahoBlanket across all the poles.
We have also provided the start of several functions and procedures, and three scene arrays shown here. The code array will be used to generate and store a random secret code, where each entry is "Up" or "Down". Initially we have set all entries to "Down".
You should note that sunFace and cedarPole are both in position 0 in their corresponding arrays, sunFace2 and cedarPole2 are both in position 1, and sunFace3 and cedarPole3 are both in position 2. The code in position 0 corresponds to the sunFace in position 0, etc.
A secret code is composed of three words, where each word is either the word "Up" or "Down". These words are to represent the position of the sunFaces on the cedarPoles for the solution. You will randomly generate the three words (using random booleans - if True use "Up", if False use "Down"). This code is not shown in the game, since the player is suppose to guess the code by clicking on the cedarPoles and moving the sunFaces until they are in the position of the code.
Here is a link to Prof. Rodger playing the game twice, once winning and once losing.
Assume the code is "DownUpDown". Each sunFace is associated to be either up (on top of a cedarPole) or down (at the bottom of a cedarPole). If you click on a sunFace, its position should change. If the sunFace is up when you click on it, then the sunFace should move all the way down to the bottom of the cedarPole. If the sunFace is down when you click on it, it should move up to the top of the cedarPole. For example, in the figure below, the game started with all the sunFaces at the bottom of the cedarPoles (in the "Down" position), then the result below is after one click: the middle sunFace, which is sunFace2, was clicked on once (sunFace2 moves up), and then it matches the code of "DownUpDown".
The game works as follows. The game generates a three word code not equal to
"DownDownDown" (otherwise you would win right away) and does not display the code.
Then you tell the player to start and tell them to click on the cedarPoles to
move the sunFaces to guess the secret code.
A counter
keeps track of how many times the player has clicked on any cedarPole.
The game ends when the
sunFaces on the cedarPoles match the three word random code. When the game
ends, the user wins if they guessed the secret code in four or fewer
clicks. If the user won, the bunny tells the user they won and also says
what the secret code was. The bunny also does a flip as it is so
excited. These are all repeated once (saying the user won, saying the
code and the bunny flipping).
If the user lost, took five or more guesses, then the bunny tells the
user what the code was and that the user took too many guesses to win.
Follow the steps below to build this game.
Hint: You will need a TextString variable. Then loop through the code
array and build a string of all the code values, Then return this
string.
TIP: Don't use blanks when you create a string of the code. There seems to
be a bug in Alice with processing strings that are blank, it tries to
help you and converts it to a string that is empty.
If you have a code array with the three values "Up",
"Down", "Up", then create a string without blanks that would be
"UpDownUp" to say the code or to compare it to the position of the
sunFaces.
In myFirstMethod, first add in a doInOrder, and have the bunny say the current code (which is
"DownDownDown") by calling the getCode function.
Hint: Use an array index loop to loop through the code array. For
each position in the code array, generate a randomBoolean. If the randomBoolean is true
then assign "Up", otherwise assign "Down".
In myFirstMethod, first call generateRandomCode, and then have the
bunny say the current code by calling the getCode function. Play it
several times, you should see different secret codes.
Hint: Use a while loop.
In myFirstMethod, instead of calling generateRandomCode, call
generateCodeThatIsNotStartCode and then have the
bunny say the current code by calling the getCode function. Play it
several times, you should see different secret codes, but never "DownDownDown".
Here is an example after two clicks showing a score of 2.
Hint: Loop through the suns array and as you do build a TextString that is
the current positions of the sunFaces. You will need a variable to
store this TextString. Then compare that TextString to the secret
code.
After updating the score, call guessedcode to see if the sunFaces are in
the position of the secret code. If so, the game is over.
If the game is over, then determine if the user won or not (based on
the score, the user wins if they guess in 4 or fewer guesses).
If the user won, then the bunny should tell them they won, tell them
what the secret code was and do a flip. All this should happen twice!
If the user lost, the bunny should tell them they guessed the
secret code but also tell them they took too long to guess it.
Steps in building the program
SUBMISSION