def __init__(self):
        self.__len = 15
        j = 0
        k = 0
        not_deck = []
        while j < 5:
            i = 0
            while i < 3:
                if k == 0:
                    not_deck.append(Duke())
                if k == 1:
                    not_deck.append(Assassin())
                if k == 2:
                    not_deck.append(Ambassador())
                if k == 3:
                    not_deck.append(Captain())
                if k == 4:
                    not_deck.append(Contessa())
                if i == 2:
                    k += 1
                i += 1
            j += 1

        deck = []
        l = 15
        #Here we shuffle the deck
        while l > 0:
            x = random.randint(0, l - 1)
            l -= 1
            deck.append(not_deck[x])
            not_deck.pop(x)

        self.__deck = deck
예제 #2
0
 def action_reroll(self, aguments):
     if self.assassin and self.assassin.alive:
         response = {
             'message': self.get_text('noreroll') % self.assassin.get_attributes(),
             'success': 0,
         }
         return response
     else:
         # Reroll new assassin.
         self.assassin = Assassin(self._gamedata['assassin'], userid=self._userid)
         self.assassin.reroll()
         attribs = self.assassin.get_attributes()
         logging.info(attribs)
         msg = self.get_text('newassassin')
         try:
             msg = msg % attribs
         except KeyError, e:
             logging.error("Couldn't find a given text replacement: %s" % str(e))
         response = {
             'message': msg,
             'data': {
                 'hero': attribs,
             }
         }
         return response
 def put_back_cards(self, i):
     #Puts a card back in the deck (at the end of it)
     c = 0
     while c == 0:
         if i == 0:
             card = Duke()
             self.deck_setter(-1, card)
         elif i == 1:
             card = Assassin()
             self.deck_setter(-1, card)
         elif i == 2:
             card = Ambassador()
             self.deck_setter(-1, card)
         elif i == 3:
             card = Captain()
             self.deck_setter(-1, card)
         elif i == 4:
             card = Contessa()
             self.deck_setter(-1, card)
         c = 1
     return 0
예제 #4
0
def StageThree(hero, winstyle = 0):

        # Initialize screen
        pygame.init()
        bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32)
        screen = pygame.display.set_mode(SCREENRECT.size, winstyle, bestdepth)
        pygame.display.set_caption('Cyborg-Fu!')

        # Creating Background
        bgdtile = load_image('rivers.png')
        background = pygame.Surface(SCREENRECT.size)
        background.blit(bgdtile, (0,0))

        #Missle & Attack object groups must be determined before characters.
        shots = pygame.sprite.Group()
        pshots = pygame.sprite.Group()
        ashots = pygame.sprite.Group()
        fakeshots = pygame.sprite.Group()
        shadows = pygame.sprite.Group()
        blade = pygame.sprite.Group()
        blood = pygame.sprite.Group()

        #Scoreboard
        score = Score()
        scoresprite = pygame.sprite.RenderPlain(score)

        assassin = Assassin([100, 100], ashots)
        Shadow([100,300], fakeshots, "left", [0,0])

        #Text
        TEXT = "They sent an 'The Assassin' for me! Please, defeat him!"
        text = Text(TEXT)
        
        
        #Create Characters
        global tesi
        global gunner
        if hero == "tesi":
                tesi = Tesi(blade)
                life = Life(tesi)
                Mana(tesi)
                lifesprite = pygame.sprite.RenderPlain(life)
                heroes = pygame.sprite.Group(tesi)
                objects = pygame.sprite.Group(tesi, assassin, score, life, text)
        if hero == "gunner":
                gunner = Hero(shots)
                life = Life(gunner)
                Mana(gunner)
                lifesprite = pygame.sprite.RenderPlain(life)
                heroes = pygame.sprite.Group(gunner)
                objects = pygame.sprite.Group(gunner, assassin, score, life, text)

        #Creating an impassable block! Excitement abounds!
        #Block works! Now to map out the river!
        middle = Block([420, 10])
        middle1 = Block([420, 40])
        middle2 = Block([420, 80])
        middle3 = Block([420, 120])
        middle4 = Block([430, 160])
        middle5 = Block([430, 200])
        middle6 = Block([460, 240])
        middle7 = Block([430, 280])
        middle8 = Block([420, 310])
        middle9 = Block([413, 400])
        middle10 = Block([435, 434])
        middle11 = Block([455, 456])
        middle12 = Block([488, 488])
        middle13 = Block([520, 496])
        middle14 = Block([557, 503])
        middle15 = Block([575, 536])
        middle16 = Block([588, 564])
        east1 = Block([464, 153])
        east2 = Block([504, 175])
        east3 = Block([543, 181])
        east4 = Block([574, 210])
        east5 = Block([575, 303])
        east6 = Block([570, 351])
        east7 = Block([544, 371])
        east8 = Block([524, 404])
        east9 = Block([495, 421])
        west1 = Block([376, 188])
        west2 = Block([323, 202])
        west3 = Block([290, 213])
        west4 = Block([240, 220])
        west5 = Block([141, 209])
        west6 = Block([108, 163])
        west7 = Block([72, 148])
        west8 = Block([42, 133])
        west9 = Block([3, 121])
        
        #Checkmarks to avoid repeating text
        CHECKMARK1 = 0
        CHECKMARK2 = 0
        
        #Create Game Groups
        gassassin = pygame.sprite.Group(assassin)
        blocks = pygame.sprite.Group(middle, middle1, middle2,
                                     middle3, middle4, middle5,
                                     middle6, middle7, middle8,
                                     middle9, middle10, middle11,
                                     middle12, middle13, middle14,
                                     middle15, middle16, east1,
                                     east2, east3, east4, east5,
                                     east6, east7, east8, east9,
                                     west1, west2, west3, west4,
                                     west5, west6, west7, west8,
                                     west9)
        
        #Default groups for each sprite class
        Shot.containers = shots
        PowerShot.containers = pshots
        Shadow.containers = shadows
        
        # Blit everything to the screen
        screen.blit(background, (0, 0))
        pygame.display.flip()

        #Tesi's blade
        BLADE = 1
        COLLIDELATENCY = 0

        #Assassin creates an illusional shadow
        shadowspawn = SHADOW_SPAWN
        SALIVE = 0

        # Initialise clock
        clock = pygame.time.Clock()

        # Event loop
        while 1:
            
                clock.tick(60)

                COLLIDELATENCY = COLLIDELATENCY - 1
                if hero == "tesi":
                        loc = tesi.rect
                if hero == "gunner":
                        loc = gunner.rect
                        
                assassin.aim(loc)

                if SALIVE == 1:
                        shadow.aim(loc)

                if shadowspawn > 0:
                        shadowspawn = shadowspawn - 1
                elif not int(random.random() * SHADOW_ODDS):
                        shadowspawn = SHADOW_SPAWN
                        loc = assassin.rect.center
                        facing = assassin.facing
                        running = assassin.movepos
                        shadow = Shadow(loc, fakeshots, facing, running)
                        shadows.add(shadow)
                        SALIVE = 1
                            
                if hero == "tesi":
                        for event in pygame.event.get():
                                if event.type == QUIT: 
                                        pygame.quit()
                                        return
                                if event.type == KEYDOWN:
                                        if event.key == K_e:
                                                tesi.healing = 1
                                        if event.key == K_SPACE:
                                                if BLADE == 1:
                                                        tesi.throw(blade)
                                                        BLADE = BLADE - 1
                                                        COLLIDELATENCY = 60
                                                        assassin.dodge()
                                        if event.key == K_w:
                                                tesi.moveup()
                                        if event.key == K_s:
                                                tesi.movedown()
                                        if event.key == K_a:
                                                tesi.moveleft()
                                        if event.key == K_d:
                                                tesi.moveright()
                                        if event.key == K_l:
                                                if BLADE == 1:
                                                        tesi.swing(blade)
                                                        COLLIDELATENCY = 150
                                elif event.type == KEYUP:
                                        if event.key == K_e:
                                                tesi.healing = 0
                                        if event.key == K_a or event.key == K_d or event.key == K_w or event.key == K_s:
                                                tesi.state = "still"

                        # Tesi gets his blade back
                        if COLLIDELATENCY <= 0:
                                if pygame.sprite.spritecollide(tesi, blade, dokill):
                                        BLADE = BLADE + 1

                        if pygame.sprite.spritecollide(tesi, ashots, dokill):
                                tesi.bleed(blood)
                                tesi.life = tesi.life - 6


                if hero == "gunner":
                        for event in pygame.event.get():
                                if event.type == QUIT: 
                                        pygame.quit()
                                        return
                                if event.type == KEYDOWN:
                                        if event.key == K_e:
                                                gunner.powershot(pshots)
                                        if event.key == K_SPACE:
                                                gunner.doublefire(shots)
                                                assassin.dodge()
                                                        
                                        if event.key == K_w:
                                                gunner.moveup()
                                        if event.key == K_s:
                                                gunner.movedown()
                                        if event.key == K_a:
                                                gunner.moveleft()
                                        if event.key == K_d:
                                                gunner.moveright()
                                elif event.type == KEYUP:
                                        if event.key == K_a or event.key == K_d or event.key == K_w or event.key == K_s:
                                                gunner.state = "still"


                        if pygame.sprite.spritecollide(gunner, ashots, dokill):
                                gunner.bleed(blood)
                                gunner.life = gunner.life - 10
                                gunner.knockback()
                      

                if pygame.sprite.groupcollide(shadows, blade, dokill, dontkill) or pygame.sprite.groupcollide(shadows, shots, dokill, dokill):
                        a = "Assassin: What's the matter? Can't hit me? Haha!"
                        b = "Assassin: Come on, stop trying to hit me and hit me!"
                        c = "Assassin: What are you swinging at? I'm right here!"
                        d = "Assassin: Bwahahahaha!"
                        e = "Assassin: Super ketchup, premio tomato, catfish tuna."
                        msg = random.choice((a, b, c, d, e))
                        newText = Text(msg)
                        objects.add(newText)
                        shadows.empty()
                        SALIVE = 0

                if pygame.sprite.spritecollide(assassin, blade, dontkill):
                        assassin.bleed(blood)
                        assassin.life = assassin.life - 2
                        score.plus(1)

                if pygame.sprite.spritecollide(assassin, shots, dokill):
                        assassin.bleed(blood)
                        assassin.life = assassin.life - 5
                        score.plus(1)

                if pygame.sprite.spritecollide(assassin, pshots, dontkill):
                        assassin.bleed(blood)
                        assassin.life = assassin.life - 8
                        score.plus(1)

                if pygame.sprite.groupcollide(blocks, heroes, dontkill, dontkill):
                        if hero == "tesi":
                                middle.collision(tesi)
                        if hero == "gunner":
                                middle.collision(gunner)

                if pygame.sprite.groupcollide(blocks, gassassin, dontkill, dontkill):
                        middle.collision(assassin)

                if assassin.life <= 0:
                        if CHECKMARK1 == 0:
                                msg = "Professor: Incredible, you defeated 'The Assassin'! Yippie!"
                                newText = Text(msg)
                                objects.add(newText)
                                CHECKMARK1 = 1
                                

                shadows.clear(screen, background)
                shadows.update()
                shadows.draw(screen)

                blood.clear(screen, background)
                blood.update()
                blood.draw(screen)
                
                shots.clear(screen, background)
                shots.update()
                shots.draw(screen)

                pshots.clear(screen, background)
                pshots.update()
                pshots.draw(screen)

                ashots.clear(screen, background)
                ashots.update()
                ashots.draw(screen)

                fakeshots.clear(screen, background)
                fakeshots.update()
                fakeshots.draw(screen)
                
                blade.clear(screen, background)
                blade.update()
                blade.draw(screen)
                
                objects.clear(screen, background)
                objects.update()
                objects.draw(screen)

                blocks.clear(screen, background)
                blocks.update()
                blocks.draw(screen)
                
                pygame.display.flip()
예제 #5
0
class Game(GoldFrame.GamePlugin):
    _gamedata = None
    _basepath = None
    _datafile = None
    _cfg = None
    assassin = None
    _datafile = 'assassinsgreed.dat'
    _alive_actions = {
        'hidden': ['reroll'],
        'active': ['assassinate', 'fight', 'heal', 'buy', 'collect', 'climb'],
    }
    _dead_actions = {
        'active': ['reroll'],
        'hidden': ['assassinate', 'fight', 'heal', 'buy', 'collect', 'climb'],
    }
    metadata = {
        'name': "Assassin's Greed",
        'gamekey': 'assassinsgreed',
        'personal_hero': True,
        'broadcast_actions': [],
        'actions': [
            {
                'key': 'assassinate',
                'name': 'Assassinate',
                'description': 'Find a villain to assassinate.',
                'img': '/images/assassinsgreed/icon-assassinate.png',
                'tinyimg': '/images/assassinsgreed/tiny-icon-assassination.png',
                'color': '#C30017',
                'button': 'active',
            },
            {
                'key': 'fight',
                'name': 'Fight',
                'description': 'Find a villain to assassinate.',
                'img': '/images/assassinsgreed/icon-fight.png',
                'tinyimg': '/images/assassinsgreed/tiny-icon-fight.png',
                'color': '#C30017',
                'button': 'active',
            },
            {
                'key': 'heal',
                'name': 'Heal',
                'description': 'Heal to regain some health.',
                'img': '/images/assassinsgreed/icon-rest.png',
                'tinyimg': '/images/assassinsgreed/tiny-icon-health.png',
                'color': '#004C7B',
                'button': 'active',
            },
            {
                'key': 'buy',
                'name': 'Buy',
                'description': 'Buy items from a local merchant.',
                'img': '/images/assassinsgreed/icon-buy.png',
                'tinyimg': '/images/assassinsgreed/tiny-icon-buy.png',
                'color': '#C30017',
                'button': 'active',
                'arguments': [
                    {
                        'type': 'list',
                        'key': 'item',
                        'name': 'Item',
                        'description': 'Item to buy',
                        'items': ['Potion', 'Smokebomb', 'Splinterbomb', 'Dagger'],
                    },
                    {
                        'type': 'input',
                        'key': 'amount',
                        'name': 'Amount',
                        'description': 'Amount of items to buy',
                    },
                ]
            },
            {
                'key': 'collect',
                'name': 'Collect Feathers',
                'description': 'Search for feathers.',
                'img': '/images/assassinsgreed/icon-collect.png',
                'tinyimg': '/images/assassinsgreed/tiny-icon-feathers.png',
                'color': '#E9B700',
                'button': 'active',
            },
            {
                'key': 'climb',
                'name': 'Climb',
                'description': 'Climb a tower in the city.',
                'img': '/images/assassinsgreed/icon-climb.png',
                'tinyimg': '/images/assassinsgreed/tiny-icon-towers.png',
                'color': '#351E00',
                'button': 'active',
            },
            {
                'key': 'reroll',
                'name': 'Reroll',
                'description': 'Reroll a new assassin if the current is dead.',
                'img': '/images/assassinsgreed/icon-reroll.png',
                'tinyimg': '/images/assassinsgreed/tiny-icon-reroll.png',
                'button': 'button',
            },
            {
                'key': 'stats',
                'name': 'Stats',
                'description': 'Update character sheet.',
                'button': 'hidden',
            },
        ],
        'stats_img': '/images/assassinsgreed/icon-stats.png',
        'stats': [
            {
                'key': 'name',
                'name': 'Name',
                'description': '',
                'type': 'string',
            },
            {
                'key': 'strength',
                'name': 'Strength',
                'description': '',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-strength.png',
            },
            {
                'key': 'health',
                'name': 'Health',
                'description': '',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-health.png',
            },
            {
                'key': 'hurt',
                'name': 'Hurt',
                'description': '',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-hurt.png',
            },
            {
                'key': 'towers',
                'name': 'Towers',
                'description': '',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-towers.png',
            },
            {
                'key': 'kills',
                'name': 'Kills',
                'description': '',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-kills.png',
            },
            {
                'key': 'assassinations',
                'name': 'Assassinations',
                'description': '',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-assassinations.png',
            },
            {
                'key': 'feathers',
                'name': 'Feathers',
                'description': '',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-feathers.png',
            },
            {
                'key': 'potions',
                'name': 'Potions',
                'description': 'Health potions.',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-potions.png',
            },
            {
                'key': 'smokebombs',
                'name': 'Smokebombs',
                'description': 'Smokebombs',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-smokebombs.png',
            },
            {
                'key': 'splinterbombs',
                'name': 'Splinterbombs',
                'description': 'Splinterbombs',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-splinterbombs.png',
            },
            {
                'key': 'daggers',
                'name': 'Daggers',
                'description': 'Daggers',
                'type': 'integer',
                'img': '/images/assassinsgreed/tiny-icon-daggers.png',
            },
            {
                'key': 'alive',
                'name': 'Alive',
                'type': 'boolean',
                'description': '',
            },
        ],
        'extra_info': {
            'hurt_in_fight': {
                'name': 'Hurt',
                'cls': 'hurtInfo',
            },
            'hurt_by_action': {
                'name': 'Hurt',
                'cls': 'hurtInfo',
            },
            'healed': {
                'name': 'Healed',
                'cls': 'restInfo',
            },
            'gold': {
                'name': 'Gold',
                'cls': 'lootInfo',
            },
            'towers': {
                'name': 'Towers',
                'style': 'color: #351E00',
            },
            'feathers': {
                'name': 'Feathers',
                'style': 'color: #666',
            },
            'dinged': {
                'name': 'Dinged',
                'style': 'color: teal',
            },
            'item': {
                'name': 'Item',
                'style': 'color: green',
            },
            'total_price': {
                'name': 'Price',
                'style': 'color: mediumorchid',
            },
        },
    }
    _items = {
        'Potion': { 'key': 'potions', 'price': 10 },
        'Smokebomb': { 'key': 'smokebombs', 'price': 25 },
        'Splinterbomb': { 'key': 'splinterbombs', 'price': 15 },
        'Dagger': { 'key': 'daggers', 'price': 10 },
    }

    def template_charsheet(self):
        return """
        <h1 id="nameValue" class="nameValue">{{ name }}</h1>
        <ul class="charsheetList">
          <li class="statItem" id="strengthStatDiv"><img src="/images/assassinsgreed/tiny-icon-strength.png" width="16" height="16" alt="Strength" title="Strength" /><span class="statValue" id="strengthValue">{{ strength }}</span></li>
          <li class="statItem" id="healthStatDiv"><img src="/images/assassinsgreed/tiny-icon-health.png" width="16" height="16" alt="Health" title="Health" /><span class="statValue" id="hurthealthValue">{{ current_health }}/{{ health }}</span></li>
          <li class="statItem" id="towersStatDiv"><img src="/images/assassinsgreed/tiny-icon-towers.png" width="16" height="16" alt="Towers" title="Towers" /><span class="statValue" id="towersValue">{{ towers }}</span></li>
          <li class="statItem" id="assassinationsStatDiv"><img src="/images/assassinsgreed/tiny-icon-assassinations.png" width="16" height="16" alt="Assassinations" title="Assassinations" /><span class="statValue" id="assassinationsValue">{{ assassinations }}</span></li>
          <li class="statItem" id="killsStatDiv"><img src="/images/assassinsgreed/tiny-icon-kills.png" width="16" height="16" alt="Kills" title="Kills" /><span class="statValue" id="killsValue">{{ kills }}</span></li>
          <li class="statItem" id="feathersStatDiv"><img src="/images/assassinsgreed/tiny-icon-feathers.png" width="16" height="16" alt="Feathers" title="Feathers" /><span class="statValue" id="feathersValue">{{ feathers }}</span></li>
          <li class="statItem" id="goldStatDiv"><img src="/images/assassinsgreed/tiny-icon-gold.png" width="16" height="16" alt="Gold" title="Gold" /><span class="statValue" id="lootValue">{{ gold }}</span></li>
        </ul>
        """

    def template_actionline(self):
        return "<li class='actionLine {{ cls }}' id='action_{{ id }}'>{{ line }}{{ extraInfo }}</li>"

    def setup(self):
        # Configure datahandler backend.
        #self.setup_database()

        # Read saved assassin.
        self.get_assassin(self._userid)

    @LogUsageCPU
    def setup_database(self):
        """
        Sets up either a sqlite database or a GAE DataStore depending on configuration.
        """
        datahandler = self._cfg.get('LOCAL', 'datahandler')
        if datahandler == 'sqlite':
            from AGSQLHandler import AGSQLHandler
            self._dh = AGSQLHandler(self._debug)
        elif datahandler == 'datastore':
            from AGDSHandler import AGDSHandler
            self._dh = AGDSHandler(self._debug)
        else:
            raise GoldFrameConfigException, "Unknown datahandler: %s" % datahandler

    @LogUsageCPU
    def get_assassin(self, userid=None):
        self.assassin = self._dh.get_alive_assassin(userid)

    def get_boss(self, lvl=None):
        if not lvl:
            lvl = self.assassin.towers or 1
        boss = random.choice(self._gamedata['boss'])
        target = Target(lvl, boss, True)
        return target

    def get_target(self, lvl=None):
        if not lvl:
            lvl = self.assassin.towers or 1
        targets = []
        for target in self._gamedata['target']:
            if lvl >= target['lowlevel'] and (target['highlevel'] == 0 or lvl <= target['highlevel']):
                targets.append(target['name'])
        if targets:
            name = random.choice(targets)
        else:
            name = None
        # TODO: Bosses need to be supported.
        target = Target(self.assassin.towers, name)
        return target

    def play(self, command, asdict=False, arguments=None):
        # Load user assassin if needed.
        if self.assassin == None or self.assassin.userid != self._userid:
            self.get_assassin(self._userid)

        logging.info(arguments)

        # Handle action command.
        response = None
        actionbuttons = None
        if command in ['reroll']:
            response = self.action_reroll(arguments)
            actionbuttons = self._alive_actions
        elif not self.assassin or not self.assassin.alive:
            msg = self.get_text('nochampion')
            response = {
                'message': msg,
                'success': 0,
            }
        else:
            try:
                func = getattr(self, 'action_%s' % command)
            except AttributeError:
                return None
            else:
                response = func(arguments)

        self.save_data()

        if not self.assassin or not self.assassin.alive:
            actionbuttons = self._dead_actions

        return self.return_response(response, asdict, actionbuttons)

    def save_data(self):
        if self.assassin:
            self._dh.save_data(self.assassin)

    def get_alive_assassin(self):
        assassin = self._dh.get_alive_assassin()
        return assassin

    def action_reroll(self, aguments):
        if self.assassin and self.assassin.alive:
            response = {
                'message': self.get_text('noreroll') % self.assassin.get_attributes(),
                'success': 0,
            }
            return response
        else:
            # Reroll new assassin.
            self.assassin = Assassin(self._gamedata['assassin'], userid=self._userid)
            self.assassin.reroll()
            attribs = self.assassin.get_attributes()
            logging.info(attribs)
            msg = self.get_text('newassassin')
            try:
                msg = msg % attribs
            except KeyError, e:
                logging.error("Couldn't find a given text replacement: %s" % str(e))
            response = {
                'message': msg,
                'data': {
                    'hero': attribs,
                }
            }
            return response