BRNSystems
440e0e2ecf
ships, abilities, ship pieces, map generator, ship placer separate pid writer to another module
74 lines
3.0 KiB
Python
74 lines
3.0 KiB
Python
|
|
ships = [
|
|
{"name": "aircraft_carrier", "size": 5, "lives": 1},
|
|
{"name": "bomber_ship", "size": 4, "lives": 1},
|
|
{"name": "sonar_ship", "size": 3, "lives": 1},
|
|
{"name": "submarine", "size": 2, "lives": 1},
|
|
{"name": "small_ship", "size": 1, "lives": 2}
|
|
]
|
|
|
|
abilities = [
|
|
{"name": "air strike", "description": "A strike that deals damage to all enemy's ships except submarines.", "ship_name": "aircraft_carrier", "round_period": 3, "ship": None},
|
|
{"name": "bomber", "description": "A bomber that allows you to shoot twice.", "round_period": 1, "ship_name": "bomber_ship", "ship": None},
|
|
{"name": "sonar", "description": "A sonar scan that reveals the location of enemy's ships.", "round_period": 5, "ship_name": "sonar_ship", "ship": None},
|
|
{"name": "torpedo", "description": "A torpedo that deals damage to all enemy's ships.", "round_period": 10, "ship_name": "submarine", "ship": None},
|
|
{"name": "spy", "description": "A spy that reveals the location of enemy's ships.", "round_period": 20, "ship_name": None, "ship": None},
|
|
{"name": "nuke", "description": "A nuclear strike that deals damage to all ships and terminates the game.", "round_period": 100, "ship_name": None, "ship": None},
|
|
]
|
|
|
|
#for all ships in abilities add ship_name to the description
|
|
def add_ship_name_to_abilities(abilities):
|
|
for ability in abilities:
|
|
if ability["ship_name"] is not None:
|
|
ability["description"] = ability["description"] + " It is fired from a " + ability["ship_name"].replace("_", " ") + "."
|
|
for ship in ships:
|
|
if ship["name"] == ability["ship_name"]:
|
|
ability["ship"] = ship
|
|
|
|
class Ability:
|
|
def __init__(self, name, description, round_period, ship_name):
|
|
self.name = name
|
|
self.description = description
|
|
self.round_period = round_period
|
|
self.ship_name = ship_name
|
|
self.current_round_period = 0
|
|
|
|
|
|
class Ship:
|
|
def __init__(self, type, direction, x, y):
|
|
self.type = type
|
|
self.direction = direction
|
|
self.x = x
|
|
self.y = y
|
|
for ship in ships:
|
|
if ship["name"] == type:
|
|
self.size = ship["size"]
|
|
self.lives = ship["lives"]
|
|
break
|
|
self.alive = True
|
|
self.pieces = []
|
|
|
|
class Ship_Piece:
|
|
def __init__(self, ship:Ship, x:int, y:int, index:int, orientation:str):
|
|
if ship == None:
|
|
raise Exception("Ship is None")
|
|
self.ship = ship
|
|
self.x = x
|
|
self.y = y
|
|
self.index = index
|
|
self.orientation = orientation
|
|
self.alive = False
|
|
self.ship.pieces.append(self)
|
|
def hit(self):
|
|
self.ship.lives -= 1
|
|
if self.ship.lives == 0:
|
|
self.ship.alive = False
|
|
ship_alive = False
|
|
for piece in self.ship.pieces:
|
|
if piece.alive:
|
|
ship_alive = True
|
|
break
|
|
self.ship.alive = ship_alive
|
|
return self.alive
|
|
|