Home / Expert Answers / Computer Science / draw-flowchart-according-to-the-program-provided-and-thoroughly-explain-the-flowchart-an-example-of-pa934

(Solved): Draw flowchart according to the program provided and thoroughly explain the flowchart. An example of ...



Draw flowchart according to the program provided and thoroughly explain the flowchart. An example of a similar flowchart is provided, please try your best to detail the new flowchart as the example below.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define ROWS 10
#define COLS 10

typedef struct {
int posX;
int posY;
int energy;
} Dodgeball;

void displayMap(char ary[ROWS][COLS], Dodgeball player1, Dodgeball player2)
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
if (i == player1.posX && j == player1.posY)
printf("1 ");
else if (i == player2.posX && j == player2.posY)
printf("2 ");
else
printf("%c ", ary[i][j]);
}
printf("\n");
}
}

int main()
{
srand(time(NULL));

char ary[ROWS][COLS];
int treasures, collected1 = 0, collected2 = 0;

for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
ary[i][j] = '.';
}
}

printf(" **Welcome to the Dodgeball Hunt game! **\n");
printf("You will be represented by the number '1', while your opponent will be represented by the number '2'.\n");
printf("Treasures are spread around the map and are indicated by the symbol '@'. Your mission is to gather as \nmany treasures as you can to boost your energy.\n");
printf("Each treasure you collect will increase your energy by 50 points.\n");
printf("But beware! Collisions with the opponent will cost each player 60 energy points.\n");
printf("Strategize your movements, gather treasures, and prepare for a deadly fight! \n");
printf("How many treasures would you like to have in this game? ");
scanf("%d", &treasures);
printf("\n");

if (treasures > 98)
{
printf("Error: Number of treasures exceeds the space available.\n");
return 1;
}

int totalTreasures = 0;
int chestPosX, chestPosY;
while (totalTreasures < treasures)
{
chestPosX = rand() % ROWS;
chestPosY = rand() % COLS;

if (ary[chestPosX][chestPosY] == '.' && (chestPosX != 0 || chestPosY != 0) && (chestPosX != ROWS - 1 || chestPosY != COLS - 1))
{
ary[chestPosX][chestPosY] = '@';
totalTreasures++;
}
}

Dodgeball player1;
player1.posX = 0;
player1.posY = 0;
player1.energy = 100;

Dodgeball player2;
player2.posX = ROWS - 1;
player2.posY = COLS - 1;
player2.energy = 100;

ary[player1.posX][player1.posY] = '1';
ary[player2.posX][player2.posY] = '2';

displayMap(ary, player1, player2);

char move;
while (player1.energy > 0 && player2.energy > 0)
{
int moveX, moveY;
printf("Player 1, enter your move (w for up, s for down, a for left, d for right): ");
scanf(" %c", &move);
system("@cls||clear");
printf("\n");

int newPosX = player1.posX;
int newPosY = player1.posY;

if (move == 'w' && player1.posX > 0)
{
newPosX--;
}
else if (move == 's' && player1.posX < ROWS - 1)
{
newPosX++;
}
else if (move == 'a' && player1.posY > 0)
{
newPosY--;
}
else if (move == 'd' && player1.posY < COLS - 1)
{
newPosY++;
}
else
{
printf("Invalid move. Please try again.\n");
continue;
}

if (ary[newPosX][newPosY] == '@')
{
collected1++;
player1.energy += 50;
}
else if (ary[newPosX][newPosY] == '2')
{
player1.energy -= 60;
player2.energy -= 60;
}

ary[player1.posX][player1.posY] = '.';
player1.posX = newPosX;
player1.posY = newPosY;
ary[player1.posX][player1.posY] = '1';

displayMap(ary, player1, player2);
printf("Player 1 energy: %d\n", player1.energy);
printf("Player 2 energy: %d\n", player2.energy);
printf("Treasures collected by Player 1: %d\n", collected1);
printf("Treasures collected by Player 2: %d\n", collected2);

printf("Player 2, enter your move (w for up, s for down, a for left, d for right): ");
scanf(" %c", &move);
system("@cls||clear");
printf("\n");

newPosX = player2.posX;
newPosY = player2.posY;

if (move == 'w' && player2.posX > 0)
{
newPosX--;
}
else if (move == 's' && player2.posX < ROWS - 1)
{
newPosX++;
}
else if (move == 'a' && player2.posY > 0)
{
newPosY--;
}
else if (move == 'd' && player2.posY < COLS - 1)
{
newPosY++;
}
else
{
printf("Invalid move. Please try again.\n");
continue;
}

if (ary[newPosX][newPosY] == '@')
{
collected2++;
player2.energy += 50;
}
else if (ary[newPosX][newPosY] == '1')
{
player1.energy -= 60;
player2.energy -= 60;
}

ary[player2.posX][player2.posY] = '.';
player2.posX = newPosX;
player2.posY = newPosY;
ary[player2.posX][player2.posY] = '2';

displayMap(ary, player1, player2);
printf("Player 1 energy: %d\n", player1.energy);
printf("Player 2 energy: %d\n", player2.energy);
printf("Treasures collected by Player 1: %d\n", collected1);
printf("Treasures collected by Player 2: %d\n", collected2);
}

if (player1.energy <= 0 && player2.energy <= 0)
{
printf("It's a draw! Both players’ energy ran out.\n");
}
else if (player1.energy <= 0)
{
printf("Player 2 wins! Player 1 energy ran out.\n");
}
else if (player2.energy <= 0)
{
printf("Player 1 wins! Player 2 energy ran out.\n");
}

return 0;
}



We have an Answer from Expert

View Expert Answer

Expert Answer



Step 1:
Display the game instructions and rules to the players.
Prompt the players for the number of ...
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe