示例#1
0
def getValueOfMaterial(material):
    data = jsonHandler.getDataFromFile("mapData.json")
    materialListOfDictionaries = data["ids"]
    for i in range(len(materialDictionaries)):
        if materialListOfDictionaries[i]["name"] == material:
            value = materialListOfDictionaries[i]["cost"]
    return value
示例#2
0
def handleGetQuest(GETR):
    data = jsonHandler.getDataFromFile("quests.json")
    ID = random.randrange(0, len(data))
    if GETR.getActiveQuest() != None:
        print(cs("You already have an Active Quest", "Red"))
        return
    GETR.setActiveQuest(ID)
    print(cs(data[ID]["textToUser"], "Magenta4"))
    print(cs("Quest Added!", "Magenta4"))
 def getMapRep(self, id, x, y):
     id = int(id)
     # goes to map data looks at id
     # if not visited return blank string
     # else return the string of the representation
     if self.checkVisited(x, y):
         data = jsonHandler.getDataFromFile("mapData.json")
         return data["ids"][id]["mapRep"]
     else:
         return ""
def performRandomScenario(GETR, currSector):
    allScenarios = jsonHandler.getDataFromFile("scenarios.json")
    randScenNum = getScenarioNum(allScenarios)
    currScenario = allScenarios[randScenNum]

    printMessageToUser(currScenario)
    userOption = getValidOption(GETR, currScenario)

    checkSuccessOrFailure(GETR, currSector, currScenario, userOption)

    return
    def ControlSeatInteract(self, GETR):
        #select new planet and tell main to call
        allPlanets = jsonHandler.getDataFromFile("planetData.json")
        allLocations = allPlanets["allLocations"]
        printAllLocations(allLocations)

        validList = makeValidList(allPlanets)

        userInput = getUserInput(validList)
        userSelectedPlace = allPlanets["allLocations"][userInput]
        if userSelectedPlace == "Shop":
            shop.openShop(GETR)
        elif userSelectedPlace == "Mothership":
            mothership.openMothership(GETR)
        return userSelectedPlace
示例#6
0
 def interact(self, GETR):
     x = GETR.getX()
     y = GETR.getY()
     if x == 5 and y == 5:
         return self.reenterShip(GETR)
     else:
         ID = self.getCellID(x, y)
         data = jsonHandler.getDataFromFile("mapData.json")
         nameOfMaterial = data["ids"][ID]["name"]
         amountToAdd = random.randrange(0, 4)
         GETR.setInventorySlot(nameOfMaterial, amountToAdd)
         print(str(amountToAdd) + " " + nameOfMaterial + "s obtained!")
         #empty out the cell:
         self.setCellID(x, y, 0)
     return
 def createBotLine(self):
     BLCor = u'\u2514'
     BRCor = u'\u2518'
     HLine = u'\u2500'
     UpT   = u'\u2534'
     data = jsonHandler.getDataFromFile("planetData.json")
     planetColor = data["locationList"][self.planet]["color"]
     linebuffer = []
     linebuffer.append(BLCor)
     for i in range(self.width):
         linebuffer.append(HLine + HLine + HLine + HLine + HLine + HLine + HLine)
         if i == self.width - 1:
             linebuffer.append(BRCor)
         else:
             linebuffer.append(UpT)
     finalLine = ""
     for item in linebuffer:
         finalLine += item
     print(cs(finalLine, planetColor))
 def createSepLine(self):
     cross = u'\u253C'
     RightT= u'\u2524'
     LeftT = u'\u251C'
     HLine = u'\u2500'
     data = jsonHandler.getDataFromFile("planetData.json")
     planetColor = data["locationList"][self.planet]["color"]
     sepLineBuffer = []
     sepLineBuffer.append(LeftT)
     for i in range(self.width):
         sepLineBuffer.append(HLine + HLine + HLine + HLine + HLine + HLine + HLine)
         if i == self.width - 1:
             sepLineBuffer.append(RightT)
         else:
             sepLineBuffer.append(cross)
     finalSep = ""
     for item in sepLineBuffer:
         finalSep += item
     print(cs(finalSep, planetColor))
 def isValidMove(self, GETR, action, extraOptions):
     # receives a GETR object and action as lowercase string
     # returns bool
     contentsId = int(self.getLocationID(GETR.getX(), GETR.getY()))
     data = jsonHandler.getDataFromFile("mapData.json")
     actions = data["ids"][contentsId]["validActions"]
     if GETR.getY() < self.height - 1:
         actions.append("s")
     if GETR.getY() > 0:
         actions.append("w")
     if GETR.getX() < self.width - 1:
         actions.append("d")
     if GETR.getX() > 0:
         actions.append("a")
     for opt in extraOptions:
         actions.append(opt)
     if action in actions:
         return True
     else:
         return False
示例#10
0
def handleFinishQuest(GETR):
    ID = GETR.getActiveQuest()
    if GETR.getActiveQuest() == None:
        print(cs("You do not have an Active Quest.", "Red"))
        return
    data = jsonHandler.getDataFromFile("quests.json")
    material = data[ID]["material"]
    count = data[ID]["count"]
    value = getValueOfMaterial(material)
    bonus = 3
    reward = value * count * bonus
    if GETR.getInventorySlot(material) >= count:
        GETR.setInventorySlot(material,
                              GETR.getInventorySlot(material) - count)
        GETR.setByteCoins(GETR.getByteCoins() + reward)
        GETR.setActiveQuest(None)
    else:
        print(
            cs("You have angered us by not having enough material!\nGo away!",
               "Red4"))
    def createTopLine(self):
        TLCor = u'\u250C'
        TRCor = u'\u2510'
        HLine = u'\u2500'
        DownT = u'\u252C'
        linebuffer = []
        linebuffer.append(TLCor)
        for i in range(self.width):
            linebuffer.append(HLine + HLine + HLine + HLine + HLine + HLine + HLine)

            if i == self.width - 1:
                linebuffer.append(TRCor)
            else:
                linebuffer.append(DownT)

        finalLine = ""
        for item in linebuffer:
            finalLine += item
        data = jsonHandler.getDataFromFile("planetData.json")
        color = data["locationList"][self.planet]["color"]
        print(cs(finalLine, color))
示例#12
0
 def generateMap(self, planet):
     data = jsonHandler.getDataFromFile("planetData.json")
     concentrations = data["locationList"][planet]["concentration"]
     for i in range(self.width):
         for j in range(self.height):
             if (i != 5 or j != 5):
                 concentrationList = []
                 concentrationKeys = []
                 for key in concentrations:
                     if len(concentrationList) == 0:
                         concentrationList.append(concentrations[key])
                     else:
                         concentrationList.append(
                             concentrationList[len(concentrationList) - 1] +
                             concentrations[key])
                     concentrationKeys.append(key)
                 randomNum = random.randrange(0, 100)
                 for k in range(len(concentrationList)):
                     if randomNum <= concentrationList[k]:
                         self.map[i][j] = concentrationKeys[k]
                         break
示例#13
0
def getShop():
    allMapData = jsonHandler.getDataFromFile("mapData.json")
    DictOfNameAndCost = {}
    for i in allMapData["materialIndexes"]:
        DictOfNameAndCost[allMapData["ids"][i]["name"]] = allMapData["ids"][i]["cost"]
    return DictOfNameAndCost
    def createMidLines(self, GETR, y):
        Vline = u'\u2502'
        data = jsonHandler.getDataFromFile("planetData.json")
        planetColor = data["locationList"][self.planet]["color"]

        # Print Top Blank line
        print(cs(Vline, planetColor), end="")
        for i in range(self.width):
            print("       ", end="")
            if i == self.width - 1:
                print(cs(Vline, planetColor))
            else:
                print(cs(Vline, planetColor), end="")

        # Print Content line
        print(cs(Vline, planetColor), end="")

        for i in range(self.width):
            id = self.getLocationID(i, y)
            rep = self.getMapRep(id, i, y)

            if self.robotIn(GETR, i, y):
                totalspaces = 8 - len(rep) - 1
                rep += "*"
            else:
                totalspaces = 8 - len(rep)

            if totalspaces % 2 == 0:
                prespaces = totalspaces / 2
                postspaces = totalspaces / 2 - 1
            else:
                prespaces = totalspaces / 2
                postspaces = prespaces

            for j in range(int(prespaces)):
                print(" ", end="")

            data = jsonHandler.getDataFromFile("mapData.json")
            checkList = data["ids"]
            color = ""
            if self.robotIn(GETR, i, y):
                for key in checkList:
                    if key["mapRep"] == rep[:-1]:
                        color = key["color"]
            else:
                for key in checkList:
                    if key["mapRep"] == rep:
                        color = key["color"]

            print(cs(rep, color), end="")

            for j in range(int(postspaces)):
                print(" ", end="")

            if i == self.width - 1:
                print(cs(Vline, planetColor))
            else:
                print(cs(Vline, planetColor), end="")

        # Print Bottom Blank line

        print(cs(Vline, planetColor), end="")
        for i in range(self.width):
            print("       ", end="")
            if i == self.width - 1:
                print(cs(Vline, planetColor))
            else:
                print(cs(Vline, planetColor), end="")
 def getValidOptions(self, GETR):
     # receives a GETR object
     # return a list of strings representing valid actions
     contentsId = self.getLocationID(GETR.getX(), GETR.getY())
     data = jsonHandler.getDataFromFile("mapData.json")
     return data["ids"][contentsId]["validActions"]
 def createCargo(self):
     allItemsAndWorth = jsonHandler.getDataFromFile("mapData.json")
     ourNewInventory = {}
     for i in allItemsAndWorth["materialIndexes"]:
         ourNewInventory[allItemsAndWorth["ids"][i]["name"]] = 0
     return ourNewInventory