Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import random EMPTY = 'e' TREASURE = 't' MONSTER = 'm' VENOM=v SWORD = 's' POTION ='p' whatToAddInGrid = (TREASURE, TREASURE, TREASURE, TREASURE, TREASURE, MONSTER,

import random EMPTY = 'e' TREASURE = 't' MONSTER = 'm' VENOM="v" SWORD = 's' POTION ='p' whatToAddInGrid = (TREASURE, TREASURE, TREASURE, TREASURE, TREASURE, MONSTER, MONSTER, MONSTER, MONSTER, MONSTER, SWORD, SWORD, SWORD, POTION, POTION, POTION, VENOM, VENOM, VENOM) NROWS_IN_GRID = 6 NCOLS_IN_GRID = 8 grid = [] for r in range(0, NROWS_IN_GRID): #0-5 aRow = [] for c in range(0, NCOLS_IN_GRID):#0-7 aRow.append(EMPTY) grid.append(aRow) def findEmptyCell(aGrid, nRows, nCols): #Find a random starting cell that is empty. while True: row = random.randrange(nRows) col = random.randrange(nCols) if(aGrid[row][col] == EMPTY): return row, col for item in whatToAddInGrid: rowRandom, colRandom = findEmptyCell(grid, NROWS_IN_GRID, NCOLS_IN_GRID) grid[rowRandom][colRandom] = item for row in grid: print(row) #Setting the starting cell startRow, startCol = findEmptyCell(grid, NROWS_IN_GRID, NCOLS_IN_GRID) print('Starting at row:', startRow, 'col:', startCol) while True: #move the user around direction = input('Press L, U, R, D to move: ').lower() print() if(direction == 'l'): if(startCol == 0): startCol = NCOLS_IN_GRID - 1 else: startCol -= 1 elif (direction == 'r'): if(startCol == NCOLS_IN_GRID - 1): startCol = 0 else: startCol += 1 elif(direction == 'u'): if(startRow == 0): startRow = NROWS_IN_GRID - 1 else: startRow -= 1 elif(direction == 'd'): if(startRow == NROWS_IN_GRID - 1): startRow = 0 else: startRow += 1 else: print('Invalid move. Quitting the game.') break foundInCell = grid[startRow][startCol] print('Now at row', startRow, ' col:', startCol, ' cell contains:', foundInCell)

I need to write code in python to define the 4 rules based on the code above.

image text in transcribed

b Mail M Mall + Help V VOID MInbo 0 Modi Smx G 1430 23 ramming%20Languages%20i/module 10-lab-assignment-part-1.pdf RITK Library (D) Watch RIT MyCourses R RIT Library 3 Google Apps at RIT start.rit.edu SIS 1/1 - 100% + There are some rules for this game that you need to implement: 1. The user will gain 1 point when finding a TREASURE spot. This should increase the current score of the user by 1 (starting from O initially). Each time the user finds a TREASURE, the updated score should be printed. The cell that had TREASURE should be set to EMPTY. 2. Finding a MONSTER will end the game unless the user has previously collected a SWORD. If the user has a SWORD item, then he will spend the SWORD for killing the MONSTOR. The cell that had MONSTER should be set to EMPTY. The user can continue playing the game. 3. Finding a VENOM will end the game unless the user has previously collected a POTION. If the user has a POTION item, then he will spend the POTION for recovering from the VENOM. The cell that had VENOM should be set to EMPTY. The user can continue playing the game. 4. Finding a POTION or SWORD means collecting them for using them later against VENOM or MONSTER. Having multiple instances of the same item is not allowed. For example, if the user already holds a POTION, finding a second POTION will not make any difference and the user will be assumed to hold still only one POTION. The same applies to SWORD. These rules still do not make this game complete. You are welcome to add more rules as you wish. For this lab assignment you will be graded based on the four rules specified above

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

Step: 3

blur-text-image

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 Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago