良い一日を。私のコードでかなり奇妙なことが起こっています。乱数を作成して quest_postition 配列に入力し、グリッド配列で使用したいと考えています。プログラムを実行するたびに場所を変えたい。
現在行っていることは、無限ループに入り、グリッドをずっと下に表示することです。
これが私のコードです:
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
using namespace std;
void draw_grid()
{
char grid[9][9] = { {'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x'}};
char character = '*';
char quest = 'Q';
int position[2] = {4,4};
int quest_position[2];
srand(time(NULL));
quest_position[0] = rand() % 9 + 0;
quest_position[1] = rand() % 9 + 0;
char direction;
for(int i = 0; i < 9; i++){
for (int j = 0; j < 9; j++){
if(i == position[0] && j == position[1])
cout << character;
if(i = quest_position[0] && j == quest_position[1])
cout << quest;
else
cout << grid[i][j];
cout << " ";
}
cout << endl;
}
}
int main()
{
draw_grid();
}
助けてください。
ありがとう。