home
·
contact
·
privacy
projects
/
plomrogue2-experiments
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0f7c3e5
)
Replenish food resources automatically.
author
Christian Heller
<c.heller@plomlompom.de>
Sun, 21 Apr 2019 19:19:32 +0000
(21:19 +0200)
committer
Christian Heller
<c.heller@plomlompom.de>
Sun, 21 Apr 2019 19:19:32 +0000
(21:19 +0200)
new/plomrogue/game.py
patch
|
blob
|
history
diff --git
a/new/plomrogue/game.py
b/new/plomrogue/game.py
index da8fe1a49962928d10fec5424baab8669db8a2ba..103d705b90287ed51a1ab32ddeadacfc743b638a 100755
(executable)
--- a/
new/plomrogue/game.py
+++ b/
new/plomrogue/game.py
@@
-13,6
+13,7
@@
from plomrogue.parser import Parser
from plomrogue.io import GameIO
from plomrogue.misc import quote, stringify_yx
from plomrogue.things import Thing, ThingMonster, ThingHuman, ThingFood
from plomrogue.io import GameIO
from plomrogue.misc import quote, stringify_yx
from plomrogue.things import Thing, ThingMonster, ThingHuman, ThingFood
+import random
@@
-80,17
+81,26
@@
class World(WorldBase):
for thing in self.things[player_i+1:]:
thing.proceed()
self.turn += 1
for thing in self.things[player_i+1:]:
thing.proceed()
self.turn += 1
+ for pos in self.map_:
+ if self.map_[pos] == '.' and \
+ len(self.things_at_pos(pos)) == 0 and \
+ random.random() > 0.999:
+ self.add_thing_at('food', pos)
for thing in self.things[:player_i]:
thing.proceed()
self.player.proceed(is_AI=False)
if self.player.task is None or not self.player_is_alive:
break
for thing in self.things[:player_i]:
thing.proceed()
self.player.proceed(is_AI=False)
if self.player.task is None or not self.player_is_alive:
break
+ def add_thing_at(self, type_, pos):
+ t = self.game.thing_types[type_](self)
+ t.position = pos
+ self.things += [t]
+ return t
+
def make_new(self, yx, seed):
def make_new(self, yx, seed):
- import random
- def add_thing(type_):
- t = self.game.thing_types[type_](self)
+ def add_thing_at_random(type_):
while True:
new_pos = (random.randint(0, yx[0] -1),
random.randint(0, yx[1] - 1))
while True:
new_pos = (random.randint(0, yx[0] -1),
random.randint(0, yx[1] - 1))
@@
-98,10
+108,7
@@
class World(WorldBase):
continue
if len(self.things_at_pos(new_pos)) > 0:
continue
continue
if len(self.things_at_pos(new_pos)) > 0:
continue
- break
- t.position = new_pos
- self.things += [t]
- return t
+ return self.add_thing_at(type_, new_pos)
self.things = []
random.seed(seed)
self.things = []
random.seed(seed)
@@
-113,14
+120,14
@@
class World(WorldBase):
continue
self.map_[pos] = random.choice(('.', '.', '.', '.', 'x'))
continue
self.map_[pos] = random.choice(('.', '.', '.', '.', 'x'))
- player = add_thing('human')
+ player = add_thing
_at_random
('human')
self.player_id = player.id_
self.player_id = player.id_
- add_thing('monster')
- add_thing('monster')
- add_thing('food')
- add_thing('food')
- add_thing('food')
- add_thing('food')
+ add_thing
_at_random
('monster')
+ add_thing
_at_random
('monster')
+ add_thing
_at_random
('food')
+ add_thing
_at_random
('food')
+ add_thing
_at_random
('food')
+ add_thing
_at_random
('food')
return 'success'
return 'success'