Beispiel #1
0
 def generateOcean(self):
     ocean = Ocean()
     for shipTuple in sorted(Ship.ship_types.items(),
                             key=lambda x: x[1],
                             reverse=True):
         ship_added = False
         while not ship_added:
             chosenY = random.randint(0, 9)
             chosenX = random.randint(0, 9)
             isVertical = bool(random.getrandbits(1))
             ship = Ship(shipTuple[0], isVertical, chosenY, chosenX)
             ship_added = ocean.insert_ship(ship)
     return ocean
class Player:

    def __init__(self, name):
        self.name = name
        self.ocean = Ocean()


    def add_ship(self, ship):
        return self.ocean.insert_ship(ship)

    def has_lost(self):
        if not self.ocean.ships:
            return True
        return False

    def take_damage(self, row, column):
        return self.ocean.make_hit(row, column)

    def __str__(self):
        return "Player: " + self.name