Exemplo n.º 1
0
 def battle(self, player, monster): #adjusted code from original, so I can simulate games without going through the choice mechanism
     turn = 1
     p_hp = player.HP
     m_hp = monster.HP
     while m_hp > 0 and p_hp > 0:
         #print "*"*30
         #print "Begin round %s" % (turn)
         #print "*"*30
         #print "You have %s HP remaining" % (p_hp)
         #print "The %s approaches" % (monster.name)
         if self.initiative(player, monster) == 1:
             m_hp -= player.attack(monster) #call choice
             if m_hp <= 0:
                 return (p_hp, m_hp)
             p_hp -= monster.attack(player) #call monster attack
             if p_hp <= 0:
                 return (p_hp, m_hp)
         else:
             p_hp -= monster.attack(player) #call monster attack
             if p_hp <= 0:
                 return (p_hp, m_hp)
             m_hp -= player.attack(monster) #call choice
             if m_hp <= 0:
                 return (p_hp, m_hp)
Exemplo n.º 2
0
 def choice(self, player, monster):
     #code for player action choice
     choice = None
     while choice == None:
         choice = raw_input("Do you (A)ttack or (R)un?   ")
         if choice.lower() in ('a', 'attack'): #call attack function
             return player.attack(monster)
         #elif choice in ('p', 'P'):
         #    print "POTION"
         #    player.use()
         #    return 0
         elif choice.lower() in ('r', 'run'):
             print "RUN!"
             player.run(monster)
         else:
             print "I don't understand"
             choice = None
Exemplo n.º 3
0
def runLevel(curLevel, brains, screen, maxfps, debug):
    screenSize = screen.get_size()
    
    #for darkening the screen
    darken=pygame.Surface(screen.get_size())
    darken.fill((20, 20, 30))
    darken.set_alpha(100)
    
    dark = 1
    
    #ids for timers
    bloodtimer = pygame.USEREVENT+1
    braintimer = bloodtimer + 1
    clock = pygame.time.Clock()
        
    level = terrain.Terrain(curLevel)
    world = pygame.Surface(level.background.get_size())
    osd = OSD(screenSize)

    screen.blit(level.background, (0, 0))
    pygame.display.flip()

    all, playerGroup, enviro, enemy, doors = terrain.groups(world.get_rect(), curLevel, level.tileSize)
    #enviro.draw(level.background)
    notPlayer = isogroup.ISOGroup()
    notPlayer.add(enviro, enemy)
    watchRect = pygame.rect.Rect((0,0), screenSize)
    player = playerGroup.sprites()[0]
    all.add(enviro)
    player.brains = brains

    onscreen = isogroup.ISOGroup()
    onscreenEnemy = isogroup.ISOGroup()
    
    pygame.time.set_timer(bloodtimer, player.bloodtick*maxfps)
    pygame.time.set_timer(braintimer, player.braintick*maxfps)
    
    while 1:
        clock.tick(maxfps)

        for event in pygame.event.get():
            if event.type == QUIT:
                return -1, player.brains
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                return 0, player.brains
            elif event.type == KEYDOWN and event.key == K_q:
                return 0,player.brains
            elif event.type == KEYDOWN and event.key == K_F1:
                help(screen)
            elif event.type == KEYDOWN and event.key == K_UP:
                player.run('n')
            elif event.type == KEYDOWN and event.key == K_DOWN:
                player.run('s')
            elif event.type == KEYDOWN and event.key == K_LEFT:
                player.run('w')
            elif event.type == KEYDOWN and event.key == K_RIGHT:
                player.run('e')
            elif event.type == KEYDOWN and event.key == K_LCTRL:
                player.attack(enemy, osd)
            elif event.type == KEYDOWN and event.key == K_a:
                player.wounded()
            elif event.type == KEYDOWN and event.key == K_s:
                player.talk()
            elif event.type == KEYDOWN and event.key == K_d:
                enemy.sprites()[0].health = 0
            elif event.type == KEYDOWN and event.key == K_f:
                player.bite(enemy)
            elif event.type == KEYDOWN and event.key == K_LALT:
                player.morph()
            elif event.type == KEYDOWN and event.key == K_t:
                dark = not dark
            elif event.type == KEYDOWN and event.key == K_p:
                return curLevel+1, player.brains
            elif event.type == KEYUP:
                if player.action == 'walking' or player.action == 'running':
                    player.stop()
            elif event.type == bloodtimer:
                player.blood -= 1
            elif event.type == braintimer:
                player.brains -= 1

        
        onscreen.empty()
        onscreenEnemy.empty()
        for s in all.sprites():
            if s.rect.colliderect(watchRect):
                if s in enemy:
                    onscreenEnemy.add(s)
                onscreen.add(s)
                
        #print clock.get_time()/1000.0
        onscreen.update(clock.get_time()/1000.0, osd, player)

        if isogroup.spritecollideany(player, doors):
            if player.level > curLevel:
                #warp level
                return curLevel + 1, player.brains
            else:
                osd.addMessage('You are not yet powerful enough to go there.')

        if isogroup.spritecollideany(player, notPlayer):
            player.collide()
            
        for s in onscreenEnemy:
            if isogroup.spritecollideany(s, enviro) or isogroup.spritecollideany(s, playerGroup):
                s.collide()
                
        osd.update(player, clock.get_fps())
        watchRect.center = player.rect.center
        sRect = world.get_rect()
        if not sRect.contains(watchRect):
            watchRect.clamp_ip(sRect)
        
        world.blit(level.background, watchRect, watchRect)
        
        onscreen.draw(world)
        if debug:
            for thing in onscreen:
                pygame.draw.rect(world, pygame.Color('red'), thing.cRect, 1)
                pygame.draw.rect(world, pygame.Color('blue'), thing.rect, 1)
                if hasattr(thing, "attackRect"):
                    pygame.draw.rect(world, pygame.Color('green'), thing.attackRect, 1)
                if hasattr(thing, "hitRect"):
                    pygame.draw.rect(world, pygame.Color('purple'), thing.hitRect, 1)
                if hasattr(thing, "velocity"):
                    pygame.draw.line(world, (50,75,222), thing.rect.center, thing.rect.center+(thing.velocity*30), 2)
                if hasattr(thing, "wanderpoint"):
                    pygame.draw.circle(world, (120,3,85), (int(thing.wanderpoint[0]), int(thing.wanderpoint[1])), 50)
            
        screen.fill((0,0,0))
        screen.blit(world, (0, 0), watchRect)
        if (dark):
            screen.blit(darken, (0, 0))
        screen.blit(osd.osd, (0, 0))
        pygame.display.flip()
        
        if not player.alive:
            return curLevel, 0
Exemplo n.º 4
0
def battle_room():
    show = 0
    form = TurnForm()
    opponentForm = OpponentForm()

    form.first.choices = dropdown([card.name for card in user.cards])
    form.second.choices = dropdown([card.name for card in opponent.cards])

    winner = endgame(opponent, user)
    if winner == opponent or winner == user:
        message = winner.name + " won!"
        show = 2
        return render_template('battle_room.html',
                               deck=user.cards,
                               name=user.name,
                               opponentDeck=opponent.cards,
                               form=form,
                               message=message,
                               opponentForm=opponentForm,
                               show=show)

    if form.validate_on_submit():
        first = form.first.data
        second = form.second.data
        show = 1
        message = attack(user.name, findElem(first, user.cards),
                         findElem(second, opponent.cards))
        updateList(opponent.cards)
        form.second.choices = dropdown([card.name for card in opponent.cards])
        return render_template('battle_room.html',
                               deck=user.cards,
                               name=user.name,
                               opponentDeck=opponent.cards,
                               form=form,
                               message=message,
                               opponentForm=opponentForm,
                               show=show)

    if opponentForm.validate_on_submit():
        first = opponent.cards[random.randint(0, len(opponent.cards) - 1)]
        second = user.cards[random.randint(0, len(user.cards) - 1)]
        show = 0

        while second.hp <= 0 or first.hp <= 0:
            first = opponent.cards[random.randint(0, len(opponent.cards) - 1)]
            second = user.cards[random.randint(0, len(user.cards) - 1)]

        message = attack("Opponent", second, first)
        updateList(user.cards)
        form.first.choices = dropdown([card.name for card in user.cards])
        return render_template('battle_room.html',
                               deck=user.cards,
                               name=user.name,
                               opponentDeck=opponent.cards,
                               form=form,
                               message=message,
                               opponentForm=opponentForm,
                               show=show)

    return render_template(
        'battle_room.html',
        deck=user.cards,
        name=user.name,
        opponentDeck=opponent.cards,
        form=form,
        opponentForm=opponentForm,
        message=
        "It's your move! Select one of your cards to attack and one of your opponent's cards as the target.",
        show=show)
Exemplo n.º 5
0
#Clears the command prompt from all text
clear = lambda: os.system('cls')

if __name__ == "__main__":
    #Make sure command prompt is clear
    clear()

    player.status()
    "Basic story"
    print("You are a traveler crossing the vast sea ")
    time.sleep(2)
    print("and scanning the horizon you see an enemy ship!")
    time.sleep(3)

    #Update the ship
    enemy.draw_ship()

    #If turn is 0 then it's the players turn, 1 is PC
    turn = 0
    start = True

    while start:

        if (turn == 1):
            enemy.attack()
            turn = 0
        elif (turn == 0):
            user_input = input()
            player.attack(user_input[5:])
            turn = 1