Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you add an IPO chart to this code about a battleship game?#include #include #include #define GRID _ SIZE 1 0 #define NUM _ SHIPS
Can you add an IPO chart to this code about a battleship game?#include
#include
#include
#define GRIDSIZE
#define NUMSHIPS
typedef struct
char name;
char symbol;
int size;
int x;
int y;
int direction; horizontal, vertical
int hits;
Ship;
typedef struct
char gridGRIDSIZEGRIDSIZE;
Ship shipsNUMSHIPS;
int missilesfired;
GameState;
Function Prototypes
void initializegameGameState game;
void placeshipsGameState game;
int isvalidpositionGameState game Ship ship;
void printgridGameState game;
void firemissileGameState game;
void checksinkGameState game;
void savescoresGameState game;
void loadscores;
void displayscores;
int main
GameState game;
char command;
int gameover ;
srandtimeNULL; Seed random number generator
initializegame&game;
placeships&game;
while gameover
printgrid&game;
printfMissiles fired: d
game.missilesfired;
printfEnter f to fire a missile, q to quit: ;
scanfc &command;
if command f
firemissile&game;
game.missilesfired;
checksink&game;
if gamemissilesfired
printfReached maximum efficient missile count.
;
else if command q
printfExiting game.
;
savescores&game;
gameover ;
displayscores;
return ;
void initializegameGameState game
for int i ; i GRIDSIZE; i
for int j ; j GRIDSIZE; j
gamegridij;
gameshipsShipSeminole State Ship", S;
gameshipsShipAir Force Academy", A;
gameshipsShipValencia Destroyer", V;
gameshipsShipEskimo University", E;
gameshipsShipDeland High School", D;
gamemissilesfired ;
void placeshipsGameState game
for int i ; i NUMSHIPS; i
int placed ;
while placed
gameshipsix rand GRIDSIZE;
gameshipsiy rand GRIDSIZE;
gameshipsidirection rand;
if isvalidpositiongame gameshipsi
for int j ; j gameshipsisize; j
if gameshipsidirection
gamegridgameshipsiygameshipsix j gameshipsisymbol;
else
gamegridgameshipsiy jgameshipsix gameshipsisymbol;
placed ;
int isvalidpositionGameState game Ship ship
for int i ; i ship.size; i
int x ship.x shipdirection i : ;
int y ship.y shipdirection i : ;
if x GRIDSIZE y GRIDSIZE gamegridyx
return ;
return ;
void printgridGameState game
for int i ; i GRIDSIZE; i
for int j ; j GRIDSIZE; j
printfc gamegridij;
printf
;
void firemissileGameState game
int x y;
printfEnter coordinates to fire x y: ;
scanfd d &x &y;
if x x GRIDSIZE y y GRIDSIZE
printfInvalid coordinates.
;
return;
if gamegridyx
gamegridyxM;
else if gamegridyxM && gamegridyxH
gamegridyxH;
void checksinkGameState game
for int k ; k NUMSHIPS; k
int hits ;
for int i ; i gameshipsksize; i
int x gameshipskx gameshipskdirection i : ;
int y gameshipsky gameshipskdirection i : ;
if gamegridyxH
hits;
if hits gameshipsksize
for int i ; i gameshipsksize; i
int x gameshipskx gameshipskdirection i : ;
int y
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started