コード例 #1
0
 def test_correct_deleting(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     cells = Unity.identifier(self.labyrinth)[0]
     way = deque(cells)
     pos = way[3]
     pos2 = way[2]
     game_state = GameState(perm_mock)
     creep2 = Creep(pos2[0], pos2[1], way, 1)
     creep = Creep(pos[0], pos[1], way, 1)
     game_state.world.creeps.append(creep)
     game_state.world.creeps.append(creep2)
     i = 0
     while i < 4:
         creep.way.popleft()
         if i < 3:
             creep2.way.popleft()
         i += 1
     game_state.world.creeps[0].health = 0
     tower = Tower(0, 32, 'laser')
     tower.is_blast = True
     tower.level = 2
     tower.attacked_creep = game_state.world.creeps[0]
     game_state.world.towers.append(tower)
     game_state.check_creeps(game_state.world, game_state.gamer)
     self.assertEqual(len(game_state.world.creeps), 2)
コード例 #2
0
class CreepTest(unittest.TestCase):
    def setUp(self):
        self.creep = Creep((0, 0), 'basic', 10, 100)

    def test_creep(self):
        self.assertEqual(self.creep.loc, (0, 0))
        self.assertEqual(self.creep.type, 'basic')
        self.assertEqual(self.creep.speed, 10)
        self.assertEqual(self.creep.health, 100)

    def test_move_to_dest(self):
        self.creep.move_to_dest((1, 1))
        self.assertEqual(self.creep.loc, (1, 1))

    def test_move_on_path(self):
        bestPath = {
            (1, 2): (0, 2),
            (3, 2): (2, 2),
            (0, 0): (1, 0),
            (2, 0): (3, 0),
            (4, 5): None,
            (4, 1): (4, 2),
            (4, 4): (4, 5),
            (2, 2): (1, 2),
            (1, 4): (2, 4),
            (0, 2): (0, 3),
            (3, 0): (4, 0),
            (0, 4): (1, 4),
            (1, 0): (2, 0),
            (4, 2): (3, 2),
            (0, 3): (0, 4),
            (3, 4): (4, 4),
            (2, 4): (3, 4),
            (4, 0): (4, 1)
        }
コード例 #3
0
 def test_creep_rect(self):
     cells = Unity.identifier(self.labyrinth)[0]
     way = deque(cells)
     pos = way.popleft()
     creep = Creep(pos[0], pos[1], way, 1)
     creep.current_pos = [0, 0]
     creep.motion, creep.move_to = Unity.make_direction(creep, creep.speed)
     creep.rect = Unity.take_new_coordinates(creep)
     self.assertEqual(creep.rect, (33, 0, 65, 32))
コード例 #4
0
 def make_way(self):
     self.ways = Unity.build_way(self.access_cells, self.start, self.finish,
                                 self.branch_start, self.branch_end)
     self.start_creep = Creep(self.start[0], self.start[1], self.ways[0],
                              self.speed)
     self.creeps.append(self.start_creep)
     self.made_creeps += 1
コード例 #5
0
 def test_stop_blast(self):
     tower = Tower(10, 20, 'laser')
     tower.attacked_creep = Creep(10, 20, [0, 0], 1)
     tower.is_blast = True
     tower.stop_blast()
     self.assertEqual(tower.is_blast, False)
     self.assertEqual(tower.attacked_creep, None)
コード例 #6
0
 def test_wave_is_over(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     game_state.world.creeps[0].rect = (20, 20, 50, 100)
     game_state.world.finish = [20, 20]
     game_state.check_creeps(game_state.world, game_state.gamer)
     self.assertEqual(game_state.wave_is_over(game_state.world), True)
     creep = Creep(20, 50, game_state.world.ways[0], 2)
     tower = Tower(30, 50, 'laser')
     tower.level = 2
     creep.health = 0
     game_state.world.creeps.append(creep)
     game_state.world.towers.append(tower)
     game_state.blast_and_kill(game_state.world.creeps[0], game_state.world,
                               game_state.gamer)
     self.assertEqual(game_state.wave_is_over(game_state.world), True)
コード例 #7
0
ファイル: creep_test.py プロジェクト: andysalerno/Towers
class CreepTest(unittest.TestCase):
	
    def setUp(self):
        self.creep = Creep((0,0), 'basic', 10, 100)
	
    def test_creep(self):
        self.assertEqual(self.creep.loc, (0,0))
        self.assertEqual(self.creep.type, 'basic')
        self.assertEqual(self.creep.speed, 10)
        self.assertEqual(self.creep.health, 100)
        
    def test_move_to_dest(self):
        self.creep.move_to_dest((1,1))
        self.assertEqual(self.creep.loc, (1,1))
    
    def test_move_on_path(self):
        bestPath = {(1, 2): (0, 2), (3, 2): (2, 2), (0, 0): (1, 0), (2, 0): (3, 0), (4, 5): None, (4, 1): (4, 2), (4, 4): (4, 5), (2, 2): (1, 2), (1, 4): (2, 4), (0, 2): (0, 3), (3, 0): (4, 0), (0, 4): (1, 4), (1, 0): (2, 0), (4, 2): (3, 2), (0, 3): (0, 4), (3, 4): (4, 4), (2, 4): (3, 4), (4, 0): (4, 1)}
コード例 #8
0
 def test_blast(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     creep = Creep(50, 62, game_state.world.ways[0], 1)
     tower = Tower(50, 62, 'laser')
     game_state.blast(tower, creep)
     self.assertEqual(creep.health, 99)
コード例 #9
0
 def test_help_creeps(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     creep_helper = CreepHelper(100, 150, game_state.world.ways[0], 1)
     creep = Creep(132, 150, game_state.world.ways[0], 1)
     creep.health = 80
     creep.need_help = 26
     game_state.world.creeps.append(creep)
     game_state.world.creeps.append(creep_helper)
     game_state.help_creeps(game_state.world.creeps[2])
     self.assertEqual(game_state.world.creeps[1].health, 90)
     self.assertEqual(game_state.world.creeps[1].doctored, True)
     game_state.world.creeps[1].health = 93
     game_state.world.creeps[1].need_help = 26
     game_state.help_creeps(game_state.world.creeps[2])
     self.assertEqual(game_state.world.creeps[1].health, 100)
コード例 #10
0
ファイル: gameboard.py プロジェクト: gentimouton/tridef
 def add_creep(self):
     """ add a creep to the game - creeps appear in the lair """
     (lx, ly) = self.__MAP.get_lair_coords()  #lair coord
     cell = self.__MAP.get_cell_from_grid((lx, ly))
     creep = Creep(self, (lx * self.__MAP.get_cell_width(),
                          ly * self.__MAP.get_cell_height()), cell)
     cell.add_creep(creep)
     self.__creep_list.append(creep)
     return
コード例 #11
0
 def update(self):
     self.wave += 1
     if self.wave == 2:
         self.speed += 1
     self.made_creeps = 0
     self.creeps.append(Creep(self.start[0], self.start[1], self.ways[0],
                              self.speed))
     self.made_creeps += 1
     self.start_wave = False
     self.time = 10
コード例 #12
0
 def create_more_creeps(self):
     branches_count = len(self.ways)
     i = self.made_creeps % branches_count
     if self.wave > 1 and self.made_creeps % 4 == 0:
         self.creeps.append(CreepHelper(self.start[0], self.start[1],
                                        self.ways[i], self.speed))
     else:
         self.creeps.append(Creep(self.start[0], self.start[1],
                                  self.ways[i], self.speed))
     self.made_creeps += 1
コード例 #13
0
 def test_intersects(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     creep = Creep(20, 50, game_state.world.ways[0], 2)
     tower = Tower(40, 50, 'laser')
     tower.level = 2
     self.assertEqual(game_state.intersects(tower, creep), True)
     tower = Tower(150, 300, 'freeze')
     self.assertEqual(game_state.intersects(tower, creep), False)
コード例 #14
0
ファイル: game.py プロジェクト: taroyanaka/canvas-td
	def sendwave(self):
		self.lastwave = self.curtick # set the last wave tick
		self.curwave += 1 # set the current wave
		
		multipliers = { 10: 1.2, 25: 1.1, 50: 1.06, 100: 1.04, 150: 1.02, 200: 1.01 } # define base hp multipliers (by wave)
		self.hpmod = multipliers[self.wave] if self.wave in multipliers else self.hpmod # possibly update the hp multiplier
		self.hp *= self.hpmod # multiply the base hp
		
		for i in range(1, 11): # create some creeps
			self.creeps.append(x = Creep(-(i * 20) - 10, y = self.map[0].y, hp = self.hp, wave = self.wave)) # creepy!
コード例 #15
0
 def test_stop_blast(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     tower = Tower(50, 62, 'laser')
     creep = Creep(50, 62, game_state.world.ways[0], 1)
     tower.attacked_creep = creep
     game_state.world.towers.append(tower)
     game_state.stop_blast(game_state.world.towers, creep)
     self.assertEqual(game_state.world.towers[0].is_blast, False)
     self.assertEqual(game_state.world.towers[0].attacked_creep, None)
コード例 #16
0
 def test_creeps_after_mines(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     cells = Unity.identifier(self.labyrinth)[0]
     way = deque(cells)
     pos = way[3]
     game_state = GameState(perm_mock)
     creep = Creep(pos[0], pos[1], way, 1)
     mine = Mine(pos[0], pos[1])
     game_state.world.mines.append(mine)
     game_state.world.creeps.append(creep)
     game_state.blast_and_kill(creep, game_state.world, game_state.gamer)
     self.assertEqual(len(game_state.world.creeps), 1)
コード例 #17
0
 def test_go_to_the_final(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     access_cells, tower_places, start, finish, branch_start, branch_end = Unity.identifier(
         self.labyrinth)
     ways = Unity.build_way(access_cells, start, finish, branch_start,
                            branch_end)
     pos = finish
     game_state = GameState(perm_mock)
     game_state.world.finish = finish
     creep = Creep(pos[0], pos[1], ways[0], 1)
     game_state.world.creeps.append(creep)
     self.assertEqual(
         game_state.creep_go_to_the_final(creep, game_state.world), True)
コード例 #18
0
ファイル: level.py プロジェクト: ToBaer94/PygameTowerDefense
    def spawn_enemy(self, enemy, lane):
        print lane
        path = random.randint(0, len(self.level.creep_path) - 1)
        if enemy == CREEP:
            creep = Creep(self.level, self.level.creep_path[lane])
        elif enemy == WORM:
            creep = Worm(self.level, self.level.creep_path[lane])

        elif enemy == BEHEMOTH:
            creep = Behemoth(self.level, self.level.creep_path[lane])

        elif enemy == SWIFTWALKER:
            creep = SwiftWalker(self.level, self.level.creep_path[lane])
        else:
            print enemy, " is not a defined creep"
        self.level.creep_group.add(creep)
コード例 #19
0
 def test_check_creeps(self):
     with patch('application.Application') as perm_mock:
         perm_mock.game_engine = None
     game_state = GameState(perm_mock)
     game_state.world.finish = [120, 150]
     creep = Creep(120, 150, game_state.world.ways[0], 2)
     tower = Tower(90, 90, 'laser')
     tower2 = Tower(50, 70, 'laser')
     tower2.attacked_creep = game_state.world.creeps[0]
     tower.attacked_creep = creep
     game_state.world.towers.append(tower)
     game_state.world.towers.append(tower2)
     game_state.world.creeps.append(creep)
     game_state.gamer.life = 10
     game_state.check_creeps(game_state.world, game_state.gamer)
     self.assertEqual(game_state.gamer.life, 9)
     self.assertEqual(len(game_state.world.creeps), 1)
     self.assertEqual(game_state.world.towers[0].attacked_creep, None)
     self.assertNotEqual(game_state.world.towers[1].attacked_creep, None)
コード例 #20
0
ファイル: creep_test.py プロジェクト: andysalerno/Towers
 def setUp(self):
     self.creep = Creep((0,0), 'basic', 10, 100)
コード例 #21
0
ファイル: __main__.py プロジェクト: probaton/creep
import signal
from creep import Creep
import logging
import sys
from slackbot.bot import respond_to

creep = None


@respond_to('.*')
def handle_message(message):
    if creep:
        creep.handle_message(message)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    creep = Creep()

    def handle_ctrl_c(signal, frame):
        creep.shutdown()
        sys.exit(0)

    signal.signal(signal.SIGINT, handle_ctrl_c)
    creep.run()
コード例 #22
0
ファイル: __main__.py プロジェクト: Achiel/creep
import signal
from creep import Creep
import logging
import sys
from slackbot.bot import respond_to

creep = None


@respond_to('.*')
def handle_message(message):
    if creep:
        creep.handle_message(message)

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    creep = Creep()

    def handle_ctrl_c(signal, frame):
        creep.shutdown()
        sys.exit(0)

    signal.signal(signal.SIGINT, handle_ctrl_c)
    creep.run()
コード例 #23
0
 def setUp(self):
     self.creep = Creep((0, 0), 'basic', 10, 100)
コード例 #24
0
 def test_is_dead(self):
     creep = Creep(10, 20, [50, 50], 2)
     creep.health = 0
     self.assertEqual(creep.is_dead(), True)
     creep.health = 90
     self.assertEqual(creep.is_dead(), False)