Advertisement
angeldp

commander

Jan 2nd, 2024
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. def commander(crew):
  2.     """
  3.    Actions to perform with each '1' obtained in the roll.
  4.    It must ask if you want to change any crew member or re-roll
  5.    available crew.
  6.    It will need to validate all user input.
  7.    It needs the crew array and returns it modified
  8.  
  9.    Parameters
  10.    ----------
  11.    crew : array
  12.        Result of the dice roll.
  13.  
  14.    Returns
  15.    -------
  16.    crew : array
  17.        Dice roll result modified by commander.
  18.  
  19.    """
  20.  
  21.     print('Commander available:')
  22.     # The key pressed by the user is stored in 'c'.
  23.     c = 'x'
  24.     oldcrew = ''
  25.     # Prompt until a valid value is obtained
  26.     while c.lower() != 'c' and c.lower() != 'r':
  27.         c = input("Do you want to change any members of your crew (c) \n \
  28.        or re-roll de dice (r)? c/r\n")
  29.     if c.lower() == 'c':
  30.         # At this point 'c' is used to validate that the number is on the
  31.         # 'crew' (an unavailable crew member cannot be changed)
  32.         c = 'n'
  33.         while c == 'n':
  34.             # 'cont' stores the position in the array in which
  35.             # the indicated value is located
  36.             cont = 0
  37.             oldcrew = int(input("Number of the crew member to be replaced:"))
  38.             # If a 6 (scanner) has been indicated, it moves on to the next
  39.             # iteration without doing anything else (continues requesting
  40.             # a crew member until a valid value is received)
  41.             if oldcrew == 6:
  42.                 continue
  43.             for i in crew:
  44.                 if i == oldcrew:
  45.                     # If the entered value is available, the new value is
  46.                     # requested, making sure that a value between 2 and 5
  47.                     # was indicated.
  48.                     newcrew = 1
  49.                     while newcrew < 2 or newcrew > 5:
  50.                         newcrew = int(
  51.                             input("Value of the new crew member (2-5)"))
  52.                     crew[cont] = newcrew
  53.                     # 'c' is updated to stop prompting.
  54.                     c = ''
  55.                     break
  56.                 cont += 1
  57.     elif c.lower() == 'r':
  58.         ncrew = []
  59.         cont = 0
  60.         while cont < len(crew):
  61.             if crew[cont] == 1 or crew[cont] == 6:
  62.                 ncrew.append(crew[cont])
  63.             else:
  64.                 ncrew.append(randint(1, 6))
  65.             cont += 1
  66.         # Crew update
  67.         crew = ncrew
  68.     if c == 'c':
  69.         print(f'Successfully changed {oldcrew} to {newcrew}')
  70.     print(f"Nueva tripulaciΓ³n: {crew}")
  71.     pretty_shown_crew(crew)
  72.     return crew
Tags: DeepSpace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement