Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
naval_battle implementation in C using only the stdio.h for Standard Input and Output. More...
#include <stdio.h>
Functions | |
int | validEntryLineColumn (int line, char column) |
for Standard Input Output More... | |
int | validatePosition (int mat[10][10], int boat, int line, int column, char guide) |
Function validatePosition Responsible for checking if the position can receive the boat. More... | |
int | canShoot (int mat[10][10], int line, int column) |
Function canShoot Responsible to verify that it is a valid position to shoot. More... | |
void | positionBoat (int mat[10][10], int boat) |
Function positionBoat Responsible for placing the boats on the board, according to the size. More... | |
void | printMessage (char *msg) |
Function printMessage Responsible for printing the auxiliary message. More... | |
void | printMessageScore (int pts1, int pts2) |
Function printMessageScore Responsible for printing the score messages. More... | |
char | printTable (int logic, int stage) |
Function printTable Responsible for printing the board. More... | |
void | printsTray (int mat[10][10], int stage) |
Function printsTray Responsible for printing the visual board for the user. More... | |
void | shoot (int mat[10][10], int line, int column) |
Function shoot Responsible for saying if he hit a boat. More... | |
int | calculateScore (int mat[10][10], int line, int column) |
Function calculateScore Responsible for calculating the score obtained during the game. More... | |
void | printPositioning (int Player, int boat, int nm) |
Function printPositioning Responsible for printing messages for positioning boats on the board; of player 1 and 2. More... | |
int | main () |
Main function. More... | |
naval_battle implementation in C using only the stdio.h for Standard Input and Output.
Naval battle is a game, to be played by two people. It consists of knocking down the enemy ship, through shots , when hit the ship is revealed with the respective number of its size. Example: size 3 = 3 3 3 on the board. To play - boats over size 1, need direction; V -> vertical and H -> horizontal. Example Input 1 A H -> line 1, column A, direction H (Horizontal).
int calculateScore | ( | int | mat[10][10], |
int | line, | ||
int | column | ||
) |
Function calculateScore Responsible for calculating the score obtained during the game.
mat | board |
line | matrix row |
column | matrix column |
int canShoot | ( | int | mat[10][10], |
int | line, | ||
int | column | ||
) |
Function canShoot Responsible to verify that it is a valid position to shoot.
mat | board |
line | matrix row |
column | matrix column |
int main | ( | void | ) |
Main function.
the one with the most points wins, or the one who knocks down all boats first.
void positionBoat | ( | int | mat[10][10], |
int | boat | ||
) |
Function positionBoat Responsible for placing the boats on the board, according to the size.
mat | board |
boat | boat |
void printMessage | ( | char * | msg | ) |
void printMessageScore | ( | int | pts1, |
int | pts2 | ||
) |
Function printMessageScore Responsible for printing the score messages.
pts1 | player 1 score |
pts2 | player 2 score |
void printPositioning | ( | int | Player, |
int | boat, | ||
int | nm | ||
) |
Function printPositioning Responsible for printing messages for positioning boats on the board; of player 1 and 2.
Player | number representing the Player |
boat | number that represents the boat |
nm | which message to print |
void printsTray | ( | int | mat[10][10], |
int | stage | ||
) |
Function printsTray Responsible for printing the visual board for the user.
mat | Matrix |
stage | game step |
char printTable | ( | int | logic, |
int | stage | ||
) |
Function printTable Responsible for printing the board.
logic | return of the logical matrix |
stage | game step |
void shoot | ( | int | mat[10][10], |
int | line, | ||
int | column | ||
) |
Function shoot Responsible for saying if he hit a boat.
mat | board |
line | matrix row |
column | matrix column |
int validatePosition | ( | int | mat[10][10], |
int | boat, | ||
int | line, | ||
int | column, | ||
char | guide | ||
) |
Function validatePosition Responsible for checking if the position can receive the boat.
mat | board |
boat | boat |
line | matrix row |
column | matrix column |
int validEntryLineColumn | ( | int | line, |
char | column | ||
) |
for Standard Input Output
Function validEntryLineColumn Responsible for validating entries, for positioning boats
line | matrix row |
column | matrix column |