X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new%2Fplomrogue%2Fgame.py;h=a5ce4740417af3b2f83a104b2177418a28983a8d;hb=c7ed14237418f807473b11e49f17a878ff344f97;hp=d244582deed90cb227bd5caa5cc7dc5e55f4d036;hpb=7d8ed36999f496383de39a76aee8dfb8e1bfbef7;p=plomrogue2-experiments diff --git a/new/plomrogue/game.py b/new/plomrogue/game.py index d244582..a5ce474 100755 --- a/new/plomrogue/game.py +++ b/new/plomrogue/game.py @@ -8,7 +8,7 @@ from plomrogue.mapping import MapHex from plomrogue.parser import Parser from plomrogue.io import GameIO from plomrogue.misc import quote, stringify_yx -from plomrogue.things import Thing +from plomrogue.things import Thing, ThingMonster, ThingHuman, ThingItem @@ -37,6 +37,11 @@ class World(WorldBase): super().__init__(*args, **kwargs) self.player_id = 0 + def new_thing_id(self): + if len(self.things) == 0: + return 0 + return self.things[-1].id_ + 1 + def new_map(self, yx): self.map_ = self.game.map_type(yx) @@ -69,6 +74,15 @@ class World(WorldBase): def make_new(self, yx, seed): import random + + def add_thing(type_): + t = self.game.thing_types[type_](self) + t.position = [random.randint(0, yx[0] -1), + random.randint(0, yx[1] - 1)] + self.things += [t] + return t + + self.things = [] random.seed(seed) self.turn = 0 self.new_map(yx) @@ -77,15 +91,13 @@ class World(WorldBase): self.map_[pos] = '#' continue self.map_[pos] = random.choice(('.', '.', '.', '.', 'x')) - player = self.game.thing_type(self, 0) - player.type_ = 'human' - player.position = [random.randint(0, yx[0] -1), - random.randint(0, yx[1] - 1)] - npc = self.game.thing_type(self, 1) - npc.type_ = 'monster' - npc.position = [random.randint(0, yx[0] -1), - random.randint(0, yx[1] -1)] - self.things = [player, npc] + + player = add_thing('human') + self.player_id = player.id_ + add_thing('monster') + add_thing('monster') + add_thing('item') + add_thing('item') return 'success' @@ -109,10 +121,15 @@ class Game: self.world_type = World self.world = self.world_type(self) self.thing_type = Thing + self.thing_types = {'human': ThingHuman, + 'monster': ThingMonster, + 'item': ThingItem} def get_string_options(self, string_option_type): if string_option_type == 'direction': return self.world.map_.get_directions() + elif string_option_type == 'thingtype': + return list(self.thing_types.keys()) return None def send_gamestate(self, connection_id=None):