Exemplo n.º 1
0
 def test_rand_coords(self):
     """ Should return coodinates that are within the limits. """
     size = 2
     mine_matrix = MineMatrix(size)
     (x, y) = mine_matrix._random_coord()
     self.assertLess(x, mine_matrix.height)
     self.assertLess(y, mine_matrix.width)
Exemplo n.º 2
0
 def to_matrix(self):
     from minesweeper.grids.matrices import MineMatrix
     matrix = MineMatrix(self.height, self.width)
     for entry in self.map_data:
         # Each entry is a mine that needs to be placed in the empty matrix
         matrix.place_mine(entry.row_num, entry.col_num)
     return matrix
Exemplo n.º 3
0
    def post(self):
        """ Creates a new Game, MineMap, and PlayerMaps. """
        # Create a MineMap
        mine_matrix = MineMatrix(const.DEFAULT_HEIGHT,
                                 width=const.DEFAULT_WIDTH,
                                 mine_number=const.DEFAULT_MINES)
        mine_map = mine_matrix.to_model()
        DBSession.add(mine_map)
        DBSession.flush()

        # Create a Game and PlayerMaps for it
        game = models.Game(mine_map=mine_map.id)
        game.player_maps = [
            models.PlayerMap(map_type=const.PlayerMapType.CLICK),
            models.PlayerMap(map_type=const.PlayerMapType.FLAG),
        ]
        DBSession.add(game)
        DBSession.flush()
        return HTTPFound(location=self.request.route_url('view_game',
                                                         game_id=game.id))