Question: For this question, you will write a simple game that uses stacks of colorful red, blue and green blocks. Playing the game involves two separate

For this question, you will write a simple game that uses stacks of colorful red, blue and green blocks.
Playing the game involves two separate stacks of blocks. On the left-hand side is a stack of blocks we will call the main stack. On the right-hand side is a stack of blocks which we will call the scoring stack. The scoring stack is initially empty; the players goal is to repeatedly stack up blocks of the same color on the scoring stack.
Below is how your program should behave in more detail.
Display the main stack of blocks somewhere on the left-hand side of the screen. When your program starts, the main stack should contain 3 blocks with randomly-determined colors (red, blue or green for each block). The stack should be placed flush against the bottom of the canvas, with the blocks directly on top of each other. (See Figure 2 below.)
Display the players score somewhere on the canvas. Initially the score is 0.
When the player presses the b key (for new Block): A new block with a randomly-determined color (red, green, or blue) is placed on top of the main stack. Doing this costs the player 1 point (i.e. their score goes DOWN by 1).
When the player presses the s key (for Score): The top block of the main stack should be moved to the top of the scoring stack. However, this operation is NOT ALLOWED if the block being moved does not match the color of all of the blocks already in the scoring stack (in this case, pressing s just does nothing). Pressing s also does nothing if the main stack is empty. If there are ever 3 blocks on the scoring stack after a move, the player scores 5 points and the scoring stack is cleared.
When the player presses the d key (for Destroy): Destroy the top block of the main stack

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!