def turn(gamer, data):
    """
    Start gamer's turn

    Parameters
    ----------
    gamer: Player who current play
    data: The whole data dict
    """
    end_flag = False
    while True:

        input_data = data["msg"].get_json_data("input")
        while input_data is False:
            input_data = data["msg"].get_json_data("input")
            # print(input_data)
        input_str = input_data[0]["request"]
        print("input_str", input_str)
        choice = int(input_str)
        if choice == 1:
            # Trade with others
            trade_data = data["msg"].get_json_data("trade")
            while trade_data is False:
                trade_data = data["msg"].get_json_data("trade")
            operation.trade(data, trade_data)
        elif choice == 2 and end_flag is False:
            # Roll dice
            dice_a, dice_b, end_flag = roll(gamer, data)
        elif choice == 3:
            # Construct building
            operation.construct_building(gamer, data)
        elif choice == 4:
            # Remove building
            operation.remove_building(gamer, data)
        elif choice == 5:
            # Mortgage
            operation.mortgage_asset(gamer, data)
        elif choice == 6:
            if end_flag is True:
                # End turn
                break
            else:
                # haven't rolled dice
                data["msg"].push2single(
                    gamer.id, operation.gen_hint_json("Please roll a dice"))
                data["msg"].push2single(gamer.id,
                                        operation.gen_newturn_json(gamer))
        else:
            # Invalide choice
            data["msg"].push2single(gamer.id,
                                    operation.gen_hint_json("Invalid choice"))
        # Update all value to front end
        data["msg"].push2all(operation.gen_update_json(data))
예제 #2
0
def turn(gamer, data):
    """
    :param gamer: players
    :return:
    """
    end_flag = False
    while True:
        operation.push2all("1: Trade with others")
        operation.push2all("2: Roll dices")
        operation.push2all("3: Construct building")
        operation.push2all("4: Remove building")
        operation.push2all("5: Mortgage asset")
        operation.push2all("6: End turn")
        while True:
            input_str = operation.wait_choice(
                "Please enter the number of your decision:")
            if (True):
                input_data = data["msg"].get_json_data("input")
                input_str = input_data[0]["request"]
                print("input_str", input_str)
            try:
                choice = int(input_str)
                break
            except ValueError:
                operation.push2all("Please enter a number.")
        operation.push2all()
        if choice == 1:
            # operation.trade(data, trade_data)
            pass
        elif choice == 2 and end_flag is False:
            dice_a, dice_b, end_flag = roll(gamer, data)
        elif choice == 3:
            operation.construct_building(gamer, data)
        elif choice == 4:
            operation.remove_building(gamer, data)
        elif choice == 5:
            operation.mortgage_asset(gamer, data)
        elif choice == 6:
            if end_flag is True:
                break
            else:
                operation.push2all("Please roll a dice")
        else:
            operation.push2all("Invalid choice")
예제 #3
0
def turn(gamer):
    """
    :param gamer: players
    :return:
    """
    global data
    end_flag = False
    while True:
        operation.push2all("1: Trade with others")
        operation.push2all("2: Roll dices")
        operation.push2all("3: Construct building")
        operation.push2all("4: Mortgage asset")
        operation.push2all("5: End turn")
        while True:
            operation.push2all("Please enter the number of your decision:")
            input_str = operation.wait_choice()
            try:
                choice = int(input_str)
                break
            except ValueError:
                operation.push2all("Please enter a number.")
        operation.push2all(" ")
        if choice == 1:
            operation.trade()
        elif choice == 2 and end_flag is False:
            dice_a, dice_b, end_flag = roll(gamer)
        elif choice == 3:
            operation.construct_building(gamer, data)
        elif choice == 4:
            operation.mortgage_asset(gamer, data)
        elif choice == 5:
            if end_flag is True:
                break
            else:
                operation.push2all("Please roll a dice")
        else:
            operation.push2all("Invalid choice")