Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def valid_index(i, current_list):
- if 0 <= i < len(current_list):
- return True
- return False
- def fire(enemy_ship):
- index = int(command[1])
- damage = int(command[2])
- game_finished = False
- if valid_index(index, enemy_ship):
- warship[index] -= damage
- if warship[index] <= 0:
- game_finished = True
- print('You won! The enemy ship has sunken.')
- enemy_ship.clear()
- return enemy_ship
- def defend(our_ship):
- start_index = int(command[1])
- end_index = int(command[2])
- damage = int(command[3])
- game_finished = False
- if valid_index(start_index, our_ship) and valid_index(end_index, pirate_ship):
- for s in range(start_index, end_index + 1):
- our_ship[s] -= damage
- if our_ship[s] <= 0:
- game_finished = True
- break
- if game_finished:
- print("You lost! The pirate ship has sunken.")
- our_ship.clear()
- return our_ship
- def repair(our_ship):
- index = int(command[1])
- health = int(command[2])
- if valid_index(index, our_ship):
- if our_ship[index] + health <= max_health_capacity:
- our_ship[index] += health
- else:
- diff = max_health_capacity - our_ship[index]
- our_ship[index] += diff
- def status(our_ship):
- repair_sections = [s for s in our_ship if s < (max_health_capacity * 0.2)]
- return f"{len(repair_sections)} sections need repair."
- pirate_ship = list(map(int, input().split('>')))
- warship = list(map(int, input().split('>')))
- max_health_capacity = int(input())
- while True:
- game_ended = False
- command = input().split()
- command_name = command[0]
- if command_name == 'Retire':
- if command_name == 'Retire':
- print(f"Pirate ship status: {sum(pirate_ship)}\n"
- f"Warship status: {sum(warship)}")
- break
- elif command_name == 'Fire':
- fire(warship)
- if len(warship) == 0:
- break
- elif command_name == 'Defend':
- defend(pirate_ship)
- if len(pirate_ship) == 0:
- break
- elif command_name == 'Repair':
- repair(pirate_ship)
- elif command_name == 'Status':
- print(status(pirate_ship))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement