예제 #1
0
    def parser(self, x):
        cmd=x.split()[0].casefold()
        params=x.split()[1:]
        if '-h' in params:
            self.docs(cmd)
            return

        # HELP
        if cmd=='help':
            if not len(params):
                print(css.HEADER+'[*]'+css.ENDC+' List of commands:')
                [print(command) for command in json.loads(open('core/commands.json').read())['commands']]
            else:
                self.docs(params[0].casefold())
        
        # SHOW
        elif cmd=='show':
            if '-a' in params:
                self.overrideshow=True
            if 'id' in params or '-id' in params:
                self.showids=True
                self.showpos=False
            elif 'pos' in params or '-pos' in params:
                self.showids=False
                self.showpos=True
            elif 'null' in params or '-null' in params:
                self.showids=False
                self.showpos=False
            else:
                raise errs.ParamError(params)

        # SELECT
        elif cmd=='select':
            if '-id' in params:
                v=int(params[params.index('-id')+1])
                for bot in self.robots:
                    if bot.id==v:
                        if bot==self.player:
                            raise errs.SameObjError(bot, self.player)
                            return
                        if int(bot.pos[0])>=(int(self.player.pos[0])-self.player.action_range) and int(bot.pos[0])<=(int(self.player.pos[0])+self.player.action_range):
                            if int(bot.pos[1])>=(int(self.player.pos[1])-self.player.action_range) and int(bot.pos[1])<=(int(self.player.pos[1])+self.player.action_range):
                                self.player.selected=bot
                            else:
                                raise errs.ActionRangeError(bot)
                        else:
                            raise errs.ActionRangeError(bot)
            elif '-pos' in params:
                v=params[params.index('-pos')+1]
                for bot in self.robots:
                    if bot.pos==[int(i) for i in v.split(',')]:
                        if int(bot.pos[0])>=(int(self.player.pos[0])-self.player.action_range) and int(bot.pos[0])<=(int(self.player.pos[0])+self.player.action_range):
                            if int(bot.pos[1])>=(int(self.player.pos[1])-self.player.action_range) and int(bot.pos[1])<=(int(self.player.pos[1])+self.player.action_range):
                                self.player.selected=bot
                            else:
                                raise errs.ActionRangeError(bot)
                        else:
                            raise errs.ActionRangeError(bot)
            else:
                raise errs.ParamError(params)

        # MOVE
        elif cmd=='move':
            self.player.move(params[0])
        
        # EXIT && BYE
        elif cmd in ['bye', 'exit']:
            print('[?] Are you sure?')
            c=getch()
            if c in ['y','s']:
                # accredita
                #globals()['srcdata']['score']+=self.gamepoints
                main()
            elif c=='n':
                return
            else:
                print(css.FAIL+'[ERR]'+css.ENDC+' Unrecognized key, back to game.')
        
        # SHOP
        elif cmd=='shop':
            self.inshop=True
            if '-s' in params or '--show' in params:
                pass
        
        # RECO
        elif cmd in ['reco', 'recognitors']:
            if not len(params):
                self.Team.parser('',self.player)
            else:
                self.Team.parser(' '.join(params), self.player)

        # NOT FOUND        
        else:
            raise errs.CommandNotFoundError(cmd)
예제 #2
0
파일: __init__.py 프로젝트: fhvck/main
 def move(self, pos):
     newx = int(pos.split(',')[0])
     x = self.pos[0]
     newy = int(pos.split(',')[1])
     y = self.pos[1]
     skip = None
     if x in [0, 5]:
         if newx > x:
             if x == 4:
                 skip = 'x'
         else:
             if x == 0:
                 skip = 'x'
     if y in [0, 4]:
         if newy > y:
             if y == 3:
                 skip = 'y'
         else:
             if y == 0:
                 skip = 'y'
     if not skip:
         for bot in self.Engine.robots:
             if bot.pos == [newx, newy]:
                 if not bot.id == self.id:
                     print(css.FAIL + '[ERR]' + css.ENDC + ' ID:', bot.id,
                           'already in', newx, ',', newy, '!')
                 return
             if newx <= self.pos[0] + self.action_range and newx >= self.pos[
                     0] - self.action_range:
                 if newy <= self.pos[
                         1] + self.action_range and newy >= self.pos[
                             1] - self.action_range:
                     self.pos = [newx, newy]
                 else:
                     print(errs.ActionRangeError(pos=[newx, newy]))
                     return
             else:
                 print(errs.ActionRangeError(pos=[newx, newy]))
                 return
     else:
         if skip == 'y':
             for bot in self.Engine.robots:
                 if bot.pos == [newx, y]:
                     if not bot.id == self.id:
                         print(css.FAIL + '[ERR]' + css.ENDC + ' ID:',
                               bot.id, 'already in', newx, ',', newy, '!')
                         return
                 # newpos=[newx, y]
                 if newx <= self.pos[
                         0] + self.action_range and newx >= self.pos[
                             0] - self.action_range:
                     if y <= self.pos[
                             1] + self.action_range and y >= self.pos[
                                 1] - self.action_range:
                         self.pos = [newx, y]
                     else:
                         print(errs.ActionRangeError(pos=[newx, y]))
                         return
                 else:
                     print(errs.ActionRangeError(pos=[newx, y]))
                     return
         else:
             for bot in self.Engine.robots:
                 if bot.pos == [x, newy]:
                     if not bot.id == self.id:
                         print(css.FAIL + '[ERR]' + css.ENDC + ' ID:',
                               bot.id, 'already in', newx, ',', newy, '!')
                     return
                 if x <= self.pos[0] + self.action_range and x >= self.pos[
                         0] - self.action_range:
                     if newy <= self.pos[
                             1] + self.action_range and newy >= self.pos[
                                 1] - self.action_range:
                         self.pos = [x, newy]
                     else:
                         print(errs.ActionRangeError(pos=[x, newy]))
                         return
                 else:
                     print(errs.ActionRangeError(pos=[x, newy]))
                     return