示例#1
0
 def encounter(self,player,gui):
     self.greeting(player,gui)
     result = self.challenge(player,gui,self.tries) 
     if result:
         gui.prn(choice_if_list(self.success_text))
     else:
         gui.prn(choice_if_list(self.failure_text))
         Enemy.encounter(self,player,gui)
     return False
示例#2
0
 def talk_with(self,player,gui):
     if self.done:
         if self.done_text:
             gui.prn(choice_if_list(self.done_text))
             gui.prn('')
         return False
     gui.prn(choice_if_list(self.message_text))
     gui.prn('')
     self.things[0].move(player)
     self.done=True
示例#3
0
def map_pattern(ch,special_pattern_table):
    try:
        place_spec = special_pattern_table[ch]
    except KeyError:
        try:
            place_spec = standard_pattern_table[ch]
        except KeyError:
            return FreeSpace()
    if not type(place_spec) in [tuple,list]:
        return place_spec()
    else:
        place=False
        gateway=False
        rest=[]
        for c in place_spec:
            o = choice_if_list(c)()
            if isinstance(o,MapItem):
                place=o
            elif isinstance(o,GateWay):
                gateway=o
            else:
                rest+=[o]
        if not place and not ch==' ':
            place=map_pattern(' ',special_pattern_table)
        elif not place:
            print("Error in map: "+ch)
            place= FreeSpace()
        place.gateway=gateway
        for o in rest:
            o.move(place)
        return place
示例#4
0
    def encounter_magic_phase(self,player,player_initiative,gui,extra= False):
        extra_damage_mult = extra and 3 or 1
        tries = extra and 2 or 1
        if player_initiative:
            gui.prn('Incanti!')
        else:
            gui.prn(choice_if_list(self.magic_text))
        if player_initiative and not self.vulnerable_spirit:
            gui.prn('Incantesimi non hanno effetto su %s!' % self.name)
            outcome = 0
        else:
            outcome = self.challenge(player,gui,tries)                
        self_damage = outcome*player_initiative*\
                      random.randint(1,max(1,int(extra_damage_mult*(player.craft*player.craft_aid_off(self)/self.craft_aid_def(player)))))
        if self_damage > 0:
            gui.prn(self.name.capitalize(), 'perde %d punti di spirito.\n' % self_damage)
            self.sp -= self_damage
            try:
                winsound.PlaySound('sounds/lightning.wav',0)
            except RuntimeError:
                pass
        player_damage =  (1-outcome)*(1-player_initiative)*\
                        random.randint(1,max(1,int(self.craft*self.craft_aid_off(player)/player.craft_aid_def(self))))
        if player_damage > 0:
            gui.prn('Perdi %d punti di spirito.\n' % player_damage)
            player.sp -= player_damage
            player.long_sp -= player_damage/2
            if self.sound:
                try:
                    winsound.PlaySound(self.sound,0)
                except RuntimeError:
                    pass

        return outcome                  
示例#5
0
 def __init__(self,name=False,description=False,agents=[],things=[],hidden_things=[],gateway=False):
     # self.agents = agents[:]+filter(lambda x : x, map(lambda a: ((choice_if_list(a) or (lambda : False))()), self.agents))
     self.agents = agents[:]+list(filter(lambda x : x, map(lambda a: ((choice_if_list(a) or (lambda : False))()), self.agents)))
     for a in self.agents:
         a.place = self
     # self.things = things[:]+filter(lambda x : x, map(lambda o: ((choice_if_list(o) or (lambda : False))()), self.things))
     self.things = things[:]+list(filter(lambda x : x, map(lambda o: ((choice_if_list(o) or (lambda : False))()), self.things)))
     for t in self.things:
         t.place = self
     # self.hidden_things = hidden_things[:]+filter(lambda x : x, map(lambda o: ((choice_if_list(o) or (lambda : False))()), self.hidden_things))
     self.hidden_things = hidden_things[:]+list(filter(lambda x : x, map(lambda o: ((choice_if_list(o) or (lambda : False))()), self.hidden_things)))
     if name:
         self.name=name
     if description:
         self.description = description
     if gateway:
         self.gateway = gateway
     elif self.gateway:
         self.gateway=self.gateway()
     basic_item.BasicItem.__init__(self)
示例#6
0
 def talk_with(self,player,gui):
     if self.done:
         if self.done_text:
             gui.prn(choice_if_list(self.done_text))
             gui.prn('')
         return False
     gui.prn(choice_if_list(self.message_text))
     gui.prn('')
     result = self.challenge(player,gui,self.tries) 
     if result:
         gui.prn(choice_if_list(self.success_text))
         gui.prn('')
         self.success_action(player,gui)
         self.done=True
     else:
         gui.prn(choice_if_list(self.failure_text))
         gui.prn('')
         self.failure_action(player,gui)
     player.redisplay = True
     return False
示例#7
0
    def defeated(self,player,gui):
        self.dead = True
        self.status_text = self.dead_suffix_text
        for t in self.things[:]:
            t.move(self.place)
        gui.prn(choice_if_list(self.defeated_text))
        try:
            winsound.PlaySound('sounds/victory.wav',0)
        except RuntimeError:
            pass

        player.redisplay=True
def phrase_question_choice(phrase_list, number_of_alts, gui):
    ph1 = phrase.choice_if_list(phrase_list).choice()
    alts = []
    tries = 0
    while len(alts) < number_of_alts and tries < 20:
        ph2 = ph1.choice()
        e = ph2.eng()
        print(e, ph2.it())
        if not (e in [a[0]
                      for a in alts]):  # filter(lambda a: e == a[0], alts):
            alts.append((e, ph2.it()))
        else:
            tries += 1
    q = random.randint(0, len(alts) - 1)
    return ask_it_choice(alts[q][1][0], alts[q][0], alts, gui)
示例#9
0
    def encounter_battle_phase(self,player,player_initiative,gui,extra=False):
        extra_damage_mult = extra and 3 or 1
        tries = extra and 2 or 1
        if player_initiative:
            gui.prn('Attacchi %s!' % self.name)
        else:
            battle_text = choice_if_list(self.battle_text)
            gui.prn(battle_text or (self.name.capitalize() + ' attacca!'))
        if player_initiative and not self.vulnerable_body and\
           not (player.weapon and player.weapon.get_special_damage(self)):
            gui.prn('Forza non ha effetto su %s!\n' % self.name)
            outcome = 0
        else:
            outcome = self.challenge(player,gui,tries)                
        self_damage = outcome*player_initiative and \
                      (random.randint(1,extra_damage_mult*(player.strength+((player.weapon and player.weapon.strength) or 0))+\
                        (player.weapon and player.weapon.get_special_damage(self) or 0)))   
        if self_damage > 0:
            self_protection = self.armour and self.armour.get_protection(player,self_damage) or 0
            gui.prn(self.name.capitalize(), 'perde %d punti di corpo.\n' % (self_damage-self_protection))
            self.hp -= max(0,self_damage-self_protection)
            try:
                winsound.PlaySound('sounds/punch.wav',0)
            except RuntimeError:
                pass

        player_damage = (1-outcome)*(1-player_initiative) and \
                        (random.randint(1,self.strength+((self.weapon and self.weapon.strength) or 0))+\
                        (self.weapon and self.weapon.get_special_damage(player) or 0))  
        if player_damage > 0:
            player_protection = player.armour and player.armour.get_protection(self,player_damage) or 0
            gui.prn('Perdi %d punti di corpo.\n' % (player_damage-player_protection))
            player.hp -= max(0,player_damage-player_protection)
            player.long_hp -= max(0,player_damage-player_protection)/2
            if self.sound:
                try:
                    winsound.PlaySound(self.sound,0)
                except RuntimeError:
                    pass

        return outcome
示例#10
0
    def __init__(self,name=False,things=[],weapon=False,magic=False,armour=False):
        if name:
            self.name=name
        self.max_hp = self.hp
        self.long_hp = self.hp
        self.max_sp = self.sp
        self.long_sp = self.sp
        self.place = False
        self.state = 0
        self.dead = False
        self.things = [ choice_if_list(o) for o in things]+[ choice_if_list(o)() for o in self.things ]
        if weapon:
            self.weapon=choice_if_list(weapon)
            self.things.insert(-1,self.weapon)
        elif self.weapon:
            self.weapon = choice_if_list(self.weapon)()
            self.things.insert(-1,self.weapon)
        if magic:
            self.magic=choice_if_list(magic)
            self.things.insert(-1,self.magic)
        elif self.magic:
            self.magic = choice_if_list(self.magic)()
            self.things.insert(-1,self.magic)
        if armour:
            self.armour=choice_if_list(armour)
            self.things.insert(-1,self.armour)
        elif self.armour:
            self.armour = choice_if_list(self.armour)()
            self.things.insert(-1,self.armour)
##            
##        self.things = filter(lambda x: x, map(lambda o: choice_if_list(o), things)+\
##                             map(lambda o: ((choice_if_list(o) or (lambda : False))()), self.things)+((self.weapon and [self.weapon]) or [])+\
##                            ((self.magic and [self.magic]) or [])+((self.armour and [self.armour]) or []))
        for t in self.things:
            t.place = self
        self.escape_place = False
        self.base = False
        basic_item.BasicItem.__init__(self)
示例#11
0
 def greeting(self,player,gui):
     gui.prn(choice_if_list(self.greeting_text))
     equip=[]
     if self.weapon:
         equip+= [self.weapon.name]
     if self.armour:
         equip+= [self.armour.name]
     if self.magic:
         equip+= [self.magic.name]
     if equip:
         equip_text = 'Ha '
         equip_max = len(equip)-1
         for i in range(equip_max+1):
             if i == equip_max:
                 if i > 0:
                     equip_text+=' e '
                 equip_text+= equip[i]+'.'
             else:
                 equip_text+= equip[i]
                 if i+1 < equip_max:
                     equip_text+= ', '
         gui.prn(equip_text)
     self.state = 1
     gui.prn('')
def phrase_question_write(phrase_list, gui):
    ph = phrase.choice_if_list(phrase_list).choice()
    return ask_eng_write(ph.eng(), ph.it(), gui)
示例#13
0
 def talk_with(self,player,gui):
     gui.prn(choice_if_list(self.message_text))
     gui.prn('')
示例#14
0
 def encounter(self,player,gui):
     gui.prn(choice_if_list(self.greeting_text))
     gui.prn('')
     if self.state == 0:
         self.talk_with(player,gui)
         self.state = 1