Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def commander(crew):
- """
- Actions to perform with each '1' obtained in the roll.
- It must ask if you want to change any crew member or re-roll
- available crew.
- It will need to validate all user input.
- It needs the crew array and returns it modified
- Parameters
- ----------
- crew : array
- Result of the dice roll.
- Returns
- -------
- crew : array
- Dice roll result modified by commander.
- """
- print('Commander available:')
- # The key pressed by the user is stored in 'c'.
- c = 'x'
- oldcrew = ''
- # Prompt until a valid value is obtained
- while c.lower() != 'c' and c.lower() != 'r':
- c = input("Do you want to change any members of your crew (c) \n \
- or re-roll de dice (r)? c/r\n")
- if c.lower() == 'c':
- # At this point 'c' is used to validate that the number is on the
- # 'crew' (an unavailable crew member cannot be changed)
- c = 'n'
- while c == 'n':
- # 'cont' stores the position in the array in which
- # the indicated value is located
- cont = 0
- oldcrew = int(input("Number of the crew member to be replaced:"))
- # If a 6 (scanner) has been indicated, it moves on to the next
- # iteration without doing anything else (continues requesting
- # a crew member until a valid value is received)
- if oldcrew == 6:
- continue
- for i in crew:
- if i == oldcrew:
- # If the entered value is available, the new value is
- # requested, making sure that a value between 2 and 5
- # was indicated.
- newcrew = 1
- while newcrew < 2 or newcrew > 5:
- newcrew = int(
- input("Value of the new crew member (2-5)"))
- crew[cont] = newcrew
- # 'c' is updated to stop prompting.
- c = ''
- break
- cont += 1
- elif c.lower() == 'r':
- ncrew = []
- cont = 0
- while cont < len(crew):
- if crew[cont] == 1 or crew[cont] == 6:
- ncrew.append(crew[cont])
- else:
- ncrew.append(randint(1, 6))
- cont += 1
- # Crew update
- crew = ncrew
- if c == 'c':
- print(f'Successfully changed {oldcrew} to {newcrew}')
- print(f"Nueva tripulaciΓ³n: {crew}")
- pretty_shown_crew(crew)
- return crew
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement