int main() {
std::srand(std::time(0));
GameEntity treasure = {
{ std::rand() % board.xDimension,
std::rand() % board.yDimension},
TREASURESYMBOL
};
GameEntity trapsInMap[NUMBEROFTRAPS];
setEntityPositions(trapsInMap, NUMBEROFTRAPS, TRAPSYMBOL);
GameEntity banditsInMap[NUMBEROFBANDITS];
setEntityPositions(banditsInMap, NUMBEROFBANDITS, BANDITSYMBOL);
GameEntity alvaro;player;
setPlayerPosition(alvaroplayer, PLAYERSYMBOL);
int gameCondition = drawBoard(alvaroplayer, trapsInMap, banditsInMap, treasure);
do {
Direction direction;
do {
direction = askDirection();
std::cout << std::endl;
} while (direction == WRONG_DIRECTION);
movePlayer(alvaroplayer, direction);
for (int i = 0; i < NUMBEROFBANDITS; i++) {
moveBandit(banditsInMap[i]);
}
clearScreenAndMoveToHome();
gameCondition = drawBoard(alvaroplayer, trapsInMap, banditsInMap, treasure);
} while (gameCondition == CONTINUE);
endGame (gameCondition);
}
int main() {
std::srand(std::time(0));
GameEntity treasure = {
{ std::rand() % board.xDimension,
std::rand() % board.yDimension},
TREASURESYMBOL
};
GameEntity trapsInMap[NUMBEROFTRAPS];
setEntityPositions(trapsInMap, NUMBEROFTRAPS, TRAPSYMBOL);
GameEntity banditsInMap[NUMBEROFBANDITS];
setEntityPositions(banditsInMap, NUMBEROFBANDITS, BANDITSYMBOL);
GameEntity alvaro;
setPlayerPosition(alvaro, PLAYERSYMBOL);
int gameCondition = drawBoard(alvaro, trapsInMap, banditsInMap, treasure);
do {
Direction direction;
do {
direction = askDirection();
std::cout << std::endl;
} while (direction == WRONG_DIRECTION);
movePlayer(alvaro, direction);
for (int i = 0; i < NUMBEROFBANDITS; i++) {
moveBandit(banditsInMap[i]);
}
clearScreenAndMoveToHome();
gameCondition = drawBoard(alvaro, trapsInMap, banditsInMap, treasure);
} while (gameCondition == CONTINUE);
endGame (gameCondition);
}
int main() {
std::srand(std::time(0));
GameEntity treasure = {
{ std::rand() % board.xDimension,
std::rand() % board.yDimension},
TREASURESYMBOL
};
GameEntity trapsInMap[NUMBEROFTRAPS];
setEntityPositions(trapsInMap, NUMBEROFTRAPS, TRAPSYMBOL);
GameEntity banditsInMap[NUMBEROFBANDITS];
setEntityPositions(banditsInMap, NUMBEROFBANDITS, BANDITSYMBOL);
GameEntity player;
setPlayerPosition(player, PLAYERSYMBOL);
int gameCondition = drawBoard(player, trapsInMap, banditsInMap, treasure);
do {
Direction direction;
do {
direction = askDirection();
std::cout << std::endl;
} while (direction == WRONG_DIRECTION);
movePlayer(player, direction);
for (int i = 0; i < NUMBEROFBANDITS; i++) {
moveBandit(banditsInMap[i]);
}
clearScreenAndMoveToHome();
gameCondition = drawBoard(player, trapsInMap, banditsInMap, treasure);
} while (gameCondition == CONTINUE);
endGame (gameCondition);
}
int main() {
std::srand(std::time(0));
GameEntity treasure = {
.position = { .xposition = std::rand() % board.xDimension,
.yposition = std::rand() % board.yDimension},
.symbolTREASURESYMBOL
= TREASURESYMBOL};
GameEntity trapsInMap[NUMBEROFTRAPS];
setEntityPositions(trapsInMap, NUMBEROFTRAPS, TRAPSYMBOL);
GameEntity banditsInMap[NUMBEROFBANDITS];
setEntityPositions(banditsInMap, NUMBEROFBANDITS, BANDITSYMBOL);
GameEntity alvaro;
setPlayerPosition(alvaro, PLAYERSYMBOL);
int main() {
std::srand(std::time(0));
GameEntity treasure = {
.position = { .xposition = std::rand() % board.xDimension,
.yposition = std::rand() % board.yDimension},
.symbol = TREASURESYMBOL};
GameEntity trapsInMap[NUMBEROFTRAPS];
setEntityPositions(trapsInMap, NUMBEROFTRAPS, TRAPSYMBOL);
GameEntity banditsInMap[NUMBEROFBANDITS];
setEntityPositions(banditsInMap, NUMBEROFBANDITS, BANDITSYMBOL);
GameEntity alvaro;
setPlayerPosition(alvaro, PLAYERSYMBOL);
int main() {
std::srand(std::time(0));
GameEntity treasure = {
{ std::rand() % board.xDimension,
std::rand() % board.yDimension},
TREASURESYMBOL
};
GameEntity trapsInMap[NUMBEROFTRAPS];
setEntityPositions(trapsInMap, NUMBEROFTRAPS, TRAPSYMBOL);
GameEntity banditsInMap[NUMBEROFBANDITS];
setEntityPositions(banditsInMap, NUMBEROFBANDITS, BANDITSYMBOL);
GameEntity alvaro;
setPlayerPosition(alvaro, PLAYERSYMBOL);
The function setEntityPositions()
would just iterate over the array and set the position to a random position and the symbol to the passed-in symbol for each entity in the array. (And of course, you'll need to define TRAPSYMBOLTRAPSYMBOL
, BANDITSYMBOLBANDITSYMBOL
, PLAYERSYMBOL
, and PLAYERSYMBOLTREASURESYMBOL
appropriately.)
bool checkSquareAgainstEntity(int x, int y, GameEntity* entities, int numEntities)
{
bool result = false;
for (int z = 0; (z < numEntities) && (!result); z++ {
GameEntity nextEntity = entities [ z ];
if (nextEntity.position.xPosition == x **&&
nextEntity.position.yPosition == y) {
std::cout << nextEntity.symbol;
result = true;
}
}
return result;
}
The function setEntityPositions()
would just iterate over the array and set the position to a random position and the symbol to the passed-in symbol for each entity in the array. (And of course, you'll need to define TRAPSYMBOL, BANDITSYMBOL, and PLAYERSYMBOL appropriately.)
bool checkSquareAgainstEntity(int x, int y, GameEntity* entities, int numEntities)
{
bool result = false;
for (int z = 0; (z < numEntities) && (!result); z++ {
GameEntity nextEntity = entities [ z ];
if (nextEntity.position.xPosition == x **
nextEntity.position.yPosition == y) {
std::cout << nextEntity.symbol;
result = true;
}
}
return result;
}
The function setEntityPositions()
would just iterate over the array and set the position to a random position and the symbol to the passed-in symbol for each entity in the array. (And of course, you'll need to define TRAPSYMBOL
, BANDITSYMBOL
, PLAYERSYMBOL
, and TREASURESYMBOL
appropriately.)
bool checkSquareAgainstEntity(int x, int y, GameEntity* entities, int numEntities)
{
bool result = false;
for (int z = 0; (z < numEntities) && (!result); z++ {
GameEntity nextEntity = entities [ z ];
if (nextEntity.position.xPosition == x &&
nextEntity.position.yPosition == y) {
std::cout << nextEntity.symbol;
result = true;
}
}
return result;
}