Esempio n. 1
0
 def test_length(self):
     """Test length float validation"""
     m = Magnet()
     self.assertEqual(m.length, 0.1)
     m.length = 'a'
     self.assertEqual(m.length, 0.1)
     m.length = 1
     self.assertEqual(m.length, 0.1)
     m.length = 0.05
     self.assertEqual(m.length, 0.05)
Esempio n. 2
0
 def test_tol(self):
     """Test tol float validation"""
     m = Magnet()
     self.assertEqual(m.tol, 0.05)
     m.tol = 'a'
     self.assertEqual(m.tol, 0.05)
     m.tol = 1
     self.assertEqual(m.tol, 0.05)
     m.tol = 0.1
     self.assertEqual(m.tol, 0.1)
Esempio n. 3
0
 def init_magnet(self):
     if self.kw.findkw('magnet_axis').is_set():
         mag = self.kw.getkw('magnet_axis')[0]
     elif self.kw.findkw('magnet').is_set():
         mag = self.kw.getkw('magnet')[0]
     else:
         raise ValueError('No magnetic field specified')
     self.magnet = Magnet(mag, self.grid)
 def add_Focus(self, L, Bp, rp):
     # L: Length of LENS
     # Bp: field strength at pole face
     # rp: radius of bore inside magnet
     self.numElements += 1
     args = [L, Bp, rp]
     el = Magnet(self, 'LENS', args)
     self.lattice.append(el)
Esempio n. 5
0
    def generate_magnets(self):

        magnet_cnt = 0

        for j in range(203, columns - columnsAtATime - 25, 401):
            x = random.randint(5, rows - 5)
            y = j + random.randint(0, 15)

            Magnet(x, y, self, magnet_cnt)

            magnet_cnt += 1
Esempio n. 6
0
 def test_properties(self):
     """Test that all the properties we expect exist"""
     m = Magnet()
     self.assertEqual(isinstance(type(m).name, property), True)
     self.assertEqual(isinstance(type(m).bctrl, property), True)
     self.assertEqual(isinstance(type(m).bact, property), True)
     self.assertEqual(isinstance(type(m).bdes, property), True)
     self.assertEqual(isinstance(type(m).ctrl_value, property), True)
     self.assertEqual(isinstance(type(m).length, property), True)
     self.assertEqual(isinstance(type(m).pv_props, property), True)
     self.assertEqual(isinstance(type(m).bdes, property), True)
     self.assertEqual(isinstance(type(m).tol, property), True)
Esempio n. 7
0
 def __init__(self,
              rows=30,
              cols=1000,
              start_x=23,
              start_y=17,
              boss_x=950,
              boss_y=5):
     self._score = 0
     self._coins = 0
     self._board = Board(rows, cols)
     self._hero = Mandalorian(start_x, start_y)
     self._boss = Enemy(boss_x, boss_y)
     self._getch = getInput._getChUnix()
     self._rem_time = 100
     self._fired_bullets = []
     self._thrown_snowballs = []
     self._coins_placed = []
     self._zappers = []
     self._speedup = False
     self._magnet = Magnet(0, 0)
     self._powerup = Powerup(0, 0)
     self._speedup = False
     self._ground = Ground()
Esempio n. 8
0
 def test_methods(self):
     """Test that all the methods we expect exist"""
     m = Magnet()
     self.assertEqual(inspect.ismethod(m.trim), True)
     self.assertEqual(inspect.ismethod(m.perturb), True)
     self.assertEqual(inspect.ismethod(m.con_to_des), True)
     self.assertEqual(inspect.ismethod(m.save_bdes), True)
     self.assertEqual(inspect.ismethod(m.load_bdes), True)
     self.assertEqual(inspect.ismethod(m.undo_bdes), True)
     self.assertEqual(inspect.ismethod(m.dac_zero), True)
     self.assertEqual(inspect.ismethod(m.calibrate), True)
     self.assertEqual(inspect.ismethod(m.standardize), True)
     self.assertEqual(inspect.ismethod(m.reset), True)
     self.assertEqual(inspect.ismethod(m.find_pv_attrs), True)
     self.assertEqual(inspect.ismethod(m.add_clbk), True)
     self.assertEqual(inspect.ismethod(m.remove_clbk), True)
Esempio n. 9
0
 def generate(self, num):
     if num == 0 and t.time() - self._lastcoin > self._coingen / self._boost:
         y = random.randrange(4, self._columnlen - 3, 1)
         paisa = Coin(self._rowlen - 5, y, ascii[1])
         self._objectlist.append(paisa)
         self._lastcoin = t.time()
     elif num == 2 and t.time(
     ) - self._lastbeam > self._beamgen / self._boost:
         shape = random.randrange(0, 3, 1)
         if shape == 0:
             y = random.randrange(4, self._columnlen - 3, 5)
             fire = Beam(self._rowlen - 19, y, ascii[3], 0)
         elif shape == 1:
             y = random.randrange(4, self._columnlen - 11, 5)
             fire = Beam(self._rowlen - 4, y, "o", 1)
         elif shape == 2:
             y = random.randrange(4, self._columnlen - 11, 5)
             fire = Beam(self._rowlen - 19, y, "o", 2)
         self._objectlist.append(fire)
         self._lastbeam = t.time()
     elif num == 4:
         y = random.randrange(4, self._columnlen - 3, 1)
         vroom = Boost(self._rowlen - 6, y, ascii[2])
         self._objectlist.append(vroom)
         self._timeboost = t.time()
     elif num == 5:
         y = random.randrange(4, self._columnlen - 5, 1)
         chep = Magnet(self._rowlen - 9, y, ascii[5])
         self._objectlist.append(chep)
         self._lastmagnet = t.time()
     elif num == 6:
         y = 42
         bandook = AT(self._rowlen - 19, y, ascii[8])
         self._objectlist.append(bandook)
     elif num == 7:
         y = 7
         gaadi = Ship(self._rowlen - 27, y, ascii[9])
         self._objectlist.append(gaadi)
Esempio n. 10
0
    def get_magnets(self):
        self.magnet_list = []

        for i in self.content.split('<li class="media">'):
            if '日期' in i:
                # print(i)
                date = re.search(r'日期:<span class="s_b">(.*?)</span>',
                                 i)[1].replace('-', '')
                size = re.search(r'大小:<span class="s_b">(.*?)</span>', i)[1]
                size = round(
                    (float(size.split(' ')[0])) / 1000 if 'gb'
                    not in size.lower() else float(size.split(' ')[0]), 4)
                pv = re.search(r'点击:<span class="s_b">(.*?)</span>', i)[1]
                title = re.search(r'title="(.*?)"', i)[1]

                href = re.search(r'<a href="(.*?)"', i)[1]
                a = requests.get(url='http://seed8.cc%s' %
                                 href).content.decode('utf-8')
                url = 'magnet' + re.search(
                    r'<a href="magnet(.*?)" id="down-url"', a)[1]

                m = Magnet(title, size, date, pv, url)
                self.magnet_list.append(m)
Esempio n. 11
0
 def test_name(self):
     """Test we get expected default"""
     m = Magnet()
     self.assertEqual(m.name, 'SOL1B')
Esempio n. 12
0
 def __init__(self, x, y):
     Magnet.__init__(self, x, y)
     self._token = 'P'
Esempio n. 13
0
class Engine(Board, Mandalorian, Enemy, Bullet, Magnet, Coins, Ground, Zapper,
             Snowball):
    def __init__(self,
                 rows=30,
                 cols=1000,
                 start_x=23,
                 start_y=17,
                 boss_x=950,
                 boss_y=5):
        self._score = 0
        self._coins = 0
        self._board = Board(rows, cols)
        self._hero = Mandalorian(start_x, start_y)
        self._boss = Enemy(boss_x, boss_y)
        self._getch = getInput._getChUnix()
        self._rem_time = 100
        self._fired_bullets = []
        self._thrown_snowballs = []
        self._coins_placed = []
        self._zappers = []
        self._speedup = False
        self._magnet = Magnet(0, 0)
        self._powerup = Powerup(0, 0)
        self._speedup = False
        self._ground = Ground()

    def create_powerup(self):
        flag = False
        while flag == False:
            x = random.randint(100, 700)
            y = random.randint(2, 17)
            self._powerup.set_coords(x, y)
            flag = self._powerup.create_obj(self._board)

    def create_magnet(self):
        flag = False
        while flag == False:
            x = random.randint(100, 700)
            y = random.randint(2, 17)
            self._magnet.set_coords(x, y)
            flag = self._magnet.create_obj(self._board)

    def create_all_zappers(self):
        for i in range(1, 20):  # 25 zappers
            mod = random.randint(5, 34)
            start_x = mod + i * 40
            start_y = random.randint(5, 17)
            Z = Zapper(start_x, start_y)
            if Z.create_zapper(self._board) == True:
                self._zappers.append(Z)

    def create_all_coins(self):
        for i in range(9):
            mod = random.randint(0, 9)
            start_x = mod + i * 85
            start_y = random.randint(5, 17)
            C = Coins(start_x, start_y)
            if C.create_obj(self._board) == True:
                self._coins_placed.append(C)

    def run(self):
        pos_x = 0
        gravity = 1
        fall_at_time = 0
        mag_exists = True
        iterator = 0
        start = False
        dims = self._board.get_dims()
        MAT = self._board.get_matrix()
        COPY = self._board.get_copy()
        hero_size = self._hero.get_dim()
        not_damage = self._hero.get_not_damage()

        def alarmhandler(signum, frame):
            raise TypeError

        def getinp(timeout=0.15):
            signal.signal(signal.SIGALRM, alarmhandler)
            signal.setitimer(signal.ITIMER_REAL, timeout)
            try:
                ch = self._getch()
                signal.alarm(0)
                return ch
            except TypeError:
                pass
            signal.signal(signal.SIGALRM, signal.SIG_IGN)
            return ''

        def terminate(msg):
            # os.system("killall -9 aplay")
            ##################UPDATE SCORE!! #########################
            os.system('reset')
            print(msg)
            exit()

        # self._board.Place(0,dims[1],0,dims[0],'*')
        self.create_all_coins()
        self.create_all_zappers()
        self.create_magnet()
        self.create_powerup()
        self._ground.create_ground(self._board)
        T = self._magnet.get_coords()
        x_mag = T[0]
        y_mag = T[1]
        print('\033[0;0H', end='')
        self._board.CopyBoard()
        # print(type(self._coins))
        X = self._hero.position(MAT, COPY)
        self._coins += X[0]
        self._speedup = self._speedup or X[1]
        Z = Zapper(0, 0)
        MAT = self._board.get_matrix()
        COPY = self._board.get_copy()
        self._boss.position(MAT, COPY)
        MAT = self._board.get_matrix()
        COPY = self._board.get_copy()
        self._hero.check_collision(MAT)
        T1 = time.time()
        T2 = T1
        T3 = T1
        last_activated = None
        start = True
        sped = False
        while True:
            # os.system('clear')
            self._score = self._coins * 50 + (10 -
                                              self._boss.get_lives()) * 1000
            # print(self._speedup)
            if (self._speedup == True and sped == False):
                self._board.set_speed(self._board.get_speed() + 1)
                sped = True
            if start == False and self._hero.get_shield() == True and round(
                    time.time()) - round(last_activated) >= 10:
                self._hero.set_shield(False)
            elif start == True and round(time.time()) - round(T1) > 2:
                self._hero.set_shield(False)
                start = False
            self._hero.shielded()
            MAT = self._board.get_matrix()
            COPY = self._board.get_copy()
            iterator += 1
            self._rem_time = 100 - (round(time.time()) - round(T1))
            if self._rem_time < 0:
                terminate("You run out of time.\n You lose. See you soon..\n")
            print('\033[0;0H')
            # time.sleep(0.6)
            # for i in range(30):
            # for j in range(204):
            # print(bg.CYAN +" ",end ='')
            # print()
            # print('\033[0;0H')
            # time.sleep(0.001)
            # os.system('clear')

            TIME = self._rem_time
            PrintTime = [TIME // 100, (TIME % 100) // 10, (TIME % 10)]
            # print("TIME REMAINING:",PrintTime[0],PrintTime[1],PrintTime[2],end ='\n')
            print("TIME REMAINING : ", PrintTime[0], end='')
            print(PrintTime[1], end='')
            print(PrintTime[2])

            LIVES = self._hero.get_lives()
            PrintLives = [LIVES // 10, (LIVES % 10)]
            print("LIVES:", PrintLives[0], end='')
            print(PrintLives[1])

            print("SCORE:", self._score, end='\n')
            print("COINS:", self._coins, end='\n')

            BOSS = self._boss.get_lives()
            PrintBoss = [BOSS // 10, BOSS % 10]
            print("BOSS LIVES:", PrintBoss[0], end='')
            print(PrintBoss[1])
            if self._hero.die(MAT) == True:
                terminate(
                    "You lost all your lives.\n You lose. See you soon..\n")
            if self._boss.die(MAT) == True:
                terminate("You win!\nYou saved Baby Yoda! See You soon..\n")
            # print(start,":::",round(time.time()) - round(T1))
            pos_hero = self._hero.get_coords()
            hero_x = pos_hero[0]
            hero_y = pos_hero[1]
            ALLOW = self._hero.get_allowed()
            UP = ALLOW[0]
            DOWN = ALLOW[1]
            RIGHT = ALLOW[2]
            LEFT = ALLOW[3]
            # print(ALLOW)

            if abs(
                    hero_x - x_mag
            ) < 100 and x_mag < pos_x + 204 and x_mag > pos_x and iterator % 2 == 1 and mag_exists == True:
                self._hero.disappear(MAT, COPY)
                MAT = self._board.get_matrix()
                COPY = self._board.get_copy()
                self._hero.attract(x_mag, y_mag)
                X = self._hero.position(MAT, COPY)
                self._coins += X[0]
                self._speedup = self._speedup or X[1]
                self._board.set_matrix(MAT)
                self._board.set_copy(COPY)

            elif abs(
                    hero_x - x_mag
            ) < 100 and x_mag < pos_x + 204 and x_mag > pos_x and mag_exists == True:
                self._hero.set_attracted(True)
            else:
                self._hero.set_attracted(False)  # enables gravity

            gravity = fall_at_time // 2 + 1
            inp = getinp()
            if inp == 'q':
                # QUIT
                terminate("See You Soon...")

            elif inp == '7':
                ### HACKS !!!!!
                pos_x = dims[1] - 190

            elif inp == ' ':
                #### SHIELD
                # print("SHIELD!")
                if last_activated == None or round(
                        time.time()) - round(last_activated) >= 60 + 10:
                    self._hero.set_shield(True)
                    last_activated = time.time()
                else:
                    print("RECHARGING SHIELD!!")

            elif inp == 'w':
                # Jump
                if UP == True:
                    MAT = self._board.get_matrix()
                    COPY = self._board.get_copy()
                    self._hero.disappear(MAT, COPY)
                    self._hero.set_moving(True)
                    pos_hero = self._hero.get_coords()
                    hero_x = pos_hero[0]
                    hero_y = pos_hero[1] - 1
                    if hero_y < 0:
                        hero_y = 0
                    self._hero.set_coords(hero_x, hero_y)
                    X = self._hero.position(MAT, COPY)
                    self._coins += X[0]
                    self._speedup = self._speedup or X[1]
                else:
                    MAT = self._board.get_matrix()
                    COPY = self._board.get_copy()
                    pos_hero = self._hero.get_coords()
                    hero_x = pos_hero[0]
                    hero_y = pos_hero[1]
                    for i in range(hero_size[0]):
                        if MAT[hero_y - 1][hero_x + i] not in not_damage:
                            if self._hero.get_shield() == False:
                                self._hero.set_lives(self._hero.get_lives() -
                                                     1)
                            self._hero.disappear(MAT, COPY)
                            if MAT[hero_y - 1][hero_x + i] == '*':  ## ZAPPER
                                Z.erase_zapper(MAT, COPY, hero_x + i,
                                               hero_y - 1)
                            elif MAT[hero_y - 1][hero_x + i] == 'M':  ## MAGNET
                                MAT[hero_y - 1][hero_x + i] = ' '
                                COPY[hero_y - 1][hero_x + i] = ' '
                                mag_exists = False
                            # elif MAT[hero_y-1][hero_x+i] == 'P':
                            #     MAT[hero_y-1][hero_x+i] = ' '
                            #     COPY[hero_y-1][hero_x+i] = ' '
                            #     self._speedup = True
                            #     self._board.set_speed(self._board.get_speed()+1)
                            time.sleep(0.01)
                            X = self._hero.position(MAT, COPY)
                            self._coins += X[0]
                            self._speedup = self._speedup or X[1]
                            ### invincibility
                            self._board.set_matrix(MAT)
                            self._board.set_copy(COPY)
                            # MAT = self._board.get_matrix()
                            # COPY = self._board.get_copy()
                            # pos_hero = self._hero.get_coords()
                            # hero_x = pos_hero[0]
                            # hero_y = pos_hero[1]
                            break

            elif inp == 'a':
                # Go Left
                if LEFT == True:
                    MAT = self._board.get_matrix()
                    COPY = self._board.get_copy()
                    self._hero.disappear(MAT, COPY)
                    self._hero.set_moving(True)
                    self._hero.set_direction(-1)
                    self._hero.set_coords(self._hero.get_coords()[0] - 1,
                                          self._hero.get_coords()[1])
                    X = self._hero.position(MAT, COPY)
                    self._coins += X[0]
                    self._speedup = self._speedup or X[1]

                else:
                    MAT = self._board.get_matrix()
                    COPY = self._board.get_copy()
                    pos_hero = self._hero.get_coords()
                    hero_x = pos_hero[0]
                    hero_y = pos_hero[1]
                    for i in range(hero_size[1]):
                        if MAT[hero_y + i][hero_x - 1] not in not_damage:
                            if self._hero.get_shield() == False:
                                self._hero.set_lives(self._hero.get_lives() -
                                                     1)
                            self._hero.disappear(MAT, COPY)
                            if MAT[hero_y + i][hero_x - 1] == '*':  ## ZAPPER
                                Z.erase_zapper(MAT, COPY, hero_x - 1,
                                               hero_y + i)
                            elif MAT[hero_y + i][hero_x - 1] == 'M':
                                MAT[hero_y + i][hero_x - 1] = ' '
                                COPY[hero_y + i][hero_x - 1] = ' '
                                mag_exists = False
                            # elif MAT[hero_y-1][hero_x+i] == 'P':
                            #     MAT[hero_y-1][hero_x+i] = ' '
                            #     COPY[hero_y-1][hero_x+i] = ' '
                            #     self._speedup = True
                            #     self._board.set_speed(self._board.get_speed()+1)

                            time.sleep(0.01)
                            X = self._hero.position(MAT, COPY)
                            self._coins += X[0]
                            self._speedup = self._speedup or X[1]
                            self._board.set_matrix(MAT)
                            self._board.set_copy(COPY)
                            ### invincibility
                            break

            elif inp == 'd':
                # Go right
                if RIGHT == True:
                    MAT = self._board.get_matrix()
                    COPY = self._board.get_copy()
                    pos_hero = self._hero.get_coords()
                    hero_x = pos_hero[0]
                    hero_y = pos_hero[1]
                    self._hero.disappear(MAT, COPY)
                    self._hero.set_moving(True)
                    self._hero.set_direction(1)
                    self._hero.set_coords(hero_x + 1, hero_y)
                    pos_hero = self._hero.get_coords()
                    hero_x = pos_hero[0]
                    hero_y = pos_hero[1]
                    self._hero.check_collision(MAT)
                    ALLOW = self._hero.get_allowed()
                    UP = ALLOW[0]
                    DOWN = ALLOW[1]
                    RIGHT = ALLOW[2]
                    LEFT = ALLOW[3]
                    if RIGHT == True:
                        self._hero.set_coords(hero_x + 1, hero_y)
                        X = self._hero.position(MAT, COPY)
                        self._coins += X[0]
                        self._speedup = self._speedup or X[1]
                        self._board.set_matrix(MAT)
                        self._board.set_copy(COPY)
                        pos_hero = self._hero.get_coords()
                        hero_x = pos_hero[0]
                        hero_y = pos_hero[1]
                        ALLOW = self._hero.get_allowed()
                        UP = ALLOW[0]
                        DOWN = ALLOW[1]
                        RIGHT = ALLOW[2]
                        LEFT = ALLOW[3]
                        X = self._hero.position(MAT, COPY)
                        self._coins += X[0]
                        self._speedup = self._speedup or X[1]
                        if self._speedup == True:
                            if RIGHT == True:
                                MAT = self._board.get_matrix()
                                COPY = self._board.get_copy()
                                self._hero.disappear(MAT, COPY)
                                self._hero.set_moving(True)
                                self._hero.set_direction(1)
                                self._hero.set_coords(hero_x + 1, hero_y)
                                pos_hero = self._hero.get_coords()
                                hero_x = pos_hero[0]
                                hero_y = pos_hero[1]
                                self._hero.check_collision(MAT)
                                ALLOW = self._hero.get_allowed()
                                X = self._hero.position(MAT, COPY)
                                self._coins += X[0]
                                self._speedup = self._speedup or X[1]
                                UP = ALLOW[0]
                                DOWN = ALLOW[1]
                                RIGHT = ALLOW[2]
                                LEFT = ALLOW[3]

                            else:
                                for i in range(hero_size[1]):
                                    if MAT[hero_y +
                                           i][hero_x +
                                              hero_size[0]] not in not_damage:
                                        if self._hero.get_shield() == False:
                                            self._hero.set_lives(
                                                self._hero.get_lives() - 1)
                                        pos_hero = self._hero.get_coords()
                                        hero_x = pos_hero[0]
                                        hero_y = pos_hero[1]
                                        if MAT[hero_y + i][
                                                hero_x +
                                                hero_size[0]] == '*':  ## ZAPPER
                                            Z.erase_zapper(
                                                MAT, COPY,
                                                hero_x + hero_size[0],
                                                hero_y + i)
                                        elif MAT[hero_y +
                                                 i][hero_x +
                                                    hero_size[0]] == 'M':
                                            MAT[hero_y + i][hero_x +
                                                            hero_size[0]] = ' '
                                            COPY[hero_y +
                                                 i][hero_x +
                                                    hero_size[0]] = ' '
                                            mag_exists = False
                                        # elif MAT[hero_y-1][hero_x+i] == 'P':
                                        #     # print("YE")
                                        #     MAT[hero_y-1][hero_x+i] = ' '
                                        #     COPY[hero_y-1][hero_x+i] = ' '
                                        #     self._speedup = True
                                        #     self._board.set_speed(self._board.get_speed()+1)

                                        time.sleep(0.01)
                                        X = self._hero.position(MAT, COPY)
                                        self._coins += X[0]
                                        self._speedup = self._speedup or X[1]
                                        break
                    else:
                        for i in range(hero_size[1]):
                            if MAT[hero_y + i][hero_x +
                                               hero_size[0]] not in not_damage:
                                if self._hero.get_shield() == False:
                                    self._hero.set_lives(
                                        self._hero.get_lives() - 1)
                                pos_hero = self._hero.get_coords()
                                hero_x = pos_hero[0]
                                hero_y = pos_hero[1]
                                if MAT[hero_y +
                                       i][hero_x +
                                          hero_size[0]] == '*':  ## ZAPPER
                                    Z.erase_zapper(MAT, COPY,
                                                   hero_x + hero_size[0],
                                                   hero_y + i)
                                elif MAT[hero_y + i][hero_x +
                                                     hero_size[0]] == 'M':
                                    MAT[hero_y + i][hero_x +
                                                    hero_size[0]] = ' '
                                    COPY[hero_y + i][hero_x +
                                                     hero_size[0]] = ' '
                                    mag_exists = False
                                # elif MAT[hero_y-1][hero_x+i] == 'P':
                                #     MAT[hero_y-1][hero_x+i] = ' '
                                #     COPY[hero_y-1][hero_x+i] = ' '
                                #     self._speedup = True
                                #     self._board.set_speed(self._board.get_speed()+1)

                                time.sleep(0.01)
                                X = self._hero.position(MAT, COPY)
                                self._coins += X[0]
                                self._speedup = self._speedup or X[1]
                                break
                                #invincibility
                    self._board.set_matrix(MAT)
                    self._board.set_copy(COPY)
                else:
                    # print("!")
                    # time.sleep(1)
                    MAT = self._board.get_matrix()
                    COPY = self._board.get_copy()
                    pos_hero = self._hero.get_coords()
                    hero_x = pos_hero[0]
                    hero_y = pos_hero[1]
                    for i in range(hero_size[1]):
                        if MAT[hero_y + i][hero_x +
                                           hero_size[0]] not in not_damage:
                            if self._hero.get_shield() == False:
                                self._hero.set_lives(self._hero.get_lives() -
                                                     1)
                            self._hero.disappear(MAT, COPY)
                            if MAT[hero_y + i][hero_x +
                                               hero_size[0]] == '*':  ## ZAPPER
                                Z.erase_zapper(MAT, COPY,
                                               hero_x + hero_size[0],
                                               hero_y + i)
                            elif MAT[hero_y + i][hero_x + hero_size[0]] == 'M':
                                MAT[hero_y + i][hero_x + hero_size[0]] = ' '
                                COPY[hero_y + i][hero_x + hero_size[0]] = ' '
                                mag_exists = False
                            # elif MAT[hero_y-1][hero_x+i] == 'P':
                            #     MAT[hero_y-1][hero_x+i] = ' '
                            #     COPY[hero_y-1][hero_x+i] = ' '
                            #     self._speedup = True
                            #     self._board.set_speed(self._board.get_speed()+1)
                            time.sleep(0.01)
                            X = self._hero.position(MAT, COPY)
                            self._coins += X[0]
                            self._speedup = self._speedup or X[1]
                            ### invincibility
                            self._board.set_matrix(MAT)
                            self._board.set_copy(COPY)
                            break

            elif inp == 'k':
                ## FIRE BULLET
                pos_hero = self._hero.get_coords()
                hero_x = pos_hero[0]
                hero_y = pos_hero[1]

                self._fired_bullets += [
                    Bullet(hero_x + self._board.get_speed(),
                           hero_y + self._board.get_speed(),
                           self._hero.get_direction())
                ]

            else:
                self._hero.set_moving(False)

                #### UPDATE NECESSARY
            MAT = self._board.get_matrix()
            COPY = self._board.get_copy()
            pos_hero = self._hero.get_coords()
            hero_x = pos_hero[0]
            hero_y = pos_hero[1]
            ALLOW = self._hero.get_allowed()
            UP = ALLOW[0]
            DOWN = ALLOW[1]
            RIGHT = ALLOW[2]
            LEFT = ALLOW[3]

            if RIGHT == False and hero_x == pos_x:  #### CHECK
                for i in range(hero_size[1]):
                    if MAT[hero_y + i][hero_x +
                                       hero_size[0]] not in not_damage:
                        if self._hero.get_shield() == False:
                            self._hero.set_lives(self._hero.get_lives() - 1)
                        self._hero.disappear(MAT, COPY)
                        if MAT[hero_y + i][hero_x +
                                           hero_size[0]] == '*':  ## ZAPPER
                            Z.erase_zapper(MAT, COPY, hero_x + hero_size[0],
                                           hero_y + i)
                            # time.sleep(3)
                        elif MAT[hero_y + i][hero_x + hero_size[0]] == 'M':
                            # MAT[hero_y+i][[hero_x+hero_size[0]] = ' '
                            self._board.Place(hero_x + hero_size[0],
                                              hero_x + hero_size[0],
                                              hero_y + i, hero_y + i, ' ')
                            self._board.PlaceCopy(hero_x + hero_size[0],
                                                  hero_x + hero_size[0],
                                                  hero_y + i, hero_y + i, ' ')
                            mag_exists = False
                        # elif MAT[hero_y-1][hero_x+i] == 'P':
                        #     MAT[hero_y-1][hero_x+i] = ' '
                        #     COPY[hero_y-1][hero_x+i] = ' '
                        #     self._board.set_speed(self._board.get_speed()+1)
                        #     self._speedup = True

                        time.sleep(0.01)
                        X = self._hero.position(MAT, COPY)
                        self._coins += X[0]
                        self._speedup = self._speedup or X[1]
                        self._board.set_matrix(MAT)
                        self._board.set_copy(COPY)
                        ### invincibility
                        break

            MAT = self._board.get_matrix()
            COPY = self._board.get_copy()

            for ii in self._fired_bullets:
                x = ii.Update_bullet(MAT, COPY, dims[1], pos_x)
                if x == True:
                    self._fired_bullets.remove(ii)
                elif x == None:
                    pass
                else:
                    # print(x)
                    # time.sleep(1)
                    y = Z.erase_zapper(MAT, COPY, x[0] + ii.get_direction(),
                                       x[1])
                    if y == False:  # zapper not found, i.e. boss
                        if MAT[x[1]][x[0] + ii.get_direction()] == 'M':
                            # print("MAG DESTR")
                            # sleep(1)
                            MAT[x[1]][x[0] + ii.get_direction()] = ' '
                            # COPY[x[1]][x[0]+ii.direction] = ' '     ### CHECK
                            self._fired_bullets.remove(ii)
                            del ii
                            mag_exists = False

                        elif MAT[x[1]][x[0] + ii.get_direction(
                        )] == 'o' or MAT[x[1]][x[0] + ii.get_direction(
                        ) + 1] == 'o':  # or MAT[x[1]][x[0]+ii.get_direction()]==fg.RED+'o'
                            # print("SNOWBALLL DESTR")
                            MAT[x[1]][x[0] + ii.get_direction()] = ' '
                            self._fired_bullets.remove(ii)
                            del ii

                        elif dims[1] - x[0] < 190 and x[
                                0] >= self._boss.get_coords()[0] and MAT[x[1]][
                                    x[0] + ii.get_direction()] != 'o':
                            self._boss.set_lives(self._boss.get_lives() - 1)

            self._board.set_matrix(MAT)
            self._board.set_copy(COPY)

            ALLOW = self._hero.get_allowed()
            UP = ALLOW[0]
            DOWN = ALLOW[1]
            RIGHT = ALLOW[2]
            LEFT = ALLOW[3]

            if inp != 'w' and DOWN == True and self._hero.get_attracted(
            ) == False:  # as long as you hold no up  gravity ; If allowed_down is False, then don t allow to come down;mag overcomes gravity also
                cntr = 0
                self._hero.disappear(MAT, COPY)
                # if self.hero.falling == True:         # checks if falling (i.e. gravity is acting)
                while cntr < gravity and DOWN == True:
                    self._hero.fall(1)
                    self._hero.check_collision(MAT)
                    ALLOW = self._hero.get_allowed()
                    DOWN = ALLOW[1]
                    cntr += 1
                    X = self._hero.position(MAT, COPY)
                    self._coins += X[0]
                    self._speedup = self._speedup or X[1]
                    self._hero.disappear(MAT, COPY)
                fall_at_time += 1  # increments time of falling
                X = self._hero.position(MAT, COPY)
                self._coins += X[0]
                self._speedup = self._speedup or X[1]
                # else:
            else:
                fall_at_time = 0

            ALLOW = self._hero.get_allowed()
            UP = ALLOW[0]
            DOWN = ALLOW[1]
            RIGHT = ALLOW[2]
            LEFT = ALLOW[3]
            MAT = self._board.get_matrix()
            COPY = self._board.get_copy()
            pos_hero = self._hero.get_coords()
            hero_x = pos_hero[0]
            hero_y = pos_hero[1]

            if DOWN == False and inp != 'w':  # downward collision check
                for i in range(hero_size[0]):
                    if MAT[hero_y + hero_size[0]][hero_x +
                                                  i] not in not_damage:
                        if self._hero.get_shield() == False:
                            self._hero.set_lives(self._hero.get_lives() - 1)
                        self._hero.disappear(MAT, COPY)
                        if MAT[hero_y + hero_size[1]][hero_x +
                                                      i] == '*':  ## ZAPPER
                            Z.erase_zapper(MAT, COPY, hero_x + i,
                                           hero_y + hero_size[1])
                        elif MAT[hero_y + hero_size[1]][hero_x + i] == 'M':
                            # self.board.matrix[self.hero.y_coord+self.hero.size_y][self.hero.x_coord+i] = ' '
                            self._board.Place(hero_x + i, hero_x + i,
                                              hero_y + hero_size[1],
                                              hero_y + hero_size[1], ' ')
                            self._board.PlaceCopy(hero_x + i, hero_x + i,
                                                  hero_y + hero_size[1],
                                                  hero_y + hero_size[1], ' ')
                            mag_exists = False
                        time.sleep(0.01)
                        X = self._hero.position(MAT, COPY)
                        self._coins += X[0]
                        self._speedup = self._speedup or X[1]
                        self._board.set_matrix(MAT)
                        self._board.set_copy(COPY)

                        ### invincibility
                        break

            ALLOW = self._hero.get_allowed()
            UP = ALLOW[0]
            DOWN = ALLOW[1]
            RIGHT = ALLOW[2]
            LEFT = ALLOW[3]
            MAT = self._board.get_matrix()
            COPY = self._board.get_copy()
            pos_hero = self._hero.get_coords()
            hero_x = pos_hero[0]
            hero_y = pos_hero[1]
            self._hero.disappear(MAT, COPY)

            if RIGHT == True or hero_x != pos_x:
                pos_x += self._board.get_speed()

            if hero_y < 0:
                hero_y = 0

            if hero_x < pos_x:
                hero_x = pos_x

            elif hero_x + 3 > pos_x + 204:  # at a time 204 columns.
                hero_x = pos_x + 204 - 3

            self._hero.set_coords(hero_x, hero_y)

            X = self._hero.position(MAT, COPY)
            self._coins += X[0]
            self._speedup = self._speedup or X[1]
            self._board.set_matrix(MAT)
            self._board.set_copy(COPY)
            MAT = self._board.get_matrix()
            COPY = self._board.get_copy()
            pos_hero = self._hero.get_coords()
            hero_x = pos_hero[0]
            hero_y = pos_hero[1]
            cols_over = self._board.PrintBoard(pos_x)
            if (
                    RIGHT == True or hero_x != pos_x
            ) and cols_over == True:  ## CHECK THIS FURTHER. What exactly happens at the end of the board. SHUD THIS BE POSITIONED NEAR POS_X+=SPEED ? HOw why?
                pos_x -= self._board.get_speed()
            self._hero.check_collision(MAT)

            ALLOW = self._hero.get_allowed()
            UP = ALLOW[0]
            DOWN = ALLOW[1]
            RIGHT = ALLOW[2]
            LEFT = ALLOW[3]
            pos_hero = self._hero.get_coords()
            hero_x = pos_hero[0]
            hero_y = pos_hero[1]

            if abs(self._boss.get_coords()[0] - hero_x) < 150:
                self._boss.fight(self._hero, MAT, COPY)
                x = random.randint(0, 15)
                if iterator % 5 == 0 and self._boss.get_lives() > 0:
                    self._thrown_snowballs += [
                        Snowball(self._boss.get_coords()[0],
                                 self._boss.get_coords()[1] + x)
                    ]
                for ii in self._thrown_snowballs:
                    x = ii.Update_snowball(MAT, COPY, pos_x)
                    if x == True:
                        self._thrown_snowballs.remove(ii)
                    elif x == None:
                        pass
                    else:
                        if MAT[x[1]][x[0] - 1] in ['^', '\\', '/', '|']:
                            if self._hero.get_shield() == False:
                                self._hero.set_lives(self._hero.get_lives() -
                                                     1)
                            self._hero.disappear(MAT, COPY)
                            time.sleep(0.01)
                            X = self._hero.position(MAT, COPY)
                            self._coins += X[0]
                            self._speedup = self._speedup or X[1]
                            self._board.set_matrix(MAT)
                            self._board.set_copy(COPY)
Esempio n. 14
0
def start_game(screen):
    height, width = os.popen( 'stty size', 'r' ).read().split()

    #this obtains board size and width as dependent on the terminal size
    config.height = int( height ) - 8
    config.width = int( width ) * 5
    config.frame_width = int( width )

    Coin = coins.Coins()
    Obs = obstacles.Obstacles()
    Bullets = bullets.Bullet()
    Mag=Magnet()
    ice=bullets.Bullet()

    screen.create_board( height, width, Coin, Obs, Mag )

    player = hero.Hero( 4, 40 )  # creating hero with co ordinates

    config.time_left = 500
    config.start_time = time()

    screen.refresh_screen( player,Bullets )

    dragon_flag=0
    Dragon=Villain(config.width-49,player.get_y())


    itr=1
    quitter=False

    while ((not game_state.is_game_over()) and (config.time_left > 0) and (not quitter)):
        player.gravity()
        player.magnet_effect(Mag.get_y(),Mag.get_start(),Mag.get_end()) #to put the effect of the magnet on the hero

        quitter=player.movehero( screen.get_screen(), Bullets)

        game_state.coin_check( screen.get_screen() )

        game_state.place_bullets( screen.get_screen(), Bullets, Obs ,dragon_flag)

        config.time_left = 500-(time()-config.start_time)
        screen.refresh_screen( player ,Bullets)

        if config.start_col < 4 * int( width ):  # for moving the board frame
            config.start_col += 1 + config.boost_speed
        else:
            #this takes place when in the last frame
            dragon_flag=1
            Dragon.update(player.get_y(),ice,screen.get_screen())
            game_state.place_ice(screen.get_screen(),ice,player)

        if config.boost_end_time <= time(): #to handle power ups
            if config.state == 'u':
                if config.boost_speed!=0:
                    config.boost_speed = 0
                elif config.shield!=0:
                    config.shield=0
                config.state = 'c'
                config.boost_end_time=time()+10

            elif config.state=='c':
                config.boost_end_time=time()+10
                config.state='r'

        itr+=1
        if player.get_y()<config.height-3:
            config.hangtime+=1

    if config.result == 1:
        print( "\nYOU WON !!!!!!!!! :)" )
    else:
        print( "YOU LOST :( :( :(" )

    print( "SCORE:- %d" % (config.score) )
Esempio n. 15
0
        if board.curPos < (columns - columnsAtATime):
            for i in range(board.game_speed):
                mandalorian.movex(1, board, boss, first_time)

        else:
            board.curPos = columns - columnsAtATime

        for i in range(4 * board.game_speed):
            Bullet.move(board, mandalorian, boss, first_time)

            if board.curPos >= (columns - columnsAtATime - 41):
                IceBall.move(board, mandalorian, boss)

        for i in range(board.game_speed):
            flag = Magnet.attract(board, mandalorian, boss, first_time)

        mandalorian.movey(0, board, boss, first_time)

        board.show(mandalorian, boss, first_time)

    char = user_input()

    if mandalorian.onGround:
        t = 0

    else:
        t += 1

    if not flag:
        if char != 'w' and char != 'W':
Esempio n. 16
0
    object_middle_row = Random_object_row[
        0]  # containes the middle row of object to placed on board

    if object_type == 1:  # object_type 1 is for coins
        for j in range(-2, 3):
            for k in range(5):
                if is_coin[j + 2][k] == 1:
                    game_board.grid[object_middle_row + j][i + k] = Coin()

    elif object_type == 2:  # object_type 2 is for spped boost
        speedBoosts.append(
            SpeedBoost(object_middle_row, i, game_board.grid, speedBoost_num))
        speedBoost_num += 1

    elif object_type == 3:
        Magnet(object_middle_row, i, game_board.grid)
prev_ice_ball_shoot = time.time()
while True:
    char = user_input()
    cur_time = time.time()
    if cur_time - prev_time_left >= 1:
        time_left -= 1
        prev_time_left = cur_time
        if time_left <= 0:
            mandalorian.game_over()
    if cur_time - prev_shield_time >= 1:
        prev_shield_time = cur_time
        if shield_remaining_time > 0:
            shield_remaining_time -= 1
        if shield_cooloff_time > 0:
            shield_cooloff_time -= 1
Esempio n. 17
0
        # Check the bullet shootings
        for bullet in PLAYER.bullets:
            if bullet.delete_me:
                continue
            for item in OBJECTS:
                if isinstance(item,
                              FireBeam) and bullet.detect_collision(item):
                    container.SCORE += 3
                    item.delete_me = True
            if BOSS is not None and bullet.detect_collision(BOSS):
                BOSS.die()
        if BOSS is not None:
            for bullet in BOSS.bullets:
                if bullet.delete_me:
                    continue
                if TIMESTEP > PLAYER.last_died + 4 and bullet.detect_collision(
                        PLAYER):
                    PLAYER.last_died = TIMESTEP
                    FRAME.player_die()
        # Create the Magnet
        if TIMESTEP == container.MAGNET_TIME:
            MAGNET = Magnet(PLAYER)
            OBJECTS.append(MAGNET)

    # Clear out the Garbage
    if time.time() > garbage_collector.LAST_RUN_TIME + 10:
        OBJECTS = garbage_collector.garbage_collect(OBJECTS)
        PLAYER.bullets = garbage_collector.garbage_collect(PLAYER.bullets)
        if BOSS is not None:
            BOSS.bullets = garbage_collector.garbage_collect(BOSS.bullets)
Esempio n. 18
0
for i in range(5):
    m1 = random.randint(1, 33)
    m2 = random.randint(20 + l1, 80 + l1 + 10)
    speed.place(board.matrix, m1, m2)
    l1 = 5 + l1 + 50
coin = Coin()
coin.loadObstacle('coin')
for i in range(7):
    c1 = random.randint(2, 5)
    c2 = random.randint(3, 8)
    x = random.randint(1, 33)
    y = random.randint(30 + i * 20, 240 + i * 20)
    for j in range(c1):
        for k in range(c2):
            coin.place(board.matrix, x + j, y + k)
magnet = Magnet()
magnet.loadObstacle('magnet')
x1 = 20
x2 = 200
magnet.place(board.matrix, x1, x2)
mando = Mando()
mando.loadMando(board.matrix, 'n', cnt)
board.printBoard(cnt, config.dragon_lives)
dragon = Dragon()
dragon.loadObstacle('dragon')
dragon.place(board.matrix, 20, 445)
st = time.time()
prev_gravity_time = time.time()
dBtime = time.time()
shield_time = time.time()
gtime = time.time()
Esempio n. 19
0
        x = (int(np.random.choice(coin_places_list[0])),int(np.random.choice(coin_places_list[1])))
        if x not in coins:
            coins.append(Coin(x[0],x[1]))
    coins = sorted(coins,key = lambda x: x.get_pos()[0])

    num_beams = 10
    beams = []
    beam_places_list = [np.array(range(board.get_bg_size()[0]+6,board.get_bg_size()[1]-board.get_window_size()[1],6)),np.array(range(din.get_ceil_ground()[1]+20,din.get_ceil_ground()[0]-10,6))]
    for i in range(num_beams):
        x = (int(np.random.choice(beam_places_list[0])),int(np.random.choice(beam_places_list[1])))
        if x not in coins and x[0]:
            beams.append(Beam(x[0],x[1],np.random.choice([7,8,12]),np.random.choice([0,1,2])))
    coins = sorted(coins,key = lambda x: x.get_pos()[0])


    magnet = Magnet(np.random.randint(board.get_window_size()[0]+10,board.get_bg_size()[1]-board.get_window_size()[1]))
    dragon = Dragon(din,board)
    # board.set_current_pos(board.get_bg_size()[1] - board.get_window_size()[1])
    kb.getch()
    while dragon.get_ended() == 0 and din.get_lives() > 0:
        board.update()
        if kb.kbhit():
            c = kb.getch()
            if c == 'q':
                break
            if c == 'k':
                board.speed_up()
            if c == 'j':
                board.speed_down()
            din_ret = din.update(c)
            if c == 's':
 def add_Drift(self, L):
     # L: length of drift region
     self.numElements += 1
     args = [L]
     el = Magnet(self, 'DRIFT', args)
     self.lattice.append(el)
Esempio n. 21
0
 def generate_magnets(self):
     n_magnet = 5
     for _ in range(n_magnet):
         c = randint(50, self.__col - 50)
         self.add_entity(Magnet(5, c, self))
Esempio n. 22
0
 def test_find_pv_attrs(self):
     """Test we have correct attributes"""
     m = Magnet()
     self.assertEqual(m.find_pv_attrs(), ATTRS)
Esempio n. 23
0
drag = Dragon(30, 500)
drag.place(screen)
for i in range(40):
    x = randint(5, 30)
    y = randint(25, 450)
    coin_p = Coin(x, y)
    coin_p.place(screen)

for j in range(10, 30):
    x = randint(5, 30)
    y = randint(50, 350)
    beam = Firebeam(x, y)
    beam.place(screen)

mag = Magnet(2, 80)
mag.place(screen)

counter3 = time()
screen.print_board(0, man, drag)
#print("time left==")
#print(100-counter3)

count_gravity = 0
count_magnet = 0
count_board = 0
print_range = 0
count_pace = 0
counter = time()
counter2 = time()
counter_dragbull = 0
Esempio n. 24
0
                     game_board.getcols() - 1, 0, -1 * speed_multiplier))

    if (num_frames % 50 == 25 and not has_boss_arrived):
        # spawn lasers
        rownum = random.randint(0, game_board.getrows() - 6)
        laser_type = random.randint(1, 4)
        lasers_list.append(
            Laser(rownum,
                  game_board.getcols() - 6, 0, -1 * speed_multiplier,
                  laser_type))

    if (num_frames == 100 and not has_boss_arrived):
        # spawn random magnet
        magnets_list = [
            Magnet(random.randint(0,
                                  game_board.getrows() - 4), ttycolumns - 1, 0,
                   -1)
        ]

    if (has_boss_arrived and num_frames % 25 == 0):
        for boss in boss_list:
            ice_balls_list.append(
                Iceball(player.getx(),
                        game_board.getcols() - boss.getwidth(), 0, -1))

    if kb.kbhit():
        char = kb.getch()
        if (char == 'w'):
            player.move_up()
        elif (char == 'a'):
            player.move_left()