Today we will practice arrays and loops.
Pick either one of the Emoji Drawing or Multi-Dice Game exercise and work through from Base to your preferred level of comfort, before attempting the other exercise.
{% tabs %} {% tab title="Emoji Drawing" %}
Use loops to create an app that draws emojis into the grey box. See here for how to input Emoji on Windows and here for how to input emoji on Mac.
See an example of all problems here.
Number of Characters
The user will enter a number of characters to display on the screen.
For example, if the user enters 4 they will see this:
Square
The user will enter the dimensions of a square to display on the screen.
Use a loop within a loop and the <br>
HTML tag in your output to create the square.
For example, if the user enters 4 they will see this:
Triangle
The user will enter the dimensions of a triangle to display on the screen.
Use a loop within a loop, a conditional and the <br>
HTML tag in your output to create the triangle.
For example, if the user enters 4 they will see this:
Outline Square
The user will enter the dimensions of a square to display on the screen. The square is outlined by a different character.
For example, if the user enters 4 they will see this:
Center Square
The user will enter the dimensions of a square to display on the screen. The square is outlined by a different character and there is another different character in the center. The app doesn't allow dimensions that will not allow the center character.
For example, if the user enters 5 they will see this:
{% tab title="Multi-Dice Game" %}
More dice rolling and guessing! See an example of all problems here.
- Create a dice-guessing game with a variable number of dice rolls determined by the user.
- The game will have 2 modes.
- In the 1st mode, the user will enter the number of dice they wish to roll.
- In the 2nd mode, the user will enter a guess that will apply to all dice rolls. For example, if the user has chosen to roll 2 dice in Mode 1 and guesses 4 in Mode 2, that guess of 4 will apply to both Dice 1 and Dice 2.
- After the user guesses, the program will run a loop where the number of iterations is the number of dice rolls from Mode 1. Each loop iteration will roll a dice and verify if the user has won.
- If the user guesses correctly for any of the dice rolls, the user wins.
- The game keeps track of and outputs the overall win-loss record.
Multi-Round Multi-Dice Game
- Alter the previous multi-dice game such that the user plays 4 rounds in the 2nd mode.
- After the user enters their guess in Mode 2, the program enters a loop that runs 4 rounds.
- Within each round the game will roll the number of dice the user specified and compare them with the single user guess.
- If the user guessed correctly for any dice rolls in a round, they win that round.
- The game will continue to output overall win-loss record, where each of the 4 rounds count as wins or losses.
Two Player Multi-Round Multi-Dice Game
- Change the game to support 2 players, starting with Player 1.
- The gameplay follows the multi-round multi-dice game above. After each player's turn, that player will have won between 0 and 4 rounds, because each player plays 4 rounds per turn.
- The game alternates between players indefinitely and outputs win-loss record for each player.
Multi-Player Multi-Round Multi-Dice Game
Change the game to ask how many players are playing the game. Players will take turns playing the game as above. {% endtab %} {% endtabs %}
Here is the reference solution to the Drawing and Dice Game exercises. Please only view the reference solution for each exercise after you have attempted the exercise yourself. Note that there are many ways to implement these solutions and the reference solution is only 1 way.