コード例 #1
0
def mapper(litX, bigX, litY, bigY, mapL, cRoom):
    drawL = []
    distX = (-1) * litX
    distY = (-1) * litY
    for j in range(litY, bigY + 1):
        drawL.append([])
        for i in range(litX, bigX + 1):
            if (i, j) in mapL:
                drawL[j + distY].append("O")
            else:
                drawL[j + distY].append(" ")
    dis = (bigX - litX - 2) // 2
    if dis < 2:
        dis = 2
    print(dis * "=" + " MAP " + dis * "=")
    print()
    for j in range(bigY, litY - 1, -1):
        spaceLine = " "
        print(" ", end="")
        for i in range(litX, bigX + 1):
            if cRoom.location == (i, j):
                print(colors.fg.red, end='')
            else:
                print(colors.fg.cyan, end='')
            print(drawL[j + distY][i + distX], end='')
            print(colors.fg.cyan, end='')
            if (drawL[j + distY][i + distX]
                    == "O") and ((i + distX) != (len(drawL[j + distY]) - 1)):
                if "east" in room.loadRoom("room" + str(i) + "_" +
                                           str(j)).possibleDirections.values():
                    print(colors.fg.cyan + "--", end='')
                else:
                    print("  ", end='')
            else:
                print("  ", end='')

            if (drawL[j + distY][i + distX] == "O") and ((j + distY) != 0):
                if "south" in room.loadRoom(
                        "room" + str(i) + "_" +
                        str(j)).possibleDirections.values():
                    spaceLine += "|  "
                else:
                    spaceLine += "   "
            else:
                spaceLine += "   "

        print("", end="\n")
        print(spaceLine)
    print(colors.reset, end='')
    print(dis * "=" + " MAP " + dis * "=")
コード例 #2
0
ファイル: npc.py プロジェクト: CiaranHagen/MUD-Game
 def move(self):
     possibleDirections = []
     for c in room.loadRoom(
             'room' + str(self.location[0]) + '_' +
             str(self.location[1])).possibleDirections.values():
         possibleDirections.append(c)
     direction = random.choice(possibleDirections)
     if direction in possibleDirections:
         if direction == ('north' or 'n'):
             self.location = [self.location[0], self.location[1] + 1]
         elif direction == ('south' or 's'):
             self.location = [self.location[0], self.location[1] - 1]
         elif direction == ('east' or 'e'):
             self.location = [self.location[0] + 1, self.location[1]]
         elif direction == ('west' or 'w'):
             self.location = [self.location[0] - 1, self.location[1]]
         elif direction == 'northwest':
             self.location = [self.location[0] - 1, self.location[1] + 1]
         elif direction == 'southwest':
             self.location = [self.location[0] - 1, self.location[1] - 1]
         elif direction == 'northeast':
             self.location = [self.location[0] + 1, self.location[1] + 1]
         elif direction == 'southeast':
             self.location = [self.location[0] + 1, self.location[1] - 1]
     self.save()
     return
コード例 #3
0
ファイル: character.py プロジェクト: CiaranHagen/MUD-Game
 def move(self, direction):
     cRoomName = 'room' + str(self.location[0]) + '_' + str(
         self.location[1])
     cRoom = room.loadRoom(cRoomName)
     if direction in cRoom.possibleDirections:
         direction = cRoom.possibleDirections[direction]
         if direction == ('north' or 'n'):
             self.location = [self.location[0], self.location[1] + 1]
         elif direction == ('south' or 's'):
             self.location = [self.location[0], self.location[1] - 1]
         elif direction == ('east' or 'e'):
             self.location = [self.location[0] + 1, self.location[1]]
         elif direction == ('west' or 'w'):
             self.location = [self.location[0] - 1, self.location[1]]
         elif direction == 'northwest':
             self.location = [self.location[0] - 1, self.location[1] + 1]
         elif direction == 'southwest':
             self.location = [self.location[0] - 1, self.location[1] - 1]
         elif direction == 'northeast':
             self.location = [self.location[0] + 1, self.location[1] + 1]
         elif direction == 'southeast':
             self.location = [self.location[0] + 1, self.location[1] - 1]
         elif direction == "":
             return
         else:
             print(
                 "The creators of this game have f***** up and entered a non-existent actual direction. Go complain..."
             )
     return
コード例 #4
0
def loadCRoom():
    roomName = "room" + str(cChar.location[0]) + "_" + str(cChar.location[1])
    cRoom = room.loadRoom(roomName)
    return cRoom
コード例 #5
0
def adminer(cPlayer, cChar, cRoom, roomL):
    print(
        "Commands are: room, mob, map, quit, createitem, additem, addtoroom, addroomdir , changestats, crown <username>"
    )
    while True:
        print()
        try:
            admIn = input(colors.fg.red + ">> " + colors.fg.pink)
            print(colors.reset, end='')
            commAdmin = ""
            splitMin = admIn.split(" ")
            for w in splitMin:
                w = w.lower()
            commAdmin = splitMin[0]
            print()
            if commAdmin == "room":
                coord = input(
                    "Please enter the coordinates (seperate by space): ")
                room.newRoom(int(coord.split(' ')[0]),
                             int(coord.split(' ')[1]))
                roomL = room.loadRooms()
                """
                elif commAdmin == "mob":
                    print("Creating new mob...")
                    npc.newMob()
                """
            elif commAdmin == "map":
                mapL = []
                print(cChar.location)
                for o in roomL:
                    oCoord = o[4:]
                    x = oCoord.split("_")[0]
                    y = oCoord.split("_")[1]
                    mapL.append((int(x), int(y)))
                bigY = max(mapL, key=operator.itemgetter(1))[1]
                bigX = max(mapL, key=operator.itemgetter(0))[0]
                litY = min(mapL, key=operator.itemgetter(1))[1]
                litX = min(mapL, key=operator.itemgetter(0))[0]
                mapper(litX, bigX, litY, bigY, mapL, cRoom)

            elif commAdmin == "createitem":
                kind = input("weapon, armor or shield: ").lower()
                if kind == "weapon":
                    item.newWeapon()
                elif kind == "shield":
                    item.newShield()
                elif kind == "armor":
                    item.newArmor()

            elif commAdmin == "changestats":
                changestats = 1
                while changestats == 1:
                    print(colors.fg.orange + 'Stats: ' + colors.fg.cyan +
                          str(cChar.stats))
                    print(colors.fg.orange + 'MaxHealth: ' + colors.fg.green +
                          str(cChar.maxhealth))
                    print()
                    print(colors.reset, end='')
                    print('what stat do you wish to modify ? (' +
                          colors.fg.orange + 'strength' + colors.reset +
                          ' / ' + colors.fg.orange + 'agility' + colors.reset +
                          ' / ' + colors.fg.orange + 'wit' + colors.reset +
                          ' / ' + colors.fg.orange + 'luck' + colors.reset +
                          ' / ' + colors.fg.green + 'maxhealth' +
                          colors.reset + ')')
                    choice = input('>').lower()

                    if choice in ['strength', 'agility', 'wit', 'luck']:
                        confirm = 1
                        while confirm == 1:
                            print('your ' + colors.fg.orange + str(choice) +
                                  colors.reset + ' is: ' + colors.fg.cyan +
                                  str(cChar.stats[str(choice)]) + colors.reset)
                            print()
                            print('input new value')
                            value = input('>')
                            try:
                                if (int(value) >= 0):
                                    cChar.stats[str(choice)] = int(value)
                                    print('your new ' + colors.fg.orange +
                                          str(choice) + colors.reset +
                                          ' is: ' + colors.fg.cyan +
                                          str(cChar.stats[str(choice)]) +
                                          colors.reset)
                                    answer = ''
                                    while answer not in [
                                            'y', 'yes', 'n', 'no'
                                    ]:
                                        print()
                                        print(
                                            'do you wish to continue modifying your stats ?'
                                        )
                                        print("[" + colors.fg.green + "yes" +
                                              colors.reset + "/" +
                                              colors.fg.red + "no" +
                                              colors.reset + "]")
                                        answer = input('>').lower()
                                        if answer in ['y', 'yes']:
                                            changestats = 1
                                            confirm = 0
                                        elif answer in ['n', 'no']:
                                            changestats = 0
                                            confirm = 0
                                            Print('Quitting ...')
                                        elif answer not in [
                                                'y', 'yes', 'n', 'no'
                                        ]:
                                            print(
                                                str(answer) +
                                                ' is not a valid input, try again :'
                                            )
                            except Exception as e:
                                print(e)
                                print(
                                    "Very clever... C'mon, I need numbers dude! N U M B E R S!"
                                )

                    if choice in ['maxhealth']:
                        confirm = 1
                        while confirm == 1:
                            print('your ' + colors.fg.orange + str(choice) +
                                  colors.reset + ' is: ' + colors.fg.cyan +
                                  str(cChar.maxhealth) + colors.reset)
                            print()
                            print('input new value')
                            value = input('>')
                            try:
                                if (int(value) >= 0):
                                    cChar.maxhealth = int(value)
                                    cChar.health = cChar.maxhealth
                                    print('your new ' + colors.fg.orange +
                                          str(choice) + colors.reset +
                                          ' is: ' + colors.fg.cyan +
                                          str(cChar.maxhealth) + colors.reset)
                                    answer = ''
                                    while answer not in [
                                            'y', 'yes', 'n', 'no'
                                    ]:
                                        print()
                                        print(
                                            'do you wish to continue modifying your stats ?'
                                        )
                                        print("[" + colors.fg.green + "yes" +
                                              colors.reset + "/" +
                                              colors.fg.red + "no" +
                                              colors.reset + "]")
                                        answer = input('>').lower()
                                        if answer in ['y', 'yes']:
                                            changestats = 1
                                            confirm = 0
                                        elif answer in ['n', 'no']:
                                            changestats = 0
                                            confirm = 0
                                            Print('Quitting ...')
                                        elif answer not in [
                                                'y', 'yes', 'n', 'no'
                                        ]:
                                            print(
                                                str(answer) +
                                                ' is not a valid input, try again :'
                                            )
                            except Exception as e:
                                print(e)
                                print(
                                    "Very clever... C'mon, I need numbers dude! N U M B E R S!"
                                )

                    elif choice in ['q', 'quit']:
                        quit = 1
                        while quit == 1:
                            print('Are you sure you wish to quit ?')
                            print("[" + colors.fg.green + "yes" +
                                  colors.reset + "/" + colors.fg.red + "no" +
                                  colors.reset + "]")
                            answer = input('>').lower()
                            if answer in ['y', 'yes']:
                                print('Quitting ...')
                                quit = 0
                                changestats = 0
                                confirm = 0
                                continue
                            elif answer in ['n', 'no']:
                                quit = 0
                                changestats = 1
                                confirm = 0
                                continue

                    elif choice not in [
                            'q', 'quit', 'strength', 'agility', 'wit', 'luck',
                            'health'
                    ]:
                        print(
                            'The status ' + colors.fg.orange + str(choice) +
                            colors.reset +
                            ' is not known to me or the game ... try again or enter'
                            + colors.fg.orange + ' quit' + colors.reset +
                            ' to abort')
                        continue

            elif commAdmin == "additem":
                kind = input("weapon, armor or shield: ")
                if kind == "weapon":
                    kind = 'wpn'
                elif kind == "shield":
                    kind = 'shd'
                elif kind == "armor":
                    kind = 'arm'
                print('Input the name of the item')
                name = input('>')
                cChar.inventory[name] = item.loadItem(name, kind).description
                print()
                if len(cChar.inventory) > 0:
                    items = cChar.inventory
                    print(colors.fg.orange + "Inventory: ")
                    print("-----------" + colors.fg.cyan)
                    for key in items:
                        print(str(key)[0].upper() + str(key)[1:])
                    print(colors.reset, end='')
                    print()
                else:
                    print("Your inventory is empty")
                    print()

            elif commAdmin == "addtoroom":
                rom = input("Room coords (<x> <y>): ")
                itemName = input("Item-name: ").lower()
                descr = input("Enter a description: ")
                addToInv = input("Add to inventory (y/n): ")
                coords = rom.split(" ")
                room.loadRoom("room" + coords[0] + "_" +
                              coords[1]).stuffDescription[itemName] = descr
                if addToInv == "y":
                    rom = room.loadRoom("room" + coords[0] + "_" + coords[1])
                    rom.inventory[itemName] = descr
                    rom.save()
                print("Added " + itemName + " to " + "room" + coords[0] + "_" +
                      coords[1] + ".")

            elif commAdmin == "addroomdir":
                rom = input("Room coords (<x> <y>): ")
                pointerDir = input("Direction: ")
                actualDir = input("Whereto: ")
                coords = rom.split(" ")
                rom = room.loadRoom("room" + coords[0] + "_" + coords[1])
                rom.possibleDirections[pointerDir] = actualDir
                rom.save()

            elif commAdmin == "crown":
                cPlayer.admin = True
                cPlayer.save()
                if cPlayer.admin:
                    print("Player " + cPlayer.username + " is now admin.")

            elif commAdmin == "quit":
                print()
                print("Returning to game...")
                print()
                return
            else:
                print(
                    "Possible commands are \"room\", \"mob\", \"map\", \"createitem\", \"additem\", \"addtoroom\", \"changestats\", \"crown <username>\" and \"quit\"."
                )
        except Exception as e:
            print(e)
            print(
                "Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee... Samfing diiidn't wörk."
            )
コード例 #6
0
def fight(char, npc):
    draw(npc)
    damageToll = 0
    while True:
        print()
        action = input("\033[31mo\033[33m-\033[90m(\033[37m==> ")
        print()
        if action in ["hit", "slash", "lunge", "stab"]:
            if item.loadItem(char.onPerson["weapon"], "wpn").health > 0:
                damageToll += hit(char, npc)
                time.sleep(1)
                if npc.health <= 0:
                    char.exp += npc.level * 50
                    levelBefore = char.level
                    character.checkLevel(char)
                    print('\033[08m')
                    os.system("clear")
                    print('\033[0m')
                    print()
                    print("You are victorious!")
                    print()
                    drawDead(npc)
                    print("Gained " + str(npc.level * 50) + " EXP.")
                    if char.level > levelBefore:
                        time.sleep(1)
                        job.jobLevelUp(char)
                    os.system("rm ../data/npcs/mob_" + npc.name + ".txt")
                    del npc
                    return "mob"
            else:
                print("Your weapon is broken and useless. You desperately try to punch a better equipped opponent, but fail miserably.")

        elif action in ["flee", "retreat", "run", "turn tail"]:
            chance = random.randint(0, 2 + char.stats["luck"])
            if chance == 0:
                print("You manage to flee the scene and sit in a corner, shivering like the coward that you are.")
                char.move(random.choice(room.loadRoom('room' + str(char.location[0]) + '_' + str(char.location[1])).possibleDirections.values()))
                return "none"
            else:
                print("The enemy hit you back into the room.")

        elif action in ["dodge", "roll", "parry", "evade"]:
            if char.job == 'rogue' and char.level >= 2: #(@lvl 2, rogue gains passive evasion buff)
                chance = random.randint(0, 2 + char.stats["agility"])
                if chance in range(1 + npc.level*2 - char.level, 2 + char.stats["agility"]):
                    print("You evade the enemy's attack.")
                    continue
                else:
                    chance = random.randint(0, 2 + char.stats["agility"])
                    if chance in range(1 + npc.level*2 - char.level, 2 + char.stats["agility"]):
                        print("You evade the enemy's attack.")
                        continue
                    else:
                        print("Bad luck. The enemy hit you anyways.")
            elif not char.job == 'rogue':
                chance = random.randint(0, 2 + char.stats["agility"])
                if chance in range(1 + npc.level*2 - char.level, 2 + char.stats["agility"]):
                    print("You evade the enemy's attack.")
                    continue
                else:
                    print("Bad luck. The enemy hit you anyways.")
        else:
            print("That is not an option...")
            continue
        hit(npc, char)
        if char.health <= 0:
            print("You have died.")
            char.location = [0,0]
            char.health = 500
            print()
            print("You have returned to the start-room.")
            print("".center(os.get_terminal_size().columns, "-"))
            return "char"