CompSci 94 Fall 2019: Assignment 5

Due: Thursday, Nov 14 - 11:59pm

15 points

This is individual work. You may talk to other students in the course about your design and for ideas, but you are to write the complete Alice program by yourself. You may receive help from the Professor, UTA's or TA.

Guess the Secret Code Game

The SetUp:

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.

How the Game Works

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.

Steps in building the program

  1. You will need to make the navajoBlanket permanently invisible. Later it will be helpful to determine whether a sunFace is above it or below it.
  2. Edit the Scene function named getCode that has been started for you. This function has no parameters. It returns a TextString that represents the secret code. For example, if the code array has the three entries in this order: "Up" "Down" "Up", then this function would return the TextString "UpDownUp"

    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.

  3. Test the function you just wrote!

    In myFirstMethod, first add in a doInOrder, and have the bunny say the current code (which is "DownDownDown") by calling the getCode function.

  4. Edit the Scene procedure named generateRandomCode that creates a secret code in the code array. This procedure has no parameters. Each entry in the code array should randomly be assigned either "Up" or "Down".

    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".

  5. Test the procedure you just wrote!

    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.

  6. Edit the Scene procedure named generateCodeThatIsNotStartCode that has been started for you. This procedure has no parameters. This procedure calls the procedure generateRandomCode repeatedly until the secret code is NOT "DownDownDown".

    Hint: Use a while loop.

  7. Test the procedure you just wrote!

    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".

  8. Add in a scorer. You will need to put in the following:

    Here is an example after two clicks showing a score of 2.

  9. In myFirstMethod, test your scorer by calling initializeScore, and then call updateScore twice. Once it works remove these calls.
  10. Now get rid of all the testing code you have in myFirstMethod and write myFirstMethod now for the game.
    1. Put in a doInOrder tile.
    2. The first line should be the call to generateCodeThatIsNotStartCode. Be sure to remove the line that has the bunny say the secret code.
    3. Next create a TextString variable and set it by calling the function getStringFromUser. Ask the user if they want instructions and to type y or n.
    4. If the user wants instructions, then call the procedure named instructions that has already been written for you. Otherwise do nothing.
    5. At the same time, have the bunny say "start now" and call the initializeScore procedure. The scorer should appear at this time.
  11. Create a keyPress event so that if you press the letter "S", the bunny will say the secret code. We won't tell the user about this secret event. It is just for you to use in testing your game.
  12. Add a mouseClickOnObject event for whenever you click on any sunFace. This event should do the following.
    1. First put in a doInOrder
    2. If a sunFace is clicked on, it should move. If it is at the top of a cedarPole, it should move down (1 unit), and if it is at the bottom of a cedarPole, it should move up (1 unit).
    3. Update the score
  13. Test your program, run it and click on the sunFaces, they should move and the score should update. The game will not stop yet once the sunFaces are in the positions of the secret code.
  14. Edit the Scene function named guessedCode. This function should return true if the sunFaces are in the positions of the secret code. Otherwise this function should return false.

    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.

  15. Finish the code in the mouseClickOnObject event for clicking on sunFaces.

    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.

  16. Play your game. The game is mostly done.
  17. There is one more thing to do. The sunFaces can be clicked on anytime, before the game starts, while the bunny is giving instructions, and after the game is over. They should only move when the game is on.
  18. Play your game. The game is now done
  19. Make a web page to describe the game. Include a description of how to play the game and include at least THREE pictures of the game on your website. It may be difficult to make a video of a game with events in Alice. The events are recorded separately and may not fit in correctly. You do not need to do a storyboard for this assignment.
  20. The presentation must be nice. 20% of the grade is on presentation and style. This also includes comments, comment your code! You should include a comment in myFirst method with your name, the date and a comment about what myFirstMethod does. Be sure to include comments in the scorer procedures you wrote and in the events you wrote.

SUBMISSION

  1. Submit your Alice program using websubmit which is on the assignment page on the CompSci 94 webpage

  2. Fill out the REFLECT form also on the assignment page. Note that in the REFLECT Form you will need to include a link to your web page for this assignment.