Update : improving code visualization

This commit is contained in:
Carlos 2021-02-18 03:00:14 -03:00
parent ef10b322a2
commit 9fd686b619

View File

@ -26,8 +26,10 @@ int validEntryLineColumn(int line, char column)
}
else
{
return 0;
}
}
/**
* @brief Function validatePosition
* Responsible for checking if the position can receive the boat.
@ -44,41 +46,56 @@ int validatePosition(int mat[10][10], int boat, int line, int column,
int i, j;
if (boat < 1 || boat > 3)
{
return 0;
}
if (guide != 'H' && guide != 'V')
{
return 0;
}
if ((line < 0 || line > 9) || (column < 0 || column > 9))
{
return 0;
}
if (guide == 'H')
{
if ((10 - column) < boat)
{
return 0;
}
else
{
for (j = column; j < (column + boat); j++)
{
if (mat[line][j] == 0)
{
cont++;
}
}
}
}
if (guide == 'V')
{
if ((10 - line) < boat)
{
return 0;
}
else
{
for (i = line; i < (line + boat); i++)
{
if (mat[i][column] == 0)
{
cont++;
}
}
}
}
if (cont == boat)
{
@ -201,12 +218,14 @@ void positionBoat(int mat[10][10], int boat)
if (a >= 0 && a <= 9 && b >= 0 && b <= 9)
{
if (mat[a][b] != boat)
{
mat[a][b] = -1;
}
}
}
}
}
}
if (guide == 'V')
{
@ -223,11 +242,13 @@ void positionBoat(int mat[10][10], int boat)
if (a >= 0 && a <= 9 && b >= 0 && b <= 9)
{
if (mat[a][b] != boat)
{
mat[a][b] = -1;
}
}
}
}
}
else
{
@ -238,6 +259,7 @@ void positionBoat(int mat[10][10], int boat)
if (a >= 0 && a <= 9 && b >= 0 && b <= 9)
{
if (mat[a][b] != boat)
{
mat[a][b] = -1;
}
}
@ -245,10 +267,11 @@ void positionBoat(int mat[10][10], int boat)
}
}
}
}
/**
* @brief Function printMessage
* Responsible for printing the auxiliary message
* @param msg prints msg with board
* @param msg msg with board
*/
void printMessage(char *msg)
{
@ -285,36 +308,54 @@ char printTable(int logic, int stage)
if (stage == 0)
{
if (logic == 0)
{
return '.';
}
else if (logic == -1)
{
return '*';
}
else if (logic == 1)
{
return '1';
}
else if (logic == 2)
{
return '2';
}
else
{
return '3';
}
}
else
{
if (logic == 0 || logic == -1 || logic == 1 || logic == 2 || logic == 3)
{
return '.';
}
else if (logic == -2)
{
return 'x';
}
else if (logic == 10 || logic == 20 || logic == 30)
{
return 'N';
}
else
{
return 'A';
}
}
}
/**
* @brief Function printsTray
* Responsible for printing the visual board for the user
@ -331,16 +372,24 @@ void printsTray(int mat[10][10], int stage)
{
printf("%c", i);
if (i < 74)
{
printf(" ");
}
}
printf("\n");
for (int i = 0; i < 12; i++)
{
if (i > 0 && i < 11)
{
printf("%02d ", i);
}
else
{
printf(" ");
}
for (int j = 0; j < 12; j++)
{
if ((i > 0 && i < 11) && (j > 0 && j < 11))
@ -350,10 +399,15 @@ void printsTray(int mat[10][10], int stage)
printf("%c", imp);
}
else
{
printf("#");
}
if (j < 11)
{
printf(" ");
}
}
printf("\n");
}
}
@ -367,17 +421,25 @@ void printsTray(int mat[10][10], int stage)
void shoot(int mat[10][10], int line, int column)
{
if (mat[line][column] == 0 || mat[line][column] == -1)
{
mat[line][column] = -2;
}
if (mat[line][column] == 1)
else if (mat[line][column] == 1)
{
mat[line][column] = 10;
}
if (mat[line][column] == 2)
else if (mat[line][column] == 2)
{
mat[line][column] = 20;
}
if (mat[line][column] == 3)
else if (mat[line][column] == 3)
{
mat[line][column] = 30;
}
}
/**
* @brief Function calculateScore
* Responsible for calculating the score obtained during the game
@ -401,13 +463,24 @@ int calculateScore(int mat[10][10], int line, int column)
else if (mat[line][column] == 20)
{
if (mat[line + 1][column] == 20)
{
b = 1;
}
if (mat[line - 1][column] == 20)
{
c = 1;
}
if (mat[line][column + 1] == 20)
{
d = 1;
}
if (mat[line][column - 1] == 20)
{
e = 1;
}
if (b == 1)
{
@ -418,8 +491,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 4;
}
else
{
return 0;
}
}
if (c == 1)
{
@ -430,8 +505,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 4;
}
else
{
return 0;
}
}
if (d == 1)
{
@ -442,8 +519,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 4;
}
else
{
return 0;
}
}
if (e == 1)
{
@ -454,20 +533,32 @@ int calculateScore(int mat[10][10], int line, int column)
return 4;
}
else
{
return 0;
}
}
}
else if (mat[line][column] == 30)
{
if (mat[line + 1][column] == 30)
{
b = 1;
}
if (mat[line - 1][column] == 30)
{
c = 1;
}
if (mat[line][column + 1] == 30)
{
d = 1;
}
if (mat[line][column - 1] == 30)
{
e = 1;
}
if (b == 1 && c == 1)
{
@ -479,8 +570,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 7;
}
else
{
return 0;
}
}
else if (d == 1 && e == 1)
{
@ -492,8 +585,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 7;
}
else
{
return 0;
}
}
else if (d == 1)
{
@ -505,8 +600,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 7;
}
else
{
return 0;
}
}
else if (e == 1)
{
@ -518,8 +615,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 7;
}
else
{
return 0;
}
}
else if (c == 1)
{
@ -531,8 +630,10 @@ int calculateScore(int mat[10][10], int line, int column)
return 7;
}
else
{
return 0;
}
}
else if (b == 1)
{
@ -544,9 +645,11 @@ int calculateScore(int mat[10][10], int line, int column)
return 7;
}
else
{
return 0;
}
}
}
return 0;
}
/**
@ -580,26 +683,26 @@ void printPositioning(int Player, int boat, int nm)
{
if (nm == 1)
printMessage(msg1);
if (nm == 2)
else if (nm == 2)
printMessage(msg2);
if (nm == 3)
else if (nm == 3)
printMessage(msg3);
if (nm == 4)
else if (nm == 4)
printMessage(msg4);
if (nm == 5)
else if (nm == 5)
printMessage(msg5);
if (nm == 6)
else if (nm == 6)
printMessage(msg6);
}
else if (boat == 2)
{
if (nm == 1)
printMessage(msg7);
if (nm == 2)
else if (nm == 2)
printMessage(msg8);
if (nm == 3)
else if (nm == 3)
printMessage(msg9);
if (nm == 4)
else if (nm == 4)
printMessage(msg10);
}
else if (boat == 3)
@ -632,33 +735,33 @@ void printPositioning(int Player, int boat, int nm)
{
if (nm == 1)
printMessage(msg1);
if (nm == 2)
else if (nm == 2)
printMessage(msg2);
if (nm == 3)
else if (nm == 3)
printMessage(msg3);
if (nm == 4)
else if (nm == 4)
printMessage(msg4);
if (nm == 5)
else if (nm == 5)
printMessage(msg5);
if (nm == 6)
else if (nm == 6)
printMessage(msg6);
}
if (boat == 2)
else if (boat == 2)
{
if (nm == 1)
printMessage(msg7);
if (nm == 2)
else if (nm == 2)
printMessage(msg8);
if (nm == 3)
else if (nm == 3)
printMessage(msg9);
if (nm == 4)
else if (nm == 4)
printMessage(msg10);
}
if (boat == 3)
else if (boat == 3)
{
if (nm == 1)
printMessage(msg11);
if (nm == 2)
else if (nm == 2)
printMessage(msg12);
}
}