Exemplo n.º 1
0
 def on_message_players_m(client, userdata, msg):
     #message format: "i:1;x:788;y:366;" i=player index, x= x position, y = y position,
     global players
     global update
     pIndex = find_between(str(msg.payload), "i:", ";")
     x = find_between(str(msg.payload), "x:", ";")
     y = find_between(str(msg.payload), "y:", ";")
     players[int(pIndex)].moveTo(x=float(x), y=float(y))
     update = True
Exemplo n.º 2
0
    def on_message_score(client, userdata, msg):
        #message format: "score0:2;score1:4;
        global score
        global update
        sc0 = find_between(str(msg.payload), "score0:", ";")
        sc1 = find_between(str(msg.payload), "score1:", ";")

        score = [int(sc0), int(sc1)]

        update = True
Exemplo n.º 3
0
    def on_message_players_url(client, userdata, msg):
        #message format: "i:1;url:"existingImageurl";"
        #                           options for i: index
        #                           options for url: url for image
        global players
        global update
        pIndex = find_between(str(msg.payload), "i:", ";")
        url = find_between(str(msg.payload), "url:", ";")

        players[int(pIndex)].imageUrl = url

        update = True
Exemplo n.º 4
0
    def on_message_players_d(client, userdata, msg):
        #message format: "i:1;" or "i:all;" i=player index or "all"
        global players
        global update
        pIndex = find_between(str(msg.payload), "i:", ";")
        if pIndex == "all":
            players = []
        else:
            players.pop(int(pIndex))

        update = True
Exemplo n.º 5
0
    def on_message_players_a(client, userdata, msg):
        #message format: "i:1;t:t;" options for i = index or "last"
        #                           options for t: t = toiletroll, v=virus, c=cart, options for p = index or "last"
        global players
        global update
        pIndex = find_between(str(msg.payload), "i:", ";")
        playerType = find_between(str(msg.payload), "t:", ";")

        if playerType == "t":
            player = p.toiletRoll()
        elif playerType == "v":
            player = p.virus()
        elif playerType == "c":
            player = p.cart()

        if pIndex == "last":
            players.append(player)
        else:
            players.insert(int(pIndex), player)

        update = True
Exemplo n.º 6
0
    def on_message_status(client, userdata, msg):
        #message format: "req:images;" for image sizes or "req:players;" for player status
        global players
        global update
        command = find_between(str(msg.payload), "req:", ";")

        if command == "images":
            client.publish("coronahamstergame/gamelogic/gui/images_status",
                           getImageSizesAsString(),
                           qos=1)
        elif command == "players":
            playerstats = ""
            i = 0
            for p in players:
                playerstats += "i:{};".format(i) + p.toString() + "\n"
                i += 1
            client.publish("coronahamstergame/gamelogic/gui/player_status",
                           playerstats,
                           qos=1)
Exemplo n.º 7
0
 def on_message_players_status(client, userdata, msg):
     strings = msg.payload.splitlines()
     global toiletRolls, viruses, carts
     toiletRolls, viruses, carts = [], [], []
     for s in strings:
         plType = find_between(str(s), "type:", ";")
         x = find_between(str(s), "x:", ";")
         y = find_between(str(s), "y:", ";")
         width = find_between(str(s), "width:", ";")
         height = find_between(str(s), "height:", ";")
         imageUrl = find_between(str(s), "imageUrl:", ";")
         pl = p.logicPlayer(plType= plType,position= p.Cartesian2D(x=float(x), y=float(y)), _width= float(width), _height= float(height), imageUrl=imageUrl)
         players.append(pl)
         if(pl.plType == "toiletRoll"):
             toiletRolls.append(pl)
         elif(pl.plType == "virus"):
             viruses.append(pl)
         elif(pl.plType == "cart"):
             carts.append(pl)
Exemplo n.º 8
0
 def on_message_setting(client, userdata, msg):
     #message format: "res:1024x768";
     global resolution
     global update
     resolution = find_between(str(msg.payload), "res:", ";")
     update = True