Skip to content

中級サンプル

Kasugaccho edited this page Apr 27, 2019 · 2 revisions

迷路の生成

サンプルコード

#include <DTL.hpp>
#include <array>
#include <bitset>
#include <cstddef>

int main() {

	//X方向の大きさ
	constexpr std::size_t width{ 33 };

	//Y方向の大きさ
	constexpr std::size_t height{ 17 };

	//ダンジョン行列 (0で初期化)
	std::array<std::bitset<width>, height> matrix{ {} };

	//迷路を生成 (値1の通路を作成する)
	dtl::MazeDig<bool>(1).draw(matrix, width, height);

	//数値出力 (区切りは「,」)
	dtl::OutputNumber<bool>(",").draw(matrix, width, height);

	//文字出力 (値0の場合は「##」、値1の場合は「  」が出力される)
	dtl::OutputString<bool>("##", "  ").draw(matrix, width, height);

}

出力結果

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,
0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,
0,1,1,1,0,1,0,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,
0,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,
0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,
0,1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,0,
0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,0,1,0,
0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,
0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,0,
0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,
0,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,0,
0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,
0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
##################################################################
##              ##      ##      ##              ##      ##      ##
######  ######  ##  ##  ##  ##  ##  ##########  ##  ######  ##  ##
##      ##  ##  ##  ##      ##  ##      ##      ##  ##      ##  ##
##  ##  ##  ##  ##  ##########  ######  ##  ######  ##  ######  ##
##  ##      ##  ##  ##      ##          ##      ##      ##      ##
##  ##########  ##  ##  ##  ##################  ##  ######  ######
##  ##          ##  ##  ##  ##      ##          ##      ##  ##  ##
##  ##  ##  ######  ######  ##  ##  ######  ##########  ##  ##  ##
##  ##  ##  ##              ##  ##  ##      ##      ##  ##  ##  ##
##  ######  ##  ##############  ######  ######  ######  ##  ##  ##
##  ##      ##                  ##                  ##  ##      ##
##  ##  ######  ##################  ##########  ##  ##  ##########
##  ##      ##  ##      ##      ##          ##  ##  ##          ##
##  ######  ######  ##  ##  ##  ##########  ##  ##########  ##  ##
##      ##          ##      ##              ##              ##  ##
##################################################################

Clone this wiki locally