Advertisement
Eddy_S

Untitled

May 29th, 2020
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. def grid_to_string(grid, player):
  2.     """Turns a grid and player into a string
  3.  
  4.    Arguments:
  5.        grid -- list of list of Cells
  6.        player -- a Player with water buckets
  7.  
  8.    Returns:
  9.        string: A string representation of the grid and player.
  10.    """
  11.     string = ""
  12.     for i, ls in enumerate(grid):
  13.         for j, cells in enumerate(ls):
  14.             if i == player.row and j == player.col:
  15.                 string += player.display
  16.             else:
  17.                 string += cells.display
  18.         string += "\n"
  19.     if player.num_water_buckets == 1:
  20.         string += f"\nYou have {player.num_water_buckets} water bucket."
  21.     else:
  22.         string += f"\nYou have {player.num_water_buckets} water buckets."
  23.     return string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement