Keep Going
Last updated
Last updated
Step 3
The game will need a way of asking questions and comparing the answers typed with the correct answers. The questions and answers that are going to be used for this game are below:
What university did I attend? Yale
What programming term did I create for problems? bug
What is my nickname? Amazing Grace
What programming language did I help develop? COBOL
What did I create for compiled languages? compiler
Look in the blocks menu and see if there is something that can be used to keep up with all of the questions and answers. You may need to click the ‘Advanced’ button to find more options.
Step 3 continued
Add 2 arrays to your program now. These need to be included with the on start block so that they get created when the game starts. You will need one array for the questions and one array for the answers. These are referred to as parallel arrays because the question is at the same index in questionList as the answer is in answerList. When you’re done, they should look like this:
In your notebook Answer these three questions
The number of elements (questions) that are in the array is referred to as the length of the array.
What is the length of the questionList array?
The location of the elements in the array are referred to as the index of the elements. In MakeCode, indexing starts with 0 and ends with the length of the array - 1.
What is the index of “What university did I attend?” What is the index of “What is my nickname?” What is the index of “What did I create for compiled languages?”
Step 4
Now it's time to have the sprites interact with each other. Think about how this has been done in previous games. The sprite of kind ‘player’ will move and touch the sprites of kind ‘question’.
Now, what should happen when this interaction happens?
The game should prompt the person playing with a question.
This question should be random and come from the question list.
The player will then be able to respond to the question.
Then, the game will determine if the answer is correct or incorrect based on the value of the answer typed by the person playing the game
In your notebook: write an algorithm that will pick a random question from the array, questionList.
Using this algorithm, let’s get this into blocks. Once you have the question being pulled from the questionList and the corresponding answer being pulled from the answerList, the game should prompt the player for the question. This can be done using this block from the Game menu:
This block will be used with an answer variable so that when the player answers the question, the data is stored into a variable:
Don’t forget to test your game. At this point the game should have a player sprite that when it’s moved to touching a question sprite, the game prompts the player with a random question from the array, questionList.