Exemple #1
0
    def test_LetterScoringHeuristicScoreWord_QUEEN_ReturnsFourteen(self):
        # Arrange
        expected = 14
        hand = []
        q = "Q"
        u = "U"
        e = "E"
        n = "N"
        tiles = []
        qTile = Tile(q)
        uTile = Tile(u)
        eTile = Tile(e)
        nTile = Tile(n)
        tiles.append(qTile)
        tiles.append(uTile)
        tiles.append(eTile)
        tiles.append(eTile)
        tiles.append(nTile)
        word = Word(tiles)
        heuristic = LetterScoringHeuristic(0)

        # Act
        result = heuristic.ScoreWord(word, hand)

        # Assert
        self.assertEqual(result, expected)
Exemple #2
0
def setupGame():
    #Setting up tiles in deck
    typesOfTile = ("Special", "Stick", "Circle", "Char")
    for types in typesOfTile:
        if (types == "Special"):
            for specialNum in range(
                    1, 8
            ):  # from 1 to 7: "East","South","West","North","Zhong","Fa cai","Bai ban"
                allTiles[Tile(types, specialNum)] = 4
        else:
            for num in range(1, 10):
                allTiles[Tile(types, num)] = 4

    for initialTile in list(allTiles.keys()):
        availableTiles.append(initialTile)

    #Setup starting hand for each player, East seat player gets the first turn
    for drawing in range(0, 3):
        for playerDrawing in playerList:
            for numtoDraw in range(0, 4):
                playerDrawing.draw()
    for playerDrawing in playerList:
        if (playerDrawing.seat == "East"):
            for numToDraw in range(0, 2):
                playerDrawing.draw()
        else:
            playerDrawing.draw()
Exemple #3
0
def newRandomTile():
    """ Fait apparaitre une nouvelle tuile
	et check si on perd """
    # random.randrange(0,4) => 0,1,2,3
    x = random.randrange(0, 4)
    y = random.randrange(0, 4)
    while tiles[x][y] != None:
        x = random.randrange(0, 4)
        y = random.randrange(0, 4)
    if random.randrange(0, 10) == 1:
        tiles[x][y] = Tile.Tile(4)
    else:
        tiles[x][y] = Tile.Tile(2)

    for x in range(0, 4):
        for y in range(0, 4):
            if (tiles[x][y] == None):
                return
    # GRILLE COMPLETE, CHECK LOOSE
    for x in range(0, 3):
        for y in range(0, 4):
            if (tiles[x][y].getValue() == tiles[x + 1][y].getValue()):
                return
    for x in range(0, 4):
        for y in range(0, 3):
            if (tiles[x][y].getValue() == tiles[x][y + 1].getValue()):
                return
    loose()
def load_world(map_data):
    # Tiles are generated by
    tiles_x = 0
    tiles_y = 0
    tiles_count = 0
    tiles = []
    solid_tiles = []

    for i in map_data:
        if i == '00':
            i = Tile(tiles_x, tiles_y, 0, False, False,
                     'resources/sprites/island/water/water1.png')
            tiles.append(i)
        elif i == '01':
            i = Tile(tiles_x, tiles_y, 0, False, False,
                     'resources/sprites/island/water/water2.png')
            i.make_solid()
            tiles.append(i)
            solid_tiles.append(i)
        tiles_x += 32
        tiles_count += 1
        if tiles_count >= 43:
            tiles_x = 0
            tiles_y += 32
            tiles_count = 0
    return tiles, solid_tiles
Exemple #5
0
  def __init__(self, difficulty):
    self.height = -1
    self.width = -1
    if difficulty == 1:
      self.height = 8
      self.width = 8
      self.mines = 10
    elif difficulty == 2:
      self.height = 16
      self.width = 16
      self.mines = 40
    else:
      self.height = 16
      self.width = 30
      self.mines = 99

    self.board = [[Tile(-1,-1) for x in range(self.width)] for y in range(self.height)]

    for x in range(self.height):
      for y in range(self.width):
        tile = Tile(x,y)
        self.board[x][y] = Tile(x, y)

    #place the mine 
    for i in range(self.mines):
      x = random.randint(0, self.width-1)
      y = random.randint(0, self.height-1)
      if self.board[x][y].hasBomb == True:
        i-=1
      self.board[x][y].setBomb()
      neighbors = self.getNeighbors(self.getTile(x,y))
      for tile in neighbors:
        tile.bombsNearby += 1
Exemple #6
0
 def generate_single_chance_terrain(self):
     # generates terrain that takes only one tile and has its own spawn % chance
     forest_chance = random.randint(self.forest_chance_min, self.forest_chance_max)          # random spawn chance from between given values
     mountain_chance = random.randint(self.mountain_chance_min, self.mountain_chance_max)+forest_chance      # its cumulative
     for i in range(0, self.size+2):               
         for j in range(0, self.size+2):
             if self.tile_array[i][j].is_set==False:
                 chance = random.randint(1, 100)
                 if chance <= forest_chance:             # forest
                     self.map_array[i][j] = 'F'
                     t = random.randint(1, 3)            # selecting random forest tile (there are 3 forest tiles)
                     if t==1:
                         self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "forest", 0, self.forest_image1, True)
                     elif t==2:
                         self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "forest", 0, self.forest_image2, True)
                     else:
                         self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "forest", 0, self.forest_image3, True)
                 elif chance <= mountain_chance:          # mountain
                     self.map_array[i][j] = 'M'
                     t = random.randint(1, 2)            # selecting random forest tile (there are 3 forest tiles)
                     if t==1:
                         self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "mountain", 0, self.mountain_image1, True)
                     else:
                         self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "mountain", 0, self.mountain_image2, True)
                 else:               # remains grass
                     pass
Exemple #7
0
    def test_LongestWordHeuristicScoreWord_FourLetterWord_ReturnsFour(self):
        # Arrange
        expected = 4
        hand = []
        f = "F"
        o = "O"
        u = "U"
        r = "R"
        tiles = []
        fTile = Tile(f)
        oTile = Tile(o)
        uTile = Tile(u)
        rTile = Tile(r)
        tiles.append(fTile)
        tiles.append(oTile)
        tiles.append(uTile)
        tiles.append(rTile)
        word = Word(tiles)
        heuristic = LongestWordHeuristic(0)

        # Act
        result = heuristic.ScoreWord(word, hand)

        # Assert
        self.assertEqual(result, expected)
Exemple #8
0
 def generate_dragon_nests(self):
     # generates nests, one of each type, loops until it can spawn it
     is_set=False
     while is_set!=True:
         xPos = random.randint(1, self.size)         # random index of tile
         yPos = random.randint(1, self.size)
         if self.tile_array[xPos][yPos].is_set==False:
             self.map_array[xPos][yPos] = 'D'
             self.tile_array[xPos][yPos] = Tile(xPos, yPos, xPos*tile_size, yPos*tile_size, "dragon nest", 0, self.dragon_image1, True)
             is_set=True
     is_set=False
     while is_set!=True:
         xPos = random.randint(1, self.size)         # random index of tile
         yPos = random.randint(1, self.size)
         if self.tile_array[xPos][yPos].is_set==False:
             self.map_array[xPos][yPos] = 'D'
             self.tile_array[xPos][yPos] = Tile(xPos, yPos, xPos*tile_size, yPos*tile_size, "dragon nest", 0, self.dragon_image2, True)
             is_set=True
     is_set=False
     while is_set!=True:
         xPos = random.randint(1, self.size)         # random index of tile
         yPos = random.randint(1, self.size)
         if self.tile_array[xPos][yPos].is_set==False:
             self.map_array[xPos][yPos] = 'D'
             self.tile_array[xPos][yPos] = Tile(xPos, yPos, xPos*tile_size, yPos*tile_size, "dragon nest", 0, self.dragon_image3, True)
             is_set=True
    def test_one_to_nine(self):
        character_1 = Tile.Tile("characters", 1)
        character_2 = Tile.Tile("characters", 2)
        character_3 = Tile.Tile("characters", 3)
        character_4 = Tile.Tile("characters", 4)
        character_5 = Tile.Tile("characters", 5)
        character_6 = Tile.Tile("characters", 6)
        character_7 = Tile.Tile("characters", 7)
        character_8 = Tile.Tile("characters", 8)
        character_9 = Tile.Tile("characters", 9)
        west = Tile.Tile("honor", "west")

        fixed_hand = [("pong", False,
                       tuple([character_4, character_4, character_4]))]
        hand = [
            character_1, character_2, character_3, character_5, character_6,
            character_7, character_8, character_9, west, west
        ]

        self.assertEqual(
            ScoringRules.HKRules.calculate_total_score(fixed_hand,
                                                       hand,
                                                       character_7,
                                                       "draw",
                                                       game=None)[1], 4)
Exemple #10
0
def __validate_helper(tile_map, suit_map, tile_count, grouped_hand=[]):
    result = []

    if tile_count == 0:
        return [list(grouped_hand)]

    for suit in Tile.suit_order:
        suit_count = suit_map[suit]
        if suit_count == 0:
            continue

        iter_items = sorted(list(tile_map[suit].items()), key=lambda x: x[0])
        for tile_val, count in iter_items:
            if count == 0:
                continue
            tile = Tile.Tile(suit, tile_val)

            if count >= 3:
                grouped_hand.append(("pong", (tile, tile, tile)))
                tile_map[suit][tile_val] -= 3
                suit_map[suit] -= 3

                tmp_result = __validate_helper(tile_map, suit_map,
                                               tile_count - 3, grouped_hand)

                grouped_hand.pop()
                tile_map[suit][tile_val] += 3
                suit_map[suit] += 3
                result.extend(tmp_result)

            if suit != "honor" and count >= 1 and int(tile_val) <= 7:
                succeeding_tile_1 = Tile.Tile(suit, int(tile_val) + 1)
                succeeding_tile_2 = Tile.Tile(suit, int(tile_val) + 2)

                if tile_map[suit][str(
                        succeeding_tile_1.value)] >= 1 and tile_map[suit][str(
                            succeeding_tile_2.value)] >= 1:
                    grouped_hand.append(
                        ("chow", (tile, succeeding_tile_1, succeeding_tile_2)))

                    tile_map[suit][tile_val] -= 1
                    tile_map[suit][str(succeeding_tile_1.value)] -= 1
                    tile_map[suit][str(succeeding_tile_2.value)] -= 1
                    suit_map[suit] -= 3

                    tmp_result = __validate_helper(tile_map, suit_map,
                                                   tile_count - 3,
                                                   grouped_hand)
                    grouped_hand.pop()

                    tile_map[suit][tile_val] += 1
                    tile_map[suit][str(succeeding_tile_1.value)] += 1
                    tile_map[suit][str(succeeding_tile_2.value)] += 1
                    suit_map[suit] += 3
                    result.extend(tmp_result)

            return result
Exemple #11
0
 def __init__(self):
     self.tile_array = [[Tile.Tile() for _ in range(3)],
                        [Tile.Tile() for _ in range(4)],
                        [Tile.Tile() for _ in range(5)],
                        [Tile.Tile() for _ in range(4)],
                        [Tile.Tile() for _ in range(3)]]
     self.connect_tiles()
     self.add_edges()
     self.add_vertices()
     self.connect_edges_to_edges()
     self.connect_vertices_to_vertices()
Exemple #12
0
	def __init__(self, boardArr):
		# Elimiate magic ints with some class consants!
		# Specifies the size of the board in a 2D matrix
		self.SIZE = 9
		# Main Key - Board Array
		self.boardArr = [[ Tile(0) for col in range(self.SIZE)] for row in range(self.SIZE)]
		# Convert boardArr ints to self.boardArr Tile objects
		for x in range(self.SIZE):
			for y in range(self.SIZE):
				# Set Tile and Solved State If Not 0
				self.boardArr[x][y] = Tile( boardArr[x][y] )
Exemple #13
0
 def test_all_pongs(self):
     character_1 = Tile.Tile("characters", 1)
     bamboo_2 = Tile.Tile("bamboo", 2)
     dots_5 = Tile.Tile("dots", 5)
     character_7 = Tile.Tile("characters", 7)
     dots_9 = Tile.Tile("dots", 9)
     hand = [
         character_1, character_1, character_1, bamboo_2, bamboo_2,
         bamboo_2, dots_5, dots_5, dots_5, character_7, character_7,
         character_7, dots_9
     ]
     grouped_hands = ScoringRules.HKRules.validate_hand([], hand, dots_9)
     self.assertEqual(len(grouped_hands), 1)
Exemple #14
0
 def generate_mountains(self):
     # for each tile there is a chance of it being a mountain
     # mountains can't generate on water
     for i in range(0, self.size+2):               
         for j in range(0, self.size+2):
             chance = random.randint(1, 100)
             if self.tile_array[i][j].is_set==False and chance<=self.mountain_chance:
                 self.map_array[i][j] = 'M'
                 t = random.randint(1, 2)            # selecting random forest tile (there are 3 forest tiles)
                 if t==1:
                     self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "mountain", 0, self.mountain_image1, True)
                 else:
                     self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "mountain", 0, self.mountain_image2, True)
 def test_one_suit_wo_honor(self):
     dots_1 = Tile.Tile("dots", 1)
     dots_2 = Tile.Tile("dots", 2)
     dots_6 = Tile.Tile("dots", 6)
     dots_7 = Tile.Tile("dots", 7)
     dots_9 = Tile.Tile("dots", 9)
     hand = [
         dots_1, dots_1, dots_1, dots_2, dots_2, dots_2, dots_6, dots_6,
         dots_6, dots_7, dots_7, dots_7, dots_9
     ]
     grouped_hands = ScoringRules.HKRules.validate_hand([], hand, dots_9)
     score, _ = ScoringRules.HKRules.score_one_suit([], grouped_hands[0])
     self.assertEqual(score, 7)
Exemple #16
0
 def setupBoard(self, level):
     lines=open("level_"+str(level)+".txt", "r").readlines()
     if lines:
         for j, line in enumerate(lines):
             kva=list()
             for i, type in enumerate(line.strip('\n')):
                 if type=='0':
                     frame=[0, 0, 32, 32]
                     kva.append(t.Tile(self.tileSurfaces['tiles'], pygame.Rect(i*32, j*32, 32, 32), frame))
                 else:
                     frame=[32, 0, 32, 32]
                     kva.append(t.Tile(self.tileSurfaces['tiles'], pygame.Rect(i*32, j*32, 32, 32), frame))
             self.board.append(kva)
Exemple #17
0
    def generate_level(self, images):
        level_grid = []

        screen_info = pygame.display.Info()

        for i in range((screen_info.current_w // 32) + 1):
            level_grid.append(["w"] * ((screen_info.current_h // 32) + 1))

        num_floors = (len(level_grid) * len(level_grid[0]) * 0.6)

        floor_count = 0

        x = len(level_grid) // 2
        y = len(level_grid[0]) // 2

        while floor_count < num_floors:
            if level_grid[x][y] != "f":
                level_grid[x][y] = "f"
                floor_count += 1

            dir = random.randint(1, 4)

            if dir == 1 and x > 2:
                x -= 1
            if dir == 2 and x < len(level_grid) - 4:
                x += 1
            if dir == 3 and y > 2:
                y -= 1
            if dir == 4 and y < len(level_grid[0]) - 4:
                y += 1

        self.place_start(level_grid)
        self.place_end(level_grid)

        for x in range(len(level_grid)):
            for y in range(len(level_grid[0])):
                if level_grid[x][y] == "w":
                    self.walls.add(Tile(images["w"], (x * 32, y * 32)))
                if level_grid[x][y] == "f":
                    self.floors.add(Tile(images["f"], (x * 32, y * 32)))
                if level_grid[x][y] == "s":
                    self.start = Door(images["door"], (x * 32, y * 32), False)
                    self.walls.add(self.start)
                if level_grid[x][y] == "e":
                    self.end = Door(images["door"], (x * 32, y * 32), False)
                    self.walls.add(self.end)

        for i in range(5):
            self.enemies.add(
                Enemy("images/enemy1.png",
                      random.choice(self.floors.sprites()).rect.center, self))
Exemple #18
0
    def buildMap(self):
        mapData = LevelHandler.loadMapFile(self.level)
        mapList = LevelHandler.parseMap(mapData)
        tileData = LevelHandler.parseData(mapData)
        try:
            stockTypes = LevelHandler.getStockBoxes(tileData)
        except:
            stockTypes = []
        boxCount = 0
        y = -1
        for line in mapList:
            x=-1
            y+=1
            for char in line:
                x+=1
                if char == "v":
                    self.tiles.append(Tile((x*80,y*80), "Images/Tiles/stove_front.png", True, False))
                if char == "s":
                    try:
                        food = stockTypes[boxCount]
                    except:
                        food = None
                    self.tiles.append(StockBox((x*80,y*80), food, True))
                    boxCount += 1
                if char == "#":
                    try:
                        top = mapList[y-1][x]
                        bottom = mapList[y+1][x]
                        left = mapList[y][x-1]
                        right = mapList[y][x+1]
                    except:
                        pass
                    if y == 0 and x != 0 and x!= 11:
                        self.tiles.append(Counter((x*80,y*80), None,"Images/Tiles/counter_front.png"))
                    elif x == 0 and y != 0:
                        self.tiles.append(Counter((x*80,y*80), None,"Images/Tiles/counter_side_left.png"))
                    elif x == 11 and y!= 0:
                        self.tiles.append(Counter((x*80,y*80), None,"Images/Tiles/counter_side_right.png"))
                    elif x == 0 and y == 0:
                        self.tiles.append(Counter((x*80,y*80), None,"Images/Tiles/counter_corner_tl.png"))
                    else:
                        self.tiles.append(Counter((x*80,y*80), None,"Images/Tiles/counter_top.png"))

                if char == "t":
                    self.tiles.append(Trash((x*80,y*80)))
                if char == "d":
                    self.tiles.append(DeliveryTable((x*80,y*80), None))
                if char == "c":
                    self.tiles.append(ChoppingBoard((x*80,y*80), None))
                if char == "-":
                    self.tiles.append(Tile((x*80,y*80), "Images/Tiles/floor.png"))
    def test_big_honors(self):
        dots_1 = Tile.Tile("dots", 1)
        dots_2 = Tile.Tile("dots", 2)
        red = Tile.Tile("honor", "red")
        green = Tile.Tile("honor", "green")
        white = Tile.Tile("honor", "white")

        hand = [
            red, red, red, green, green, green, white, white, white, dots_1,
            dots_1, dots_1, dots_2
        ]
        grouped_hands = ScoringRules.HKRules.validate_hand([], hand, dots_2)
        score, _ = ScoringRules.HKRules.score_honor_tiles([], grouped_hands[0])
        self.assertEqual(score, ScoringRules.HKRules.get_score_upper_limit())
Exemple #20
0
    def test_one_nines(self):
        bamboo_1 = Tile.Tile("bamboo", 1)
        bamboo_9 = Tile.Tile("bamboo", 9)
        dots_1 = Tile.Tile("dots", 1)
        east = Tile.Tile("honor", "east")
        character_9 = Tile.Tile("characters", 9)

        hand = [
            bamboo_1, bamboo_1, bamboo_1, bamboo_9, bamboo_9, bamboo_9, dots_1,
            dots_1, dots_1, east, east, east, character_9
        ]
        grouped_hands = ScoringRules.HKRules.validate_hand([], hand,
                                                           character_9)
        self.assertEqual(len(grouped_hands), 1)
Exemple #21
0
 def generate_empty(self):
     # first loop that creates all the tiles with is_set = false and borders
     for i in range(0, self.size+2):               
         for j in range(0, self.size+2):
             if i==0 or i==self.size+1 or j==0 or j==self.size+1:        # generates map outline, overwrites everthing   (TO DO)
                 self.map_array[i][j] = 'B'
                 self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "border", 0, self.mountain_image2, True)
             else:                                 # generates grass if a tile is empty
                 self.map_array[i][j] = 'G'
                 t = random.randint(1, 2)            # selecting random forest tile (there are 3 forest tiles)
                 if t==1:
                     self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "grass", 0, self.grass_image1, False)
                 else:
                     self.tile_array[i][j] = Tile(i, j, i*tile_size, j*tile_size, "grass", 0, self.grass_image2, False)
Exemple #22
0
 def load_tile(self, tile: namedtuple, x, y):
     if 'sides' in tile.type:
         Tile.Tile(tile, self.tiles, self.all_sprites, self.side_sprites, x,
                   y)
     elif tile.type.startswith('floor'):
         Tile.Tile(tile, self.tiles, self.all_sprites, self.floor_sprites,
                   x, y)
     elif tile.type.startswith('animated'):
         if tile.name.startswith('spikes'):
             AnimatedTile.AnimatedTile(self.tiles[tile.type][tile.name], 1,
                                       4, x, y, self.animated_sprites,
                                       self.all_sprites)
     elif tile.type.startswith('items'):
         Tile.Tile(tile, self.tiles, self.all_sprites, self.boxes_sprites,
                   x, y)
Exemple #23
0
    def LoadBoard(self):
        y = 0
        x = 0
        level = open("levels/level1.lvl", "r").read()
        for row in level.split("\n"):
            print "newline"
            for element in row.split(","):
                tileMeta = element.split(":")
                rot = 1
                if len(tileMeta) > 1: rot = tileMeta[1]
                newTile = ""
                if (tileMeta[0] == "0"):
                    newTile = Tile(x, y)
                elif (tileMeta[0] == "1"):
                    newTile = Tile_Conveyer(x, y, rot)
                tileSprite = pygame.sprite.RenderPlain(newTile)
                tileSprite.draw(self.screen)
                self.tiles.append((newTile, tileSprite))

                x += 1
            y += 1
            self.width = x * 50
            self.height = y * 50
            x = 0
        self.screen = pygame.display.set_mode((self.width, self.height))
Exemple #24
0
 def __init__(self, size):
     self.size = size
     self.tiles = []
     for y in range(self.size.y):
         for x in range(self.size.x):
             self.tiles.append(Tile(Vector2i(x, y)))
     self.layersName = {}
    def get_state_from_strings(state_str):
        """
            Take a list of strings that contain any of GamePiece.B_CHAR, GamePiece.W_CHAR, GamePiece.EMPTY_CHAR and
            return a 2d list of Tiles with GamePieces corresponding to

            ex. to generate the starting state:
                start_state_str = [
                    '--------',
                    '--------',
                    '--------',
                    '---wb---',
                    '---bw---',
                    '--------',
                    '--------',
                    '--------'
                ]
                start_state = Board.get_state_from_strings(start_state_str)
        """

        state = []
        for rank_index, rank in enumerate(state_str):
            state.append([])
            for file_index, color in enumerate(rank):
                state[rank_index].append(Tile.Tile(GamePiece.GamePiece(color)))

        return state
Exemple #26
0
    def __init__(self, game, base, door, background, full_background, props,
                 enemies):
        self.base = base
        self.door = door  #list of doors that this room has
        self.game = game

        self.background = background  #filename of the background image for this room's tiles

        self.full_background = full_background

        self.full_background_image = pygame.image.load(
            self.full_background).convert_alpha()

        self.doors = door

        rows, cols = (8, 8)

        self.props = props

        self.enemies = enemies

        #initialize array the manual way
        self.tiles = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]

        x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        for x in range(0, 8):
            for y in range(0, 8):
                self.tiles[x][y] = Tile(
                    self.game, x1[x], x1[y],
                    background)  #fill the 2d array with tile objects
def main_gen_level_algorithm():
    rnd = 0
    level = [[
        tile.Tile(blocked=True,
                  explore=True,
                  view=True,
                  char='#',
                  color=color.dark_wall) for i in range(const.MAP_WIDTH)
    ] for j in range(const.MAP_HEIGHT)]
    rooms = [make.create_room()]

    bsp = libtcod.bsp_new_with_size(0, 0, 50, 50)
    libtcod.bsp_split_recursive(bsp, 0, 2, 5, 5, 1.5, 1.5)
    fathre = libtcod.bsp_right(bsp)
    print(fathre.y)
    """
    нач:
        выбираем правого
        если его нету есть в списке:
            нач.
        иначе:
            добавляем текущий в список
            возвращаемся к папе
            выбираем левого
            нач.
    """

    return level
Exemple #28
0
    def __init__(self, rows, cols, player, enemies, **kwargs):
        self.player = player
        self.enemies = enemies
        self.rows = rows
        self.cols = cols
        self.start = None
        self.exit = None

        # create player image
        self.playerImage = None

        # create list of tiles
        self.land = []
        for i in range(0, rows):
            self.land.append([])
            for j in range(0, cols):
                self.land[i].append(t.Tile())

        # connect tiles in a dictionary
        self.connectDictionary()

        self.corners = [self.land[0][0],
                        self.land[0][self.cols-1],
                        self.land[self.rows-1][self.cols-1],
                        self.land[self.rows-1][0]]

        # should there be barriers?
        if "barriers" in kwargs:
            if kwargs["barriers"]:
                self.setBarriers(0, self.rows, 0, self.cols)
        else:
            self.setBarriers(0, self.rows, 0, self.cols)
    def create_matrix(self):
        """
        Cria a matriz de pecas do tabuleiro
        """
        import random
        random.seed()
        #pecas_disponiveis   = ["escudo", "espada", "espada_dupla", "machadinha", "adaga", "punhais"]
        pecas_disponiveis = [
            "escudo", "punhais", "espada_dupla", "machadinha", "adaga"
        ]
        x_start, y_start = 10, self.running.top_bar
        x, y = x_start, y_start
        anterior_esq = [None] * self.running.linhas
        anterior_acima = None

        for i in range(self.running.colunas):
            coluna = []
            for j in range(self.running.linhas):
                possiveis_escolhas = pecas_disponiveis.copy()
                if possiveis_escolhas.count(anterior_esq[j]) > 0:
                    possiveis_escolhas.remove(anterior_esq[j])
                if possiveis_escolhas.count(anterior_acima) > 0:
                    possiveis_escolhas.remove(anterior_acima)

                e_type = random.choice(possiveis_escolhas)
                tile = Tile(self.game, x, y, e_type)
                coluna.append(tile)
                self.running.game_images.append(tile.game_image)
                y += self.running.y_space
                anterior_esq[j] = e_type
                anterior_acima = e_type
            self.running.tabuleiro.append(coluna)
            x += self.running.x_space
            y = y_start
        return
Exemple #30
0
 def add(self, letter):
     if len(self.tiles) < self.rows * self.cols:
         used_positions = [t for t in self.tile_positions]
         for i in range(self.rows * self.cols):
             if i not in used_positions:
                 print("Assigning {} to position {}".format(letter, i))
                 next_avail_coord = self.grid.coord_from_pos(i)
                 break
     else:
         print("Hand is full.")
         return
     color = RANK_COLOR[LETTER_RANK[letter]]
     new_tile = Tile(self.canvas,
                     self.grid.pxcoord_from_coord(next_avail_coord),
                     grid=self.grid,
                     color=color,
                     text=letter,
                     width=self.twidth,
                     height=self.theight,
                     frozen=False)
     new_tile.reveal()
     self.tiles.append(new_tile)
     self.tile_positions.append(i)
     self.changed = True
     print("Hand: {}".format(self.tiles))