Keeping Score

Step 5

The game needs to have an algorithm that determines if the answer that is typed is correct or not. Create an algorithm that will compare two variables, answer and correct, and then manage the points in the game as well as the questions in the list.

In your notebook, write your algorithm.

Let’s start building this algorithm in the game. This needs to be placed right after the previous code that you built. Using the conditional if/else block in the Logic menu, you can determine if the variables, answer and correct are equal to each other. If these are equal, then the score should go up. if these are not equal the score should go down or have a counter that keeps up with how many questions have been missed.

Try your game out. Make sure to test your game by answering a question correctly and a question incorrectly.

The game needs to a few more things so that it is engaging for the player:

  • Needs to have a way of winning or losing the game

  • Get rid of the sprites for correct answers (so don’t ask same question again)

  • Get rid of questions in the list for correct answers (for the sprites that have been removed)

Tackling the question of correct answers: there are a few blocks that can make this easy. Look for these blocks in the blocks menu to implement when the player answers a question correctly:

These blocks will be used to destroy the sprite of kind question and to remove the question asked from the array, questionList, and the answer from the array, answerList. For example, if the game starts with 5 questions and the player answers a question correctly, then the game will only have 4 question sprites on the screen, and both arrays will only have 4 elements in them each.

To take care of the game winning and losing, this can be done using a conditional if statement that is found in the Logic menu. Here is an example of what that could look like to win the game:

Implement this code in your game in the correct location. Use this as an example to write an algorithm for the player to lose the game as well.

  1. This game increased in complexity from the previous game. What programming concepts were introduced to you in this game?

  1. Using a list is an example of a data abstraction since it holds multiple data elements but is called by one name. How many data abstractions are used in this game?

  1. This game implements sequencing because some of the steps in the algorithms used must be implemented in a specific order to work. What is one algorithm that demonstrates sequencing in this game?

  1. This game implements selection because there are situations in the game that a decision needs to be made. What is one algorithm that demonstrates selection in this game?

  1. There are extra features that could be added to this game to make it better. Brainstorm on a few ideas and write down 3 feature ideas that you would want to add to this game.

Last updated