Created
February 9, 2013 20:45
-
-
Save Dretch/4747041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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