privateの変数、xとyが意図したとおりに変化できない
このプログラムを実行すると、decide_direction()内のxとyが意図したとおりに変化しません。教えてもらえませんか?
このコードを実行したときに出力されるyの値を2, 4, 6, 8 ... としたいのですが、2, 2, 2, 2, ... と値が変わらないです。
#include <iostream>
#include <ctime>
/*
*棒倒し法
*/
class maze {
int wall_info[77][77] = {{0}};
int x, y;
public:
maze();
void make_wall();
int decide_direction();
int wall_check();
void show();
};
maze::maze()
{
//make wall
for (y = 0; y <= 76; y++) {
for (x = 0; x <= 76; x++) {
if (y == 0 || x == 0 || y == 76 || x == 76) {
wall_info[y][x] = 1;
}if (y % 2 == 0 && x % 2 == 0) {
wall_info[y][x] = 1;
}
}
}
y = 2;
x = 2;
}
void maze::make_wall()
{
while (y < 76) {
while (x < 76) {
if (decide_direction() == 4) {
wall_info[y - 1][x] = 1;
}
else if (decide_direction() == 3) {
wall_info[y][x - 1] = 1;
}
else if (decide_direction() == 2) {
wall_info[y + 1][x] = 1;
}
else {
wall_info[y][x + 1] = 1;
}
x += 2;
}
y += 2;
// std::cout << y << std::endl;
}
}
int maze::decide_direction()
{
int direction = 0;
int check;
std::cout << y << std::endl;
if (y <= 2) {
check = wall_check();
if (wall_check() == -1) {
direction = rand() % 3 + 1;
}
else {
direction = rand() % 4 + 1;
}
}
else {
if (wall_check() == -1) {
direction = rand() % 2 + 1;
}
else {
direction = rand() % 3 + 1;
}
}
return direction;
}
int maze::wall_check()
{
if (wall_info[y][x - 1] == 1) {
return -1;
}
else {
return 0;
}
}
void maze::show()
{
for (int i = 0; i <= 76; i++) {
for (int j = 0; j <= 76; j++) {
if (wall_info[i][j] == 1) {
std::cout << "■ ";
}
else {
std::cout << "□ ";
}
}
std::cout << std::endl;
}
}
int main()
{
srand((unsigned)time(NULL));
maze maze;
maze.make_wall();
maze.show();
return 0;
}