Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program (carpet_fishing.py) to implement Dilbert\'s Carpet Fishing Game.

ID: 3576965 • Letter: W

Question

Write a program (carpet_fishing.py) to implement Dilbert's Carpet Fishing Game.

Let's call Dilbert's cubicle floor "Carpet Sea". Carpet Sea is divided into a grid of N x N cells. Your program should randomly select a cell in the carpet grid to place a fish and then prompt the user to enter the cell in which they want to drop their fishing line. Every M minutes, reel in the fishing line and check if the user caught a fish (i.e. they dropped their line in the same cell as the randomly placed fish). Repeat this process:

Randomly place a fish

Prompt for a fishing line location

Wait M minutes

Reel in the line and check if the fish was caught

until the user wants to quit.

Program Details

Your code should include N and M variables and be able to handle different integer values of N (2 <= N <= 9) and M (M >= 15); however, for simplicity, you may hard-code N = 2 and M = 60 in your program instead of prompting the user for values for N and M. If you do this, Carpet Sea will be a 2 x 2 grid and the user will reel in the line once every hour.

Simulation of Time

To save on time, we are going to simulate M minutes by S real-time seconds, where 1 real-time second is equivalent to 1/60 simulated minutes:

S=M160S=M160

For example, in the original comic, Dilbert checks his fishing line once every hour (M = 60 minutes). So our program will check the fishing line once every second (S = 1) in real-time:

S=60160=1S=60160=1

We can have our program "wait" for S seconds by importing the time module and calling time.sleep(S).

Carpet Sea

The underlying representation of Carpet Sea should include the following classes:

Coordinate: represents the coordinates of a cell in the carpet grid. Coordinate should contain the following attributes and methods (at a minimum):

row: a row location (an integer)

col: a column location (an integer)

__init__(): accepts values to assign to the attributes.

__str__(): returns a string representation of a Coordinate, i.e. (0, 0)

Cell: represents a cell in the carpet grid. Cell should contain the following attributes and methods (at a minimum):

location_coords: the location of this cell on the board (a Coordinate object).

contains_line: whether or not this cell contains the user's fishing line (a bool)

fish: the fish contained in this cell (a string)

__init__(): accepts values to assign to the attributes.

__str__(): returns a string representation of a Cell, i.e. return the contents of this cell (e.g. " " (nothing), "F" (fish), "*" (line), "F*" (fish and line)

CarpetSea: represents the carpet grid. CarpetSea should contain the following attributes and methods (at a minimum):

N: dimension of board (an integer)

grid: the N x N grid (a 2-Dimensional list of Cell objects)

available_fish: species of fish in the Carpet Sea (a list of strings)

__init__(): accepts a value to assign to the attribute N.

__str__(): returns a string representation of a CarpetSea, i.e. display the organized contents of each cell. Rows and columns should be labeled with indices.

randomly_place_fish(): randomly selects coordinates of a cell and randomly selects a fish from the available_fish list attribute. Marks the cell as containing the fish.

drop_fishing_line(): accepts the location of the user's fishing line (a Coordinate object). Marks the cell as containing the line.

check_fish_caught(): If the cell containing the fishing line also contains a fish, returns the fish. Otherwise, return False.

Carpet Fishing Game Stats

Keep track of the game progress in a GameStats class. When the user wants to quit playing Carpet Fishing, report the user's game stats, including:

Total number of fish caught

Total (simulated) time played in terms of hours

Average number of fish caught per hour

Be sure to define __init__() and __str__() methods for GameStats!

Additional Details

Display instructions at the beginning of the program, including a description of the fish in Carpet Sea.

Prompt the user for the following values during game play:

Cell coordinates: 2 space-separated integers representing the coordinates where the user would like to drop their line. Validate each coordinate is between [0, N - 1] inclusive.

Menu choice: after checking if a fish was caught, prompt the user to determine if they want to keep fishing. Validate the user enters "y" to keep playing or "q" to quit.

Display the Carpet Sea grid after checking if a fish was caught.

You are free to decide which functions/methods to define beyond the ones listed above to solve this problem. Break the problem into tasks and build your solution accordingly. You will be graded on your approach. Ask the instructor or your TA for help with this!

Example Run

Here is an example run of the program:

-------------

This is my strter code:

class Coordinate:
'''
  
'''
def __init__(self, row, col):
'''
  
'''
self.row = row
self.col = col
def __str__(self):
'''
  
'''
return ("(%d, %d)" %(self.row, self.col))
  
class Cell:
'''
  
'''
def __init__(self, row, col):
'''
  
'''
self.coords = Coordinate(row, col)
  
def main():
'''
  
'''
N = 2
grid = []
for i in range(N):
row = []
for j in range(N):
cell = Cell(i, j)
row.append(cell)
grid.append(row)
print(grid)
  
main()

-----

I need some help to edit it to work.

Explanation / Answer

""" PROJECT NAME : chegprograms AUTHOR : ravi FILE NAME : Coordinate.py DATE : 22/12/16 """ import random class Coordinate: def __init__(self, row, col): """ :param row: :param col: :return: """ self.row = row self.col = col def __str__(self): return "(" + str(self.row) + ", " + str(self.col) + ")" class Cell: def __init__(self, location_coord, contains_line, fish): """ :param location_coord: :param contains_line: :param fish: :return: """ self.location_coords = location_coord self.contains_line = contains_line self.fish = fish def __str__(self): return self.fish class CarpetSea: def __init__(self,n): self.N = n self.grid = [[""*self.N] for x in range(self.N)] self.available_fish = ["M","S","T","H"]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote