Esempio n. 1
0
def run_game(connect):
    while True:
        mess = SocketSender.recv_all(connect)
        mess = json.loads(mess.decode("utf-8"), "utf-8")
        if mess["goal"] == 1:
            s, face, color = ui.make_turn(mess["message"])
            if s == "s":
                ans = {"method": "put_card", "card": face, "color": color}
            elif s == "cc":
                ans = {"method": "change_color", "card": face, "color": color}
            elif s == "pass":
                ans = {"method": "pass_turn"}
            elif s == "draw":
                ans = {"method": "draw_card"}
            else:
                raise Exception("wtf!")
            a = json.dumps(ans)
            SocketSender.send_all(connect, a.encode("utf-8"))
        elif mess["goal"] == 0:
            ui.write_table(mess["players"], mess["who's_turn"], mess["hand"], mess["direction"], mess["color"],
                           mess["up_card"], mess["_game_over"])
            if mess["_game_over"]:
                break