Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The goal is to create a code for implementing a Columns game using pygame Your program will read its input via the Python shell (i.e.,

The goal is to create a code for implementing a Columns game using pygame

Your program will read its input via the Python shell (i.e., using the built-in input() function), printing no prompts to a user with no extraneous output other than precisely what is specified below. The intent here is not to write a user-friendly user interface; what you're actually doing is building a tool for testing your game mechanics, which we'll then be using to automatically test them. So it is vital that your program reads inputs and write outputs precisely as specified below. You can freely assume that the input will match the specification described; we will not be testing your program on any inputs that don't match the specification.

First, your program needs to know the size of the field. It will always be a rectangle, but the number of rows and columns can vary.

First, your program reads a line of input specifying the number of rows in the field. You can assume this will be no less than 4.

Next, your program reads a line of input specifying the number of columns in the field. You can assume this will be no less than 3.

At any given time, the field contains jewels that are one of seven colors. The colors are represented by these uppercase letters (and only these letters): S, T, V, W, X, Y, Z. In both the input and output, we'll use these seven letters to denote the seven colors.

Now, your program needs to know what jewels are in the field to begin with. There are two situations: We might want to start with an empty field, or we might want to specify the contents of the field in the input.

If the field is to begin empty, the word EMPTY will appear alone on the next line of input.

If instead we want to specify the contents of the field in the input, the word CONTENTS will appear alone on the next line of input. Given that there are r rows and c columns in the field, there would then be r lines of input, each of which will contain exactly c characters; these characters represent the contents of each of the field's cells to start with.

For a cell that should contain a jewel of some color, an uppercase letter describing each color will be used.

For a cell that should be empty, a space will be used instead.

Note that when we're specifying the contents of the field explictly, the spaces will always be present in the input for every cell that's empty; the program should expect to read exactly the correct number of characters.

At this point, the game is ready to begin. From here, we will repeatedly do two things: Display the field, then read a command from the user.

The rules for displaying the field are:Given that the field has r rows, the field will be displayed as a total of r + 1 lines of output. The first r will correspond to the r rows of the field, which each row displayed like this:The vertical bar character '|', followed by three characters for each of the c columns in that row, followed by another vertical bar character '|'. For each column in that row, the three characters will be:

Three spaces if the cell is empty

A space, followed by an uppercase letter if the cell contains a jewel that has been frozen.

A left bracket character '[', followed by an uppercase letter, followed by a right bracket character ']' if the cell contains a jewel that is part of the faller (if any).

A vertical bar character '|', followed by an uppercase letter, followed by another vertical bar character '|' if the cell contains a jewel that is part of a faller that has landed but not yet frozen.

An asterisk character '*', followed by an uppercase letter, followed by another asterisk character '*' if the cell contains a jewel that has frozen and has been recognized as a match.

After the last row of the field, a space, followed by 3c dashes, followed by another space is displayed.

The commands that you would read are:A blank line, which is a crude representation of the passage of time. (In our complete game, this would happen without any input; instead, when a certain amount of time passes, we would see the appropriate effect.)

If there is a faller present, it falls; if there is a faller that has landed (and has not been moved so that it is no longer in a landed position), it freezes; and so on.

F, followed by an integer that is a column number (the columns are numbered 1 through c, if there are c columns), followed by a space, followed by three uppercase letters (representing colors), each of these things separated by spaces (e.g., F 1 S T V). This means to create a faller in column 1, with a jewel of color S on the top, a jewel of color T below it, and a jewel of color V below that.

The faller begins with only the bottommost of the three jewels visible. See the example outputs below for more details.

Note that there can only be one faller at a time, so this command has no effect if there is a faller that has not already been frozen.

R alone on a line, which rotates the faller, if there is one. If there is no faller currently, this command has no effect. Note, though, that it is possible to rotate a faller that has landed but not yet frozen.

< alone on a line, which moves the faller one column to the left, if there is one (and if it not blocked by jewels already frozen on the field or by the edge of the field). If there is no faller or the faller can't be moved to the left, this command has no effect. Note, though, that it is possible to move a faller that has landed but not yet frozen, which can take it out of its "landed" status (if it moves to a column with nothing underneath it).

> alone on a line, which moves the faller one column to the right, if there is one (and if it not blocked by jewels already frozen on the field or by the edge of the field). If there is no faller or the faller can't be moved to the right, this command has no effect. Note, though, that it is possible to move a faller that has landed but not yet frozen, which can take it out of its "landed" status (if it moves to a column with nothing underneath it).

Q alone on a line, which means that to quit the program.

There are two ways for the program to end:

If the user specifies the command Q, the program ends, with no additional output being printed.

When a faller freezes without all three of its jewels being visible in the field (for example, if it lands on a jewel that's two rows below the top and then freezes), the game ends, so the program ends, as well. In that case, you would print GAME OVER before ending the program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions