project for 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Diff: map.cpp
- Revision:
- 8:2e18a96e0c77
- Parent:
- 7:1912b4a2e4fe
- Child:
- 9:c9d6eda597b0
--- a/map.cpp Tue Nov 24 11:21:33 2020 +0000 +++ b/map.cpp Tue Nov 24 12:35:16 2020 +0000 @@ -33,7 +33,8 @@ * This function should uniquely map (x,y) onto the space of unsigned integers. */ static unsigned XY_KEY(int X, int Y) { - // TODO: Fix me! + //implement pairing function for unique number + return .5(X+Y)(X+Y+1)+Y; } /** @@ -43,14 +44,16 @@ */ unsigned map_hash(unsigned key) { - // TODO: Fix me! + return key%5; } void maps_init() -{ - // TODO: Implement! +{ // Initialize hash table + items = createHashTable(map_hash, 5); // Set width & height + w = 500; + h = 500; } Map* get_active_map() @@ -82,49 +85,49 @@ int map_width() { - + return get_active_map()->w; } int map_height() { - + return get_active_map()->h; } int map_area() { - + return map_height()*map_width(); } MapItem* get_current(int x, int y) { - + return getItem(get_active_map()->items, XY_KEY(x,y)); } MapItem* get_north(int x, int y) { - + return getItem(get_active_map()->items, XY_KEY(x,y+1)); } MapItem* get_south(int x, int y) { - + return getItem(get_active_map()->items, XY_KEY(x,y-1)); } MapItem* get_east(int x, int y) { - + return getItem(get_active_map()->items, XY_KEY(x+1,y)); } MapItem* get_west(int x, int y) { - + return getItem(get_active_map()->items, XY_KEY(x-1,y)); } MapItem* get_here(int x, int y) { - + return getItem(get_active_map()->items, XY_KEY(x,y)); } void map_erase(int x, int y) { - + deleteItem(get_active_map()->items, XY_KEY(x,y)); } void add_wall(int x, int y, int dir, int len)