Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Battleship game in C program (Code) You need to build the software infrastructur

ID: 3568400 • Letter: B

Question

Battleship game in C program (Code)

You need to build the software infrastructure that will allow you to build a simplified version of the classic game of Battleship that will display on the screen/console. In this program, the user will attempt to find a randomly placed aircraft carrier and battleship on a 10 by 10 board implemented as a two-dimensional array. You should define this SIZE as a constant in case you want to expand or shrink the board later.

Your program will then ask the user to enter the difficulty level of the game as a string, where

Explanation / Answer

#include #include void startBoard(int board[][5]) { int line, column; for(line=0 ; line < 5 ; line++ ) for(column=0 ; column < 5 ; column++ ) board[line][column]=-1; } void showBoard(int board[][5]) { int line, column; printf(" 1 2 3 4 5"); printf(" "); for(line=0 ; line < 5 ; line++ ){ printf("%d",line+1); for(column=0 ; column < 5 ; column++ ){ if(board[line][column]==-1){ printf(" ~"); }else if(board[line][column]==0){ printf(" *"); }else if(board[line][column]==1){ printf(" X"); } } printf(" "); } } void startShips(int ships[][2]){ srand(time(NULL)); int ship, last; for(ship=0 ; ship < 3 ; ship++){ ships[ship][0]= rand()%5; ships[ship][1]= rand()%5; //let's check if this shot was not tried //if it was, just get out of the 'do while' loop when draws a pair that was not tried for(last=0 ; last
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote