GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cpp-tutorial/Map.cpp at master · chudonghao/cpp-tutorial Expand file tree/ Copy pathMap.cppMore file actions 38 lines (28 loc) · 1012 Bytes / Copy pathMap.cppFile metadata and controls38 lines (28 loc) · 1012 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include "Map.h" #include <random> Map::Map(int width, int height) : _width(width), _height(height) {} int Map::width() { return _width; } int Map::height() { return _height; } vec2 Map::food_pos() { return _food_pos; } // bool Map::CreateFood(int length, vec2 *exclude) { bool Map::CreateFood(const std::vector<vec2> &exclude) { std::random_device rd; std::default_random_engine re{rd()}; std::uniform_int_distribution<int> gen_x(0, _width - 1); std::uniform_int_distribution<int> gen_y(0, _height - 1); vec2 food_pos = vec2{gen_x(re), gen_y(re)}; vec2 food_pos_start = food_pos; bool collision_occurred = false; for (; collision(exclude, food_pos) && food_pos != food_pos_start;) { collision_occurred = true; food_pos = food_pos + vec2{1, 0}; if (!in_bound(_width, _height, food_pos)) { food_pos = vec2{0, (food_pos.y + 1) % _height}; } } if (collision_occurred && food_pos == food_pos_start) { return false; } _food_pos = food_pos; return true; } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |