Skip to content

Instantly share code, notes, and snippets.

@Dretch
Created February 9, 2013 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dretch/4747041 to your computer and use it in GitHub Desktop.
Save Dretch/4747041 to your computer and use it in GitHub Desktop.
enum TileType {
WALL,
FLOOR
}
pub struct Tile {
known : bool,
t : TileType
}
const MAP_WIDTH : uint = 16;
const MAP_HEIGHT : uint = 16;
pub struct HexMap {
// TODO: use constants above (do not work now for some reason)
map : [ mut [mut Tile * 16] * 16]
}
pub impl HexMap {
fn at(&self, x : int, y : int) -> Tile {
self.map[x][y]
}
static fn new() -> ~HexMap {
let map = ~HexMap {
map: [mut [mut Tile {known: false, t: WALL}, .. 16], .. 16]
};
let rng = rand::Rng();
for uint::range(0u, MAP_WIDTH) |x| {
for uint::range(0u, MAP_HEIGHT) |y| {
map.map[x][y].t = if (rng.gen_int_range(0, 10) == 0) {
WALL
} else {
FLOOR
}
}
}
map
}
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment