home · contact · privacy
Add "item" thing type differentiated from animate thing types.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 21 Feb 2019 12:19:33 +0000 (13:19 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 21 Feb 2019 12:19:33 +0000 (13:19 +0100)
new/example_client.py
new/plomrogue/game.py
new/plomrogue/tasks.py
new/plomrogue/things.py

index 039d8de6bc134f9835c4f70a130a3a4879fb7890..8a0de5060f9c1bc7a144132e7fce64efa5492c84 100755 (executable)
@@ -172,6 +172,8 @@ class Game:
             symbol = '@'
         elif type_ == 'monster':
             symbol = 'm'
+        elif type_ == 'item':
+            symbol = 'i'
         return symbol
 
 
@@ -292,7 +294,10 @@ class MapWidget(Widget):
             terrain_as_list = list(self.tui.game.world.map_.terrain[:])
             for t in self.tui.game.world.things:
                 pos_i = self.tui.game.world.map_.get_position_index(t.position)
-                terrain_as_list[pos_i] = self.tui.game.symbol_for_type(t.type_)
+                symbol = self.tui.game.symbol_for_type(t.type_)
+                if symbol in {'i'} and terrain_as_list[pos_i] in {'@', 'm'}:
+                    continue
+                terrain_as_list[pos_i] = symbol
             return ''.join(terrain_as_list)
 
         def pad_or_cut_x(lines):
@@ -315,6 +320,8 @@ class MapWidget(Widget):
             for c in ''.join(lines):
                 if c in {'@', 'm'}:
                     chars_with_attrs += [(c, curses.color_pair(1))]
+                elif c == 'i':
+                    chars_with_attrs += [(c, curses.color_pair(4))]
                 elif c == '.':
                     chars_with_attrs += [(c, curses.color_pair(2))]
                 elif c in {'x', 'X', '#'}:
@@ -365,6 +372,7 @@ class TUI:
         curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_RED)
         curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)
         curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE)
+        curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_YELLOW)
         curses.curs_set(False)  # hide cursor
         self.to_send = []
         self.edit = EditWidget(self, (0, 6), (1, 14), check_tui = ['edit'])
index a031406b19e32a36432bea01131df305df0a3c5f..dcc6c3dffd917fc46b257877a0db9cc3982f4d77 100755 (executable)
@@ -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, ThingMonster, ThingHuman
+from plomrogue.things import Thing, ThingMonster, ThingHuman, ThingItem
 
 
 
@@ -83,7 +83,10 @@ class World(WorldBase):
         npc = self.game.thing_types['monster'](self, 1)
         npc.position = [random.randint(0, yx[0] -1),
                         random.randint(0, yx[1] -1)]
-        self.things = [player, npc]
+        item = self.game.thing_types['item'](self, 2)
+        item.position = [random.randint(0, yx[0] -1),
+                         random.randint(0, yx[1] -1)]
+        self.things = [player, npc, item]
         return 'success'
 
 
@@ -107,7 +110,9 @@ class Game:
         self.world_type = World
         self.world = self.world_type(self)
         self.thing_type = Thing
-        self.thing_types = {'human': ThingHuman, 'monster': ThingMonster}
+        self.thing_types = {'human': ThingHuman,
+                            'monster': ThingMonster,
+                            'item': ThingItem}
 
     def get_string_options(self, string_option_type):
         if string_option_type == 'direction':
index fe41e419ca32fba8961823dcada0572e95a9e651..262576273f4726301777fe0297f7e0b441d4c0a8 100644 (file)
@@ -40,7 +40,7 @@ class Task_MOVE(Task):
         if self.thing.world.map_[test_pos] != '.':
             raise GameError('%s would move into illegal terrain' % self.thing.id_)
         for t in self.thing.world.things:
-            if t.position == test_pos:
+            if t.blocking and t.position == test_pos:
                 raise GameError('%s would move into other thing' % self.thing.id_)
 
     def do(self):
index 2decc6709f747113e888edc9327f406c8e43739c..386dbc4522071e059cb80b73647c80d289053ee3 100644 (file)
@@ -13,6 +13,20 @@ class ThingBase:
 
 
 class Thing(ThingBase):
+    blocking = False
+
+    def proceed(self):
+        pass
+
+
+
+class ThingItem(Thing):
+    type_ = 'item'
+
+
+
+class ThingAnimate(Thing):
+    blocking = True
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -129,10 +143,10 @@ class Thing(ThingBase):
 
 
 
-class ThingHuman(Thing):
+class ThingHuman(ThingAnimate):
     type_ = 'human'
 
 
 
-class ThingMonster(Thing):
+class ThingMonster(ThingAnimate):
     type_ = 'monster'