Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Faller:
def __init__(self, col, color1, color2, color3):
self.col = col
self._color1 = color1
self._color2 = color2
self._color3 = color3
self._faller = self._generateFaller()
self.is_frozen = False
self.is_landing = False
self._faller_count = 0
self._bottom_count = 0

def getFaller(self) -> list:
return self._faller

def getCol(self) -> int:
return self.col

def rotateFaller(self):
self._faller = self._faller[-1:] + self._faller[-3:-1]

def _generateFaller(self) -> list:
faller = []
faller.append(self._color1)
faller.append(self._color2)
faller.append(self._color3)
return faller

def addFrozen(self):
self.is_frozen = True

def addLanding(self):
self.is_landing = True


#tick -> ui

class GameBoard:
def __init__(self, row: int, column: int, field: str):
self._row = row
self._column = column
self._field = field
self._board = self.getField()
#match, land


def getRow(self) -> int:
return self._row
def getColumn(self) -> int:
return self._column
def getList(self):
return self._board

def getField(self) -> [[str]]:
if self._field == 'EMPTY':
self._board = self._generateEmptyField()
return self._board
elif self._field == 'CONTENTS':
self._board = self._generateContentField() #wip
return self._board
###
def startFall(self, block):
self._board[0][int(block.col) -1] = '[' + block._faller[2] + ']'
block._bottom_count = 1
block._faller_count = 1

def falling(self, block):
if block._faller_count < self._row:
if block._faller_count > 0:
self._board[block._faller_count][int(block.col) -1] = '[' + block._faller[2] + ']'
self._board[block._faller_count-1][int(block.col) -1] = '[' + block._faller[1] + ']'
if block._faller_count > 1:
self._board[block._faller_count][int(block.col) -1] = '[' + block._faller[2] + ']'
self._board[block._faller_count-1][int(block.col) -1] = '[' + block._faller[1] + ']'
self._board[block._faller_count-2][int(block.col) -1] = '[' + block._faller[0] + ']'
if block._faller_count > 2:
self._board[block._faller_count-3][int(block.col) -1] = ' '
block._faller_count += 1
block._bottom_count += 1
self.landing(block)

def landing(self, block):
'''
block - faller object
self._faller_count - the row # of the lowest jewel
'''
# TODO: Implement check if above jewel
if block._bottom_count == self._row and (self._board[block._bottom_count-1][int(block.col) -1] != ' '):
self._board[block._bottom_count-1][int(block.col) -1] = '|' + block._faller[2] + '|'
self._board[block._bottom_count-2][int(block.col) -1] = '|' + block._faller[1] + '|'
self._board[block._bottom_count-3][int(block.col) -1] = '|' + block._faller[0] + '|'
block.addLanding() ###
return True
return False



def checkBlock(self, block):
self._board[block._bottom_count-1][int(block.col) -1] = ' ' + block._faller[2] + ' '
self._board[block._bottom_count-2][int(block.col) -1] = ' ' + block._faller[1] + ' '
self._board[block._bottom_count-3][int(block.col) -1] = ' ' + block._faller[0] + ' '
block._bottom_count = 0
block.addFrozen()

def updateBlock(self, block):
if '[' in self._board[block._bottom_count-1][int(block.col) -1]:
self._board[block._bottom_count-1][int(block.col) -1] = '[' + block._faller[2] + ']'
self._board[block._bottom_count-2][int(block.col) -1] = '[' + block._faller[1] + ']'
self._board[block._bottom_count-3][int(block.col) -1] = '[' + block._faller[0] + ']'
else:
self._board[block._bottom_count-1][int(block.col) -1] = '|' + block._faller[2] + '|'
self._board[block._bottom_count-2][int(block.col) -1] = '|' + block._faller[1] + '|'
self._board[block._bottom_count-3][int(block.col) -1] = '|' + block._faller[0] + '|'

###move right, left, landing, frozen, rotate

###

def _generateEmptyField(self):
field = []
for col in range(self._row):
field.append([])
for row in range(self._column):
field[-1].append(' ') #3 spaces
return field

def _generateContentField(self): #wip
content = []
jewel = []
for col in range(self._row):
jewel.append(input())
for color in jewel:
temp = []
for t in color:
slot = ' ' + t + ' '
temp.append(slot)
content.append(temp)
return content


def displayField(game: GameBoard):
display = game.getList()
for space in display:
d = []
for tile in space:
d.append(tile)
print('|' + ''.join(d) + '|')
print(' ' + '-'*3*game.getColumn() + ' ')


if __name__ == '__main__':
print('Please enter how many rows.')
user_row = int(input())
print('Please enter how many columns.')
user_column = int(input())
print('Please enter EMPTY or CONTENTS for the option to fill the field or not.')
start = input()
board = GameBoard(user_row, user_column, start)
displayField(board)
####
while True:
user_create = input()
block = Faller(user_create[2], user_create[4], user_create[6], user_create[8])
print(block)
count = 0
board.startFall(block)
displayField(board)
while not block.is_frozen:
u = input()
if u == "R" and block.is_landing:
block.rotateFaller()
board.updateBlock(block)
displayField(board)
elif u == 'R' and not block.is_landing:
block.rotateFaller()
board.updateBlock(block)
displayField(board)
elif u == '' and block.is_landing:
board.checkBlock(block)
displayField(board)
else:
board.falling(block)
displayField(board)
#if the top one is not in the board yet
#check last one for < >

Add a comment
Know the answer?
Add Answer to:
The goal is to create a code for implementing a Columns game using pygame Your program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Row and columns sum Create a java program that: Input: Receive as input in command line...

    Row and columns sum Create a java program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (m x n) Compute: Compute the sum for each row and store the results in a...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

  • Write a program to Simulate a game of tic tac toe in c#

    Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1)    ...

  • using c++ program the following The Assignment For this assignment, we are asking you to implement...

    using c++ program the following The Assignment For this assignment, we are asking you to implement Conway's Game of Life using a two-dimensional array as a grid in which to store the cells. Live cells are denoted as * characters, dead cells are denoted by the character. Input As input, you will be given a line containing the number of rows, number of columns, and number of generations to simulate in the form mng followed by m lines containing the...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT