Commit 6550d3d5 authored by Ralf's avatar Ralf
Browse files

Merge branch 'master' of

parents 6ee4826d db8881f6
......@@ -4,6 +4,7 @@ from enum import Enum
from functools import reduce
directions = {"north": (-1, 0), "east": (0, 1), "west": (0, -1), "south": (1, 0)}
directions_inv = {v:k for k, v in directions.items()}
class Labyrinth:
class GroundType(Enum):
from util import *
from thing import Thing
from labyrinth import directions as directionOffsets
from labyrinth import directions_inv as directions_t
goVerbs = ['go', 'walk']
sayVerbs = ['say', 'talk', 'scream']
......@@ -51,6 +52,32 @@ class Player(Thing):
def __str__(self):
return "another player"
def isMovedBy(self,pusher):
dx = self.field.column - pusher.field.column
dy = self.field.row - pusher.field.row
pushTarget = self.field.neighbor(dx=dx,dy=dy)
travelDistance = 1
while pushTarget is not None and not pushTarget.isWalkable():
pushTarget = pushTarget.neighbor(dx=dx,dy=dy)
if pushTarget is None:
self.send("Another player pushed you out of the playing field.\nYou are dead.\nGood Bye.")
assert travelDistance >= 1
if travelDistance == 1:
self.send("Another player pushed you to the "+directions_t[(dy,dx)]+".")
elif travelDistance == 2:
self.send("Another player pushed you SO HARD to the "+directions_t[(dy,dx)]+", that you flew right THROUGH A WALL!\nThis must have been a very rare occurence of quantum tunneling!\nYou feel a bit dizzy.")
self.send("Another player pushed you SO HARD to the "+directions_t[(dy,dx)]+", that you flew through a very thick, gamma-ray proof wall.\nYou are unsure about how you survived this, but quickly remember that you are in a completely virtual world with arbitrary phsyics. This makes you feel comfortable.")
playerToPush = None
for thing in pushTarget.things:
if thing != self and isinstance(thing, Player):
playerToPush = thing # yes, this may have higher speeds than one *grin*
self.send("After coming out of the wall with incredible speed, you hit another player, who is in turn pushed away by your momentum. Poor bastard..."),pushTarget,(lambda:playerToPush.isMovedBy(self) if playerToPush else None))
# high(er)-level functions
def readCmd(self, cmd):"Someone [{1}] wrote '{0}'".format(cmd, self.uid))
......@@ -72,7 +99,14 @@ class Player(Thing):
if target is None or not target.isWalkable():
self.send("Sorry, you cannot go there")
return, target)
playerToPush = None
for thing in target.things:
if thing != self and isinstance(thing, Player):
playerToPush = thing
self.send("By moving to the "+direction[0]+" you pushed another player away.")), target, (lambda:playerToPush.isMovedBy(self) if playerToPush else None))
elif verb in sayVerbs:
msg = " ".join(words[1:])
for dx, dy in [(0, 0)]+directionOffsets.values():
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment