座標の2D配列を作成し、オブジェクト(アイテム、宝物、敵)をランダムな場所に配置するこのメソッドを作成しました。現在のPlayerオブジェクトを取り込んで(現在のhp、統計、ポイントを維持できるように)、ランダムな場所に一連の座標とオブジェクトを生成する新しいメソッドを作成したいと思います。
void Game::newGame() {
srand(time(0));
int count = 0;
int row = 0;
int col = 0;
Room* newRoom = new Room;
room = newRoom;
m_alive = true;
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
room->aRoom[i][j] = NULL;
}
}
//spawn player at 0,0
room->aRoom[0][0] = new Player("Lemmiwinks", rand()%9+11, rand()%6+7, rand()%6+7);
m_player = room->aRoom[0][0];
room->currentRow = 0;
room->currentCol = 0;
printMoves();
//spawn boss
room->aRoom[rand()%rows][cols-1] = new Boss("Demon Lord", rand()%9 + 10, rand()%7 + 8, rand()%7 + 8);
//spawn meat cleaver
count = 0;
while(count < 1) {
row = rand()%rows;
col = rand()%cols;
if (room->aRoom[row][col] == NULL) {
room->aRoom[row][col] = new Item("Rusty Shank", 0, 3, 1);
count++;
}
}
//spawn barrel lid
count = 0;
while(count < 1) {
row = rand()%rows;
col = rand()%cols;
if (room->aRoom[row][col] == NULL) {
room->aRoom[row][col] = new Item("Barrel Lid", 0, 1, 3);
count++;
}
}
//place potion at random loc
count = 0;
while(count < 2) {
row = rand()%rows;
col = rand()%cols;
if (room->aRoom[row][col] == NULL) {
room->aRoom[row][col] = new Item("Potion", 10, 0, 0);
count++;
}
}
//place 5 enemies at random loc
count = 0;
while(count < 5) {
row = rand()%rows;
col = rand()%cols;
if (room->aRoom[row][col] == NULL) {
room->aRoom[row][col] = new Enemy("Demon", rand()%5 + 5, rand()%4 + 4, rand()%4 + 4);
count++;
}
}
//place 5 treasures at random loc
count = 0;
while(count < 5) {
row = rand()%rows;
col = rand()%cols;
if (room->aRoom[row][col] == NULL) {
room->aRoom[row][col] = new Treasure("Artifact", rand()%5 + 5);
count++;
}
}
cout << "\n---Stats---" << endl;
m_player->printEntity();
}
このメソッドを複製してプレーヤーオブジェクトを渡し、同じプレーヤーを新しいマップで再利用できるようにする方法はありますか?