def get_level(self, user):
     """Returns the level of a specific user.
     Args:
         user: name of the user"""
     experience = self.get_experience(user)
     level = Level()
     return level.check_level(int(experience))
    def test_updating_unit_position_functions_correctly(self):
        unit = Unit(pos_x=0, pos_y=0)

        correct_positions = [[None, None, None], [None, None, None],
                             [None, None, unit]]

        level = Level(LEVEL_DATA, [unit])
        level.update_unit_position(unit, 2, 2)

        self.assertEqual(level.unit_positions, correct_positions)
    def test_on_enemy_phase_movement_data_affected_by_allied_units(self):
        correct_data = [[1, sys.maxsize, 1], [1, sys.maxsize, sys.maxsize],
                        [1, sys.maxsize, 1]]

        unit = Unit(pos_x=1, pos_y=2, alignment=Alignment.ALLY)
        unit2 = Unit(pos_x=2, pos_y=1, alignment=Alignment.ALLY)

        level = Level(LEVEL_DATA, [unit, unit2])

        self.assertEqual(level.get_movement_data_with_units(False),
                         correct_data)
Example #4
0
 def startGame(self):
     self.state = "Game"
     self.buildLevel(
         Level([
             ['w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', 'w', 'w', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
         ]) + Level([
             ['w', 'w', 'w', 'w', 'w', 'w', 'w', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', 'w', 'w', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
         ]) + Level([
             ['w', 'w', 'w', ' ', ' ', 'w', 'w', 'w', 'w', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', 'p', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', 'w', 'w', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', 'w', 'w', 'w', 'w', 'w', ' ', ' ', 'w', 'w'],
         ]) + Level([
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'w'],
             ['w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w'],
         ]))
Example #5
0
 def buildLevel(self, level):
     level = level + Level(
         [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']])
     level = level + Level(
         [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']])
     level = level + Level(
         [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']])
     self.screen.clear()
     self.screen.setLevelWidth(SCREEN_WIDTH)
     print("SCREEN_WIDTH: {}".format(SCREEN_WIDTH))
     for sprite in level:
         if not isinstance(sprite, Player):
             self.screen.append(sprite)
         else:
             self.player = sprite
             self.screen.append(sprite)
             # print(self.player)
     self.controls = Controls(self.screen)
    def test_units_assigned_correct_positions(self):

        unit = Unit(pos_x=1, pos_y=2, alignment=Alignment.ENEMY)
        unit2 = Unit(pos_x=2, pos_y=1, alignment=Alignment.ENEMY)

        level = Level(LEVEL_DATA, [unit, unit2])

        self.assertEqual(level.unit_positions[2][1], unit)
        self.assertEqual(level.unit_positions[1][2], unit2)
Example #7
0
    def setUp(self):
        self.units = []
        unit = Unit(pos_x=0, pos_y=2, alignment=Alignment.ENEMY)
        unit2 = Unit(pos_x=2, pos_y=3)

        self.units.append(unit)
        self.units.append(unit2)

        self.level = Level(LEVEL_DATA, self.units)
        self.pathfinding = PathFinding(1, 1, self.level.movement_data)

        self.ai = Ai(self.units, self.pathfinding, self.level)
import unittest
from logic.pathfinding import PathFinding
from entities.level import Level

game_map = [[1, 80, 1], [1, 80, 1], [1, 1, 1]]

level = Level([[0, 0, 0], [0, 0, 0], [0, 0, 0]], [])

level.movement_data = game_map


class TestPathfinding(unittest.TestCase):
    def setUp(self):
        self.pathfinding = PathFinding(1, 1, game_map)

    def test_pathfinding_returns_correct_distances(self):
        self.pathfinding.calculate_distances(0, 0, level)
        distances = self.pathfinding.distance
        correct_distances = [[0, 80, 6], [1, 81, 5], [2, 3, 4]]
        self.assertEqual(distances, correct_distances)

    def test_return_path_returns_correct_path(self):
        path = self.pathfinding.return_path((0, 0), (2, 0))
        correct_path = [(2, 0), (2, 1), (2, 2), (1, 2), (0, 2), (0, 1), (0, 0)]
        self.assertEqual(path, correct_path)

    def test_return_ranges_returns_correct_tiles(self):
        self.pathfinding.calculate_distances(1, 2, level)
        ranges = self.pathfinding.return_ranges(2)
        self.assertEqual(ranges, [(0, 1), (2, 1), (0, 2), (1, 2), (2, 2)])
Example #9
0
 def initialize(self):
     for i in range(self.level_count):
         self.levels.append(Level(i, self.rows_per_level, self.slots_per_row))
Example #10
0
from entities.level import Level

l = Level([['p']])
l += Level([['w']])
print(l)
Example #11
0
            bullet_list.remove(bullet)
            all_sprites_list.remove(bullet)
            score += 1

        # Enlève la ball quand elle est trop haute sur l'écran à vous de voir quel hauteur précisement
        if bullet.rect.y < -10:
            bullet_list.remove(bullet)
            all_sprites_list.remove(bullet)

    if (time.time() - lastInsert) > timeRespawn:
        speedMonster += 1
        levelNumber += 1
        displayMonster(8, speedMonster)
        lastInsert = time.time()
        if levelNumber % 2 == 0:
            level = Level(levelNumber)
            imageLevel = level.getImage()
            imageLevel = pygame.transform.scale(imageLevel, (100, 100))
            lastDisplayImage = time.time()

    # Fait un écran blanc (j'ai fait ça pour mes testes)
    screen.fill((255, 255, 255))

    # affiche tout les sprites
    all_sprites_list.draw(screen)
    myfont = pygame.font.SysFont("Arial", 15)
    letter = myfont.render("Score : "+str(score), 0, (0, 0, 0))
    screen.blit(letter, (10, 10))
    myfont = pygame.font.SysFont("Arial", 15)
    letter = myfont.render("Prochaine vague dans : " + str(int(timeRespawn - (time.time() - lastInsert))) + ' secondes',
                           0, (0, 0, 0))
Example #12
0
def main():
    screen_width = 640
    screen_height = 640
    screen = pygame.display.set_mode((screen_width, screen_height))
    pygame.display.set_caption("Faux Emblem")

    camera = Camera(0, 0)

    units = []
    units.append(
        Unit(1,
             4,
             name="Ferdinand",
             strength=8,
             speed=6,
             defense=5,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units[0].items.append(Item(3, 3, 0))
    units[0].items.append(Item(3, 3, 0))
    units[0].items.append(Item(3, 3, 0))
    units.append(
        Unit(1,
             5,
             name="Sylvain",
             strength=4,
             speed=2,
             defense=8,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(3,
             6,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(6,
             6,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(12,
             4,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(9,
             7,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(2,
             5,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))

    pygame.font.init()
    font = pygame.font.SysFont("Arial", 20)
    font2 = pygame.font.SysFont("Arial", 14)

    clock = GameClock()

    level = [[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
             [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
             [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
             [0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1],
             [0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1],
             [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1],
             [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1],
             [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1]]

    test_level = Level(level, units)
    tile_map = TileMap(level)

    test_level.get_movement_data_with_units(True)

    pathfinding = PathFinding(1, 1, test_level.movement_data)
    target_selector = TargetSelector()

    enemy_ai = Ai(units, pathfinding, test_level)

    game_loop = GameLoop(screen, SpriteRenderer(),
                         Cursor(1, 4, camera.offset_x, camera.offset_y),
                         MenuCursor(), EventQueue(), units,
                         MovementDisplay(pathfinding), font, font2, clock,
                         target_selector, camera, test_level, tile_map,
                         enemy_ai)

    pygame.init()
    game_loop.start()

    pygame.quit()
 def setUp(self):
     self.level = Level(LEVEL_DATA, [])