示例#1
0
def Take(item):
    if item == "all":
        itemlist = []
        taken = 0
        output = ""
        for i in locations.Get(items.Get("me").Location()).contents:
            if items.Get(i).canTake is True and i != "me":
                if items.Get(i).Adjective() is not None:
                    itemlist.append(
                        items.Get(i).Adjective().capitalize() + " " +
                        items.Get(i).description["short"] + ": " +
                        items.Get(i).Do("get"))
                else:
                    itemlist.append(
                        items.Get(i).description["short"].capitalize() + ": " +
                        items.Get(i).Do("get"))
        if len(itemlist) > 0:
            for i in itemlist:
                output += i + "\n"
            return output
        else:
            return "There's nothing here to take."
    elif game.Settings().Current("object") in [
            "up", "u", "down", "d", "in", "out"
    ]:
        Go(game.Settings().Current("object"))
    elif items.Get(item).Location() == "me":
        return "You're already carrying it."
    elif items.Get(item).canTake is True and PlayerHas(item, True):
        items.Get(item).Location("me")
        items.Get(item).Description("initial", None)
        return "Taken."
    else:
        # Okay, the item isn't in the room, it isn't "all", and we're not already carrying it. Let's check the other objects in the room to see if they have the object.
        return "You can't take that."
示例#2
0
def Stats():
    print "Player location: " + items.Get("me").Location()
    print "Moves taken: " + str(game.Settings().Moves())
    print "Points: " + str(
        game.Settings().Points()) + " points (out of a possible " + str(
            game.Settings().MaxPoints()) + ")"
    print "Last command: " + str(Game().lastcommand)
    if game.Settings().Current("object"):
        try:
            print
            print "Location of '" + game.Settings().Current("object") + "':",
            if items.Get(game.Settings().Current("object")).Location():
                print items.Get(game.Settings().Current("object")).Location()
            else:
                print "The null world"
        except:
            print
            print "Item '" + game.Settings().Current(
                "object") + "' does not exist."
    else:
        print
        print "Active daemons:"
        for i in game.Settings().daemons:
            print "\t" + i + " (" + str(
                game.Settings().daemons[i].countdown) + ")"
示例#3
0
def RestoreGameProcess():
    try:
        game.Load(game.Settings().Current("object"))
        return "Restored \"" + game.Settings().Current(
            "object") + "\".\n" + Look()
    except:
        return "Failed to restore \"" + game.Settings().Current(
            "object") + "\". Perhaps the file does not exist?"
示例#4
0
def SaveGameProcess():
    try:
        game.Save(game.Settings().Current("object"))
        return "Saved \"" + game.Settings().Current("object") + "\"."
    except:
        return "Failed to save \"" + game.Settings().Current(
            "object"
        ) + "\". You might not have permission to create that file on this computer."
示例#5
0
def SaveGame():
    if game.Settings().Current("object"):
        return SaveGameProcess()
    else:
        return Capture(
            "What would you like to name your saved game (this will overwrite any saved game with the same name)?",
            "saveas %input%")
示例#6
0
def RestoreGame():
    if game.Settings().Current("object"):
        return RestoreGameProcess()
    else:
        return Capture(
            "What is the name of the saved game you would like to restore?",
            "restoreas %input%")
示例#7
0
def Talk(key=None):
    continuecapture = False
    output = ""
    if key is None:
        try:
            oldkey = game.Settings().Current("input").lower().split(" ")[1]
            choice = game.Settings().Current("input").lower().split(" ")[2]
            result = {
                'a': 0,
                'b': 1,
                'c': 2,
                'd': 3,
                'e': 4,
                'f': 5,
                'g': 6,
                'h': 7,
                'i': 8,
                'j': 9
            }[choice]
            key = dialogue[oldkey]["options"][result].values()[0]
        except KeyError:
            output += "\nThat was an invalid option."
            key = oldkey
        except IndexError:
            output += "\nThat was an invalid option."
            key = oldkey
    try:
        output += "\n" + dialogue[key]["text"]
        if dialogue[key]["go"]:
            # if dialogue[key]["speak"]:
            # output += "\n" + dialogue[key]["text"]
            key = dialogue[key]["go"]
    except:
        raise
    if dialogue[key]["options"]:
        continuecapture = True
        output += "\n(Chose an option:)\n"
        keycount = 0
        alpha = "abcdefghij"
    for i in dialogue[key]["options"]:
        output += "     " + alpha[keycount] + ") " + i.keys()[0] + "\n"
        keycount += 1
    # output = output.encode("utf-8")
    if continuecapture:
        return scripts.Capture(output, "sys_talk " + key + " %input%")
    else:
        return output
示例#8
0
def StartGame():
	global story
	import dialogue
	dialogue.Init() # Loads the dialogue module -- needs game.softdata to be complete first, so this is called by the client
	exec Game().storyscripts in globals()
	story = StoryScripts()
	if not game.Settings().Started():
		intro = Game().Intro() + "\n<center><b><big>" + Game().Name() + "</big></b>"
		if Game().Author() != "Unknown": intro += "<br/>By " + Game().Author()
		intro += "</center>\n" + scripts.Go(Game().StartRoom()) + "\n(For instructions on how to play, type 'help' and hit enter)"
		Game().Started(True)
		Game().Response(intro)
		if Game().Response().find("{") is not -1:
			try:
				Game().Response(SplitCommand(Game().Response()))
			except:
				game.Log("Error with splitting a command.")
示例#9
0
    def Describe(self):
        output = "<br/><medium>" + str(
            self.description["short"]) + "</medium>\n\n"
        if self.description["long"]:
            output += self.description["long"]
        if game.Settings().showexits is True:
            output += "Exits are"
            list = ""
            for i in self.connections.keys():
                list += " " + i + ","
            output += scripts.Listify(list)
            output += "."
        if len(self.contents) > 1:
            initialoutput = []
            noinitialoutput = []
            for i in self.contents:
                if items.Get(
                        i).description["initial"] is not None and items.Get(
                            i).isSilent is False:
                    initialoutput.append(items.Get(i).Description("initial"))
                elif items.Get(i).name != "me" and items.Get(
                        i).isSilent is False:
                    noinitialoutput.append(items.Get(i).name)
            if initialoutput:
                for i in initialoutput:
                    if i != "me":
                        output += "\n" + i
            if noinitialoutput:
                output += "\n\nHere, you find "
                itemlist = ""
                for i in noinitialoutput:
                    itemlist += " " + items.Get(i).Grammar("a") + " "
                    # if items.Get(i).Adjective() is not None:
                    # itemlist += items.Get(i).Adjective() + " "
                    itemlist += items.Get(i).Description("short") + ", "
                output += scripts.Listify(itemlist)


#					output += "\n\t"+items.Get(i).Grammar("a").capitalize()+ " "+i
        output += "\n\n"
        return output
示例#10
0
def Capture(prompt, script):
    game.Settings().capturemode = True
    game.Settings().captureprocess = script
    return prompt
示例#11
0
def Game():
    return game.Settings()
示例#12
0
def Go(direction=None):
    output = ""
    if direction is None and game.Settings().Current("object"):
        direction = game.Settings().Current("object")
        if direction == "enter":
            direction = "i"
        if direction == "exit":
            direction = "o"
        if direction in ["forward", "forwards"]:
            direction = "f"
        if direction in ["back", "backwards"]:
            direction = "b"
        direction = direction[0]
    elif direction is None and game.Settings().Current("verb") == "climb":
        direction = "u"
    elif direction is None:
        direction = "f"
    if direction in [
            "n", "s", "e", "w", "u", "d", "i", "o", "l", "r", "f", "b"
    ]:
        if direction == "f":
            if game.Settings().Facing() in ["n", "u", "d"]:
                output += "\n(north)"
            elif game.Settings().Facing() == "s":
                output += "\n(south)"
            elif game.Settings().Facing() == "e":
                output += "\n(east)"
            elif game.Settings().Facing() == "w":
                output += "\n(west)"
            direction = game.Settings().Facing()
        if direction == "b":
            if game.Settings().Facing() == "n":
                direction = "s"
                output += "\n(south)"
            elif game.Settings().Facing() == "s":
                direction = "n"
                output += "\n(north)"
            elif game.Settings().Facing() == "e":
                direction = "w"
                output += "\n(west)"
            elif game.Settings().Facing() == "w":
                direction = "e"
                output += "\n(east)"
            elif game.Settings().Facing() == "u":
                direction = "d"
                output += "\n(down)"
            elif game.Settings().Facing() == "d":
                direction = "u"
                output += "\n(up)"
            elif game.Settings().Facing() == "i":
                direction = "o"
                output += "\n(outt)"
            elif game.Settings().Facing() == "o":
                direction = "i"
                output += "\n(in)"
            else:
                direction = "s"
                output += "\n(south)"
        if direction == "l":
            if game.Settings().Facing() == "n":
                direction = "w"
                output += "\n(west)"
            elif game.Settings().Facing() == "s":
                direction = "e"
                output += "\n(east)"
            elif game.Settings().Facing() == "e":
                direction = "n"
                output += "\n(north)"
            elif game.Settings().Facing() == "w":
                direction = "s"
                output += "\n(south)"
            else:
                direction = "w"
                output += "\n(west)"
        if direction == "r":
            if game.Settings().Facing() == "n":
                direction = "e"
                output += "\n(east)"
            elif game.Settings().Facing() == "s":
                direction = "w"
                output += "\n(west)"
            elif game.Settings().Facing() == "e":
                direction = "s"
                output += "\n(south)"
            elif game.Settings().Facing() == "w":
                direction = "n"
                output += "\n(north)"
            else:
                direction = "e"
                output += "\n(east)"
        currentlocation = items.Get("me").Location()
        try:  # Check to see if everything is blocked
            return locations.Get(currentlocation).blockedconnections["a"]
        except:  # So far so good
            try:  # Check to see if that direction is blocked
                return locations.Get(
                    currentlocation).blockedconnections[direction]
            except:  # Coast is clear!
                try:
                    if locations.Get(currentlocation).Description(
                            "exit") is not None:
                        output += "\n" + locations.Get(
                            currentlocation).Description("exit")
                    items.Get("me").Location(
                        locations.Get(currentlocation).connections[direction])
                    for i in locations.Get(currentlocation).contents:
                        if items.Get(i).followPlayer is True:
                            items.Get(i).Location(items.Get("me").Location())
                            if items.Get(i).Description("follow") is not None:
                                output += "\n" + items.Get(i).Description(
                                    "follow")
                    output += "\n" + Look()
                    if locations.Get(items.Get("me").Location()).Description(
                            "firstenter") is not None:
                        output += "\n" + locations.Get(
                            items.Get("me").Location()).Description(
                                "firstenter")
                        locations.Get(items.Get("me").Location()).Description(
                            "firstenter", "")
                    if locations.Get(items.Get("me").Location()).Description(
                            "enter") is not None:
                        output += "\n" + locations.Get(
                            items.Get("me").Location()).Description("enter")
                    game.Settings().Facing(direction)
                    return output
                except:
                    # raise
                    return "You can't go in that direction."
    else:
        try:
            currentlocation = items.Get("me").Location()
            items.Get("me").Location(locations.Get(direction).name)
            if currentlocation:
                if locations.Get(currentlocation).Description(
                        "exit") is not None:
                    output += locations.Get(currentlocation).Description(
                        "exit") + "\n"
                for i in locations.Get(currentlocation).contents:
                    if items.Get(i).followPlayer is True:
                        items.Get(i).Location(items.Get("me").Location())
                        if items.Get(i).Description("follow") is not None:
                            output += "\n" + items.Get(i).Description("follow")
            output += "\n" + Look()
            if locations.Get(items.Get("me").Location()).Description(
                    "firstenter") is not None:
                output += locations.Get(items.Get(
                    "me").Location()).Description("firstenter") + "\n"
                locations.Get(items.Get("me").Location()).Description(
                    "firstenter", "")
            if locations.Get(items.Get("me").Location()).Description(
                    "enter") is not None:
                output += locations.Get(
                    items.Get("me").Location()).Description("enter") + "\n"
            game.Settings().Facing("n")
            return output
        except:
            return "You can't go in that direction."
示例#13
0
def Game(): return game.Settings()

ignoreautotake = ["look", "get", "touch"]
示例#14
0
def Disambig(objecttype):
	# Wow, this is an eyesore. This is invoked when the parser can't narrow down the object being referred to by the player to a single item.
	# Type can be "object" or "idobject"
	if objecttype == "object" or objecttype == "idobject":
		try:
			ambig = Indices(directory, game.Settings().current[objecttype])
			if len(ambig) > 1:
				# Hmm, we have conflicting indirect objects. Let's try to figure out which one's being referred to.
				possibilities = []
				for i in ambig: # Finds objects that are currently in the room
					if type(objects[i]) is str:
						if Get(objects[i]).Location() == Get("me").Location() or Get(objects[i]).Location() == "me": 
							possibilities.append({"id": i, "name": Get(objects[i]).name, "adjective": Get(objects[i]).Adjective()})
						elif Get(objects[i]).Location() in locations.Get(Get("me").Location()).contents:
							possibilities.append({"id": i, "name": Get(objects[i]).name, "adjective": Get(objects[i]).Adjective()})
					else:
						if objects[i].Location() == Get("me").Location() or objects[i].Location() == "me": # Rules out anything not in the room
							possibilities.append({"id": i, "name": objects[i].name, "adjective": objects[i].Adjective()})
						elif objects[i].Location() in locations.Get(Get("me").Location()).contents:
							possibilities.append({"id": i, "name": objects[i].name, "adjective": objects[i].Adjective()})
				if len(possibilities) == 0:
					return "You don't see that here." + daemonoutput
				# Okay, we have some possibilities. Let's see if any adjectives line up.
				for i in range(len(possibilities)):
					if str(game.Settings().current[objecttype+"adj"]) == possibilities[i]["adjective"]:
						game.Settings().current[objecttype] = possibilities[i]["name"]
						raise
				if len(possibilities) == 1:
					game.Settings().current[objecttype] = possibilities[0]["name"]
					raise
				else:
					captureprompt = "Which " + game.Settings().current[objecttype] + ": "
					if len(possibilities) == 2:
						captureprompt += possibilities[0]["adjective"] + " or " + possibilities[1]["adjective"] + "?"
					else:
						for i in range(len(possibilities)):
							if i < len(possibilities)-2:
								captureprompt += possibilities[i]["adjective"] + ", "
						captureprompt += possibilities[(len(possibilities)-2)]["adjective"] + " or " + possibilities[(len(possibilities)-1)]["adjective"] + "?"
					# We'll need to rebuild the input a bit to fit in the new adjective
					if objecttype == "object":
						captureprocess = game.Settings().current["verb"] + " %input% " + game.Settings().current["object"]
						if game.Settings().current["idobject"]:
							if game.Settings().current["idobjectadj"]:
								captureprocess += " " + game.Settings().current["idobjectadj"] + " " + game.Settings().current["idobject"]
							else:
								captureprocess += " " + game.Settings().current["idobject"]
						return scripts.Capture(captureprompt, captureprocess)
					if objecttype == "idobject":
						captureprocess = game.Settings().current["verb"]
						if game.Settings().current["objectadj"]:
							captureprocess += " " + game.Settings().current["objectadj"]
						captureprocess += " " + game.Settings().current["object"] + " to %input% " + game.Settings().current["idobject"]
						return scripts.Capture(captureprompt, captureprocess)
			else:
				# No more conflicts.
				return None
		except:
			return None
	else:
		game.Log("Incorrect object type: '" + type + "'")
		return None
示例#15
0
                            queue.append(n)
                            came_from[n] = node
                next_node = came_from[self.game.squad.pos]
                result.insert(0, next_node)
                while next_node != self.pos:
                    next_node = came_from[next_node]
                    result.insert(0, next_node)
                try:
                    self.pos = result[1]
                except IndexError:
                    pass

        if self.pos == self.game.squad.pos:
            if self.game.squad.power / len(self.game.squad.player_list) > 5:
                logger.info("Minotaur is dead")
                self.game.text_display.print("Zabiliście Minotaura!")
                self.kill()
            else:
                self.game.squad.dead = True
                logger.info("Player is dead")
                self.game.text_display.print("Nie żyjecie!")


if __name__ == "__main__":
    settings = game.Settings(20, 30, 30)

    minotaur = Minotaur(settings)

    minotaur.pos_x = random.randrange(0, settings.width)
    minotaur.pos_y = random.randrange(0, settings.height)
示例#16
0
def Game(): return game.Settings()

objects = []
示例#17
0
def Game(): return game.Settings()

directobjectlist = ["through", "into", "in", "out", "on", "off", "with", "to", "for", "from", "at", "around"]
示例#18
0
import sys, pygame, os, game, led
import screenobjects
from gravsensor.adxl345 import adxl345

pygame.init()
pygame.joystick.init()
pygame.mouse.set_visible(0)

game = game.Settings()

#Initiate the LED
led = led.Led()
led.setColor(game.COLORS_TO_EYES[1])

# Used to manage how fast the screen updates
clock = pygame.time.Clock()
joysticks = [
    pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())
]

# Get count of joysticks
joystick_count = pygame.joystick.get_count()
print("Number of joysticks: {}".format(joystick_count))

#Setup the accelorometer
accel = adxl345()

#Check the joystick is plugged in and initiate it
try:
    pygame.joystick.Joystick(0)
except NameError: