Dungeon Crawlの分岐を表示するコードを書いてみた。うまく重ならないようにするには工夫が必要。図でLを配置してからVが後で重なることが判明した場合ずらす必要があるが、Lに属するMやPも移動させないといけない。
そういうことを防ぐには、これを横にした二分木とみなし、上の方から位置を確定させていけばよい。配置する場合は自分より上のものをチェックし重ならないように決める。
01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27 [T]| | | [H] | | | 01-02-03-04 | | [V] | | 01-02-03-04-05-06-07-08 | | | [B] | | [C] | | 01-02-03-04-05 | [L] [T] | 01-02-03-04-05-06-07-08-09-10 01-02-03 [O] | | [M] 01-02-03-04 | | 01-02-03-04-05-06 | | [P] | | 01-02-03-04-05 | [S] | 01-02-03-04-05 [E] 01-02-03-04-05-06-07
そのためのクラス
class branch_disp { public: int id, sidx; int sx, sy, ex, ey; //表示領域 branch_disp *child; //長男(自分から出ている枝で最も右のもの) branch_disp *next; //弟(自分と同じ親から出ている枝で自分の左にあるもの) branch_disp *parent;//親 int startdepth; //親のどこから生えているか int depth; //長さ branch_disp(branch_disp *root, int sdep, int dep); bool overlap(branch_disp *b); //重なり判定 }; branch_disp::branch_disp(branch_disp *root, int sdep, int dep) { startdepth = sdep; depth = dep; parent = root; child = NULL; next = NULL; if(!root) return; //幹 branch_disp **h = &(root->child); branch_disp *ph = *h; while(ph != NULL) { if (ph->startdepth < sdep) break; h = &(ph->next); ph = *h; } next = ph; *h = this; }