Version: 4.2.1 +
In this exercise we will create the basic formula for our guessing game.
- The Futurama Editor must be installed.
- Futurama Runtime must be installed.
- Completing the tutorial Creating formulas with Futurama first, is recommended.
Guess the number is a game we are going to create in Futurama. In this game you have to guess a number that is chosen randomly (by Futurama). This number lies between 0 and 100. When the user enters a number, the game will say whether the guess is correct, or should be higher, or lower.
In this first part of the implementation of the game, we will create a formula that choses a random number between 0 and 100. Next to that, we will create a formula that states whether a given number is equal, higher or lower as the number chosen.
Create the following objects in a new Futurama document:
'RandomSelected 0 - 100' - Formula, Type Long
- We will use the formula 'Rand(), that gives a random number between 0 and 1. To convert this number to an integer between 0 and 100, we have to create the following formula:
- To create this formula, you should use the formulas 'Round', 'Rand()' and 'Multiply'. First create the formula 'Round'. Within this formula, create another formula, 'Multiply', Type Double. First element of this formula should be the 'Rand()' formula. You don't have to fill in the argument. Second element of the formula is the fixed number 100.
'InputNumber' - Fixed, Type Long
- Create a Fixed, and enter an arbitrary number in the Text property.
'AnswerCorrect' - Formula, Type Boolean
- Create a Formula, Type Boolean.
- In the property Text select the function ‘IsEqual’. Refer in Number 1 to the ‘RandomSelected 0-100 formula’ and in Number 2 to the ‘InputNumber’.
' - Formula, Type String
- Create a Formula, Type String, that consists of two nested 'If'-formulas:
- In the property Text select the logical formula 'If'. In the Logical Test you refer to the Formula ‘AnswerCorrect’. For’ Value_if_true’ enter the Fixed value text 'Correct'.
- In the ‘Value_if_false’, create another 'If' Formula. In the ‘Value if True’ you will fill in the Fixed value,’ Lower’. In the ‘Value if false’ you will fill in the Fixed value ‘Higher’. In the Logical text you create another formula, ‘IsGreater’. In Number 1 you refer to the fixed ‘InputNumber’, and in Number 2 to you refer to Formula ‘RandomSelected 0-100’.
- Pay attention to the Formula Types.
- Verify if your formula works correctly. Change the value of your Fixed 'InputNumber', and evaluate the Message formula to see if it gives the correct result.
You can download our solution for this assignment by clicking the image at the right. (Futurama 126.96.36.199)
Please note that you can very well have a different solution that is just as good as ours.