示例#1
0
def play():
    level = 1
    player_name = input('Enter your name Player! \n')
    print(f"Welcome to The Hunger Games. And may luck always be on your side! {player_name}\n")
    player = Player(player_name)
    enemy_name = 'Enemy monster'
    enemy = Enemy(enemy_name, level)

    while True:
        command = input(
            f"{player_name}, Please enter \"START\" to start the game\n"
            f"or enter \"HELP\" to enter setup\n")  # .lower()

        if command == "start":
            print(f'Your enemy name is {enemy_name}!')
            while True:

                try:

                    player.allowed_attack = input('Please make a choice for attack: '
                                                  '\'1\' - Wizard, \'2\' - Warrior,'
                                                  ' \'3\' - Rogue \n')
                    player.attack(enemy)
                    print(f'Your lives: {player.lives} | {enemy_name} lives: {enemy.lives}\n')
                    player.allowed_attack = input('Please make a choice for defence: '
                                                  '\'1\' - Wizard, \'2\' - Warrior,'
                                                  ' \'3\' - Rogue \n')
                    player.defence(enemy)
                    print(f'Your lives: {player.lives} | {enemy_name} lives: {enemy.lives}\n')
                except EnemyDown:
                    player.score += 5
                    player.level += 1
                    level += 1
                    print(f'\n---------------------------------------------------------\n'
                          f' You killed {enemy_name}. Your score: '
                          f'{player.score}. Level: {player.level}.\n'
                          f'---------------------------------------------------------\n')  # format(self.enemy_name, ))
                    enemy_name = 'goga'
                    enemy = Enemy(enemy_name, level)
                    print(f'\nYour enemy name is {enemy_name}!\n')
                except InvalidLiteral:
                    print('\nONLY 3 classes of fighters!!! 1-2-3\n')

        elif command == "help":
            settings.show_commands()

        elif command == "show scores":
            print('\n')
            Scores.show_score()
            print('\n')

        elif command == "exit":
            raise KeyboardInterrupt
示例#2
0
def create(scores):
    gameDate = date.today()
    Will = assignPoints('Will', scores)
    Dan = assignPoints('Dan', scores)
    Ben = assignPoints('Ben', scores)
    Sven = assignPoints('Sven', scores)

    print(gameDate)

    existing_record = None

    # Can we insert this person?
    if existing_record is None:

        # Create a person instance using the schema and the passed-in person
        schema = ScoresSchema()
        new_record = schema.load(scores, session=db.session).data

        # Add the person to the database

        newScores = Scores(gameDate=gameDate,
                           Will=Will,
                           Dan=Dan,
                           Ben=Ben,
                           Sven=Sven)

        db.session.add(newScores)
        db.session.commit()

        # Serialize and return the newly created person in the response
        return schema.dump(new_record).data, 201

    # Otherwise, nope, person exists already
    else:
        abort(409, f'Record exists already')
示例#3
0
def edit_user_problem_data(id, pid):
    if not request.json:
        abort(400)

    updated_score = Scores.db_update_user_problem_data(conn, id, pid,
                                                       request.json)
    if updated_score is None:
        return abort(404)
    return jsonify(updated_score)
def play():
    """
    - Entering the player's name
    - Creating a player object - level = 1
    - Creating an enemy object
    - calls the attack and defense
      methods of the player object in an endless loop
    - when an exception occurs, EnemyDown raises the game level,
      creates a new Enemy object with a new level,
      adds +5 points to the player."""
    level = 1
    player = Player(Inputs.input_player_name(), LIVES)
    Inputs.input_start()
    enemy = Enemy(level)

    while True:
        try:
            player.attack(enemy)
            player.defence(enemy)

        except EnemyDown:
            level += 1
            enemy = Enemy(level)
            player.score += ENEMY_DOWN_SCORE
            print(cli_color(f'{ENEMY_DOWN_STRING} {player.score}', 'c'))
            print(LIVES_STRING, player.lives)

        except GameOver:
            scores = Scores()
            # read scores from file
            try:
                scores.read_from_file(SCORE_FILE)
            except FileNotFoundError:
                pass
            # write score to scores file
            scores.new_result(player, SCORE_FILE)
            raise GameOver
示例#5
0
def countscore(r, mathobj, checkscore, attckscore):

    print('统计 %d 轮分数' % r)
    #统计check
    #队伍数量
    team_count = Teams.query.count()
    #被扣分的container.id和typename
    checked = Round.query.join(containers,
                               containers.id == Round.containerid).filter(
                                   Round.rounds == r,
                                   Round.attackteamid == 0).with_entities(
                                       containers.typename,
                                       containers.id).all()

    checked_score_sum = {}

    for i in checked:
        if checked_score_sum.get(i[0]):
            checked_score_sum[i[0]]['score'] += checkscore
            checked_score_sum[i[0]]['containers'].append(i[1])
        else:
            checked_score_sum[i[0]] = {}
            checked_score_sum[i[0]]['containers'] = []
            checked_score_sum[i[0]]['score'] = checkscore
            checked_score_sum[i[0]]['containers'].append(i[1])

    for i in checked_score_sum:
        if team_count > len(checked_score_sum[i]['containers']):
            checked_score_sum[i][
                'avgscore'] = checked_score_sum[i]['score'] / (
                    team_count - len(checked_score_sum[i]['containers']) + 0.0)
        else:
            checked_score_sum[i]['avgscore'] = 0

    print '============================='
    print 'check情况'
    print '============================='

    print checked_score_sum

    for i in mathobj:
        for c in checked_score_sum:
            if i.db_containers.typename == c:
                print c, i.db_containers.id
                #print i.teamid
                print i.db_containers.score
                if i.db_containers.id in checked_score_sum[c]['containers']:
                    i.db_containers.score -= decimal.Decimal(checkscore)
                else:
                    i.db_containers.score += decimal.Decimal(
                        checked_score_sum[c]['avgscore']).quantize(
                            decimal.Decimal('0.00'))
                print i.db_containers.score
                i.update_score()

    #统计丢分

    checked = Round.query.join(containers,
                               containers.id == Round.containerid).filter(
                                   Round.rounds == r,
                                   Round.attackteamid != 0).with_entities(
                                       containers.typename, containers.id,
                                       Round.attackteamid).all()
    #print checked
    checked_score_sum = {}

    for i in checked:
        #print 'Key ERROR?',i

        if checked_score_sum.get(i[0]):
            if checked_score_sum[i[0]].get(i[1]):
                checked_score_sum[i[0]][i[1]]['attackteams'].append(i[2])
            else:

                checked_score_sum[i[0]][i[1]] = {}
                checked_score_sum[i[0]][i[1]]['attackteams'] = []
                checked_score_sum[i[0]][i[1]]['attackteams'].append(i[2])
        else:
            checked_score_sum[i[0]] = {}
            checked_score_sum[i[0]][i[1]] = {}
            checked_score_sum[i[0]][i[1]]['attackteams'] = []
            checked_score_sum[i[0]][i[1]]['attackteams'].append(i[2])

    print '============================='
    print '丢分情况'
    print '============================='

    for i in checked_score_sum:
        for j in checked_score_sum[i]:
            checked_score_sum[i][j]['avgscore'] = attckscore / (
                len(checked_score_sum[i][j]['attackteams']) + 0.0)

    print '============================='
    print checked_score_sum
    print '============================='

    for i in checked_score_sum:
        for cid in checked_score_sum[i]:
            for x in Round.query.filter(Round.rounds == r,
                                        Round.containerid == cid).all():
                x.score = decimal.Decimal(
                    checked_score_sum[i][cid]['avgscore'])
    db.session.commit()

    for c in checked_score_sum:
        for i in mathobj:
            if i.db_containers.typename == c:
                for i1 in checked_score_sum[c]:
                    #print c,i.db_containers.id,i.db_containers.score
                    if i.db_containers.id == i1:
                        i.db_containers.score -= decimal.Decimal(attckscore)
                        #print c,i.db_containers.id,i.db_containers.score
                        #i.update_score()
                        #break

                    if i.teamid in checked_score_sum[c][i1]['attackteams']:
                        i.db_containers.score += decimal.Decimal(
                            checked_score_sum[c][i1]['avgscore']).quantize(
                                decimal.Decimal('0.00'))
                        #print c,i.db_containers.id,i.db_containers.score
                        #i.update_score()
                        #continue
                        #break
            #i.session.commit()
            i.update_score()

    # 记录每轮的分数

    teams = Teams.query.all()

    for i in teams:
        #team_score = i.score() #r
        db.session.add(Scores(i.id, i.score(), r))
    db.session.commit()
    return
示例#6
0
def delete_user_problem_data(id, pid):
    if Scores.db_delete_user_problem_data(conn, id, pid):
        return jsonify({"success": True})

    return abort(404)
示例#7
0
def add_user_problem_data(id, pid):
    if not request.json:
        abort(400)

    new_score = Scores.db_create_user_problem_data(conn, id, pid, request.json)
    return jsonify(new_score), 201
示例#8
0
def get_user_problem_data(id, pid):
    score = Scores.db_get_user_problem_data(conn, id, pid)
    if score is None:
        return abort(404)
    return jsonify(score)