Skip to content

Commit 7c895f8

Browse files
committed
Function Coments and text translation to english
1 parent 6aa87bf commit 7c895f8

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

Jogo da Velha/Jogo da Velha.c

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ extern void setupConsole(void);
1111
extern void restoreConsoleMode(void);
1212
extern void restoreConsole(void);
1313

14-
/*verifica se alguém venceu e retorna um array[3]
15-
caso verdade, retorna {1, W, C},
16-
sendo W o tipo de vitória:
17-
0 = Horizontal, 1 = Vertical
18-
2 = Diagonal 1 (\), 3 = Diagonal 2 (/)
19-
sendo C uma coordenada, i para vitória
20-
horizontal e j para o resto */
14+
// Verifyes if someone won and return an array[3]
15+
//if someone won, returns {1, W, C}, being:
16+
// W the win type:
17+
// 0, if horizontal
18+
// 1, if vertical
19+
// 2, if diagonal 1 (\)
20+
// 3, if diagonal 2 (/)
21+
// C the coordinate, being:
22+
// row for horizontal win
23+
// column for the rest
2124
int* winVerifyer(int grid[3][3])
2225
{
2326
static int returnValue[3];
@@ -127,8 +130,8 @@ int* winVerifyer(int grid[3][3])
127130
return returnValue;
128131
}
129132

130-
/*verifica se há até 3 casas livres
131-
e retorna as 3 posições, ou menos*/
133+
// Verifyes if exists 3 or less free cells
134+
// and return the coordinate of these cells
132135
int** freeCells(int grid[3][3])
133136
{
134137
static int freePositions[4][2] = { 0 };
@@ -172,9 +175,7 @@ int** freeCells(int grid[3][3])
172175
return freePositions;
173176
}
174177

175-
176-
/*retem a gridCopy usada na tieVerifyer
177-
para passá-la para a main*/
178+
// gets the tied grid to pass it to main
178179
int** gridTiedReturner(int gridCopy[3][3], int mod)
179180
{
180181
static int gridCopyToReturn[3][3];
@@ -186,9 +187,9 @@ int** gridTiedReturner(int gridCopy[3][3], int mod)
186187
return 0;
187188
}
188189

189-
/*verifica se o jogo vai empatar daqui 3, 2 ou 1 jogada(s)
190-
caso empate, retorna 1
191-
caso não, retorna 0*/
190+
// Verifyes if the game will tie in 3, 2 or 1 plays
191+
// if it ties, returns 1
192+
// if not, returns 0
192193
int tieVerifyer(int grid[3][3], int player, int insertionPreference)
193194
{
194195
static int gridCopy[3][3];
@@ -266,7 +267,7 @@ int tieVerifyer(int grid[3][3], int player, int insertionPreference)
266267
return 1;
267268
}
268269

269-
//converte o posicionamento de 1 a 9 por coordenadas
270+
// Converts the position to coordinates
270271
int* convertToCoordinate(int position)
271272
{
272273
static int coordinate[2];
@@ -319,8 +320,7 @@ int* convertToCoordinate(int position)
319320
return coordinate;
320321
}
321322

322-
//converte as coordenadas da grade para coordenadas da
323-
//super grade
323+
// converts the grid coordinates to supergrid coordinates
324324
int* coordinatesToSupergrid(int coordinates[2])
325325
{
326326
static int supergridCoordinates[2];
@@ -359,7 +359,7 @@ int* coordinatesToSupergrid(int coordinates[2])
359359
return supergridCoordinates;
360360
}
361361

362-
//modifica a super grade, botando X ou O
362+
// Modifies the supergrid, putting X or O
363363
void superGridModifier(char supergrid[31][51], int grid[3][3])
364364
{
365365
int supergridCoordinates[2], gridCoordinates[2];
@@ -409,7 +409,7 @@ void superGridModifier(char supergrid[31][51], int grid[3][3])
409409

410410
}
411411

412-
//imprime a grade
412+
// prints the supergrid
413413
void gridPrinter(int grid[3][3], int mod)
414414
{
415415
static char superGrid[31][51];
@@ -630,7 +630,7 @@ void gridPrinter(int grid[3][3], int mod)
630630
}
631631
}
632632

633-
//imprime os agradecimentos
633+
//print the thanks
634634
void thanks()
635635
{
636636
printf("\nMuito Obrigado por Jogar!\n");
@@ -646,23 +646,22 @@ void thanks()
646646

647647
int main(int argc, char* argv[])
648648
{
649-
static int grid[3][3] = { 0 };
650-
int playCoordinates[2] = { 0 }, playPosition, player;
651-
int insertionPreference, symbolPreference;
652-
int win = 0, tie = 0;
653-
int tieFlag = 0;
654-
int freeCellsReturn[4][2];
655-
char keepPlaying;
656-
char trashcan[10];
649+
static int grid[3][3] = { 0 }; //grid creation
650+
int playCoordinates[2] = { 0 }, playPosition, player; // creates the player interaction
651+
int symbolPreference; // this will be used to determine if the player 1 wants X or O
652+
int win = 0, tie = 0; // win and tie flags
653+
int freeCellsReturn[4][2]; // this will hold the return array of the free cells verifyer function
654+
char keepPlaying; // keep playing flag
655+
char trashcan[10]; //used to freeze the program
657656
keepPlaying = 'x';
658657

659-
printf("Iniciando Jogo da Velha!\n");
658+
printf("Starting Tic Tac Toe\n");
660659
printf("To select a position you use:\n");
661660
gridPrinter(grid, 3);
662661
fgets(trashcan, 5, stdin);
663-
printf("Gostaria de jogar o modo: 1- Singleplyer ou 2- Multiplayer\n");
662+
printf("Would you like to play which mode: 1- Singleplyer or 2- Multiplayer\n");
664663
if (scanf("%i", &player) == 1);
665-
printf("Com qual gostaria de jogar? 1- X ou 2- O\n");
664+
printf("Which you'll play with? 1- X ou 2- O\n");
666665
if (scanf("%i", &symbolPreference) == 2);
667666
if (symbolPreference == 2)
668667
symbolPreference = -1;
@@ -682,7 +681,6 @@ int main(int argc, char* argv[])
682681
gridPrinter(grid, 0);
683682
win = 0;
684683
tie = 0;
685-
tieFlag = 0;
686684
while (win == 0 && tie == 0)
687685
{
688686
setupConsole();
@@ -692,7 +690,7 @@ int main(int argc, char* argv[])
692690
gridPrinter(grid, 2);
693691
if (player == 3)
694692
player = 1;
695-
printf("Jogue, Jogador %i\n", player);
693+
printf("Play, Player %i\n", player);
696694

697695
if(scanf("%i", &playPosition) == 1);
698696
memcpy(playCoordinates, convertToCoordinate(playPosition), sizeof(playCoordinates));
@@ -701,7 +699,7 @@ int main(int argc, char* argv[])
701699
break;
702700
if (grid[playCoordinates[0]][playCoordinates[1]] != 0)
703701
{
704-
printf("\nEssa casa já foi marcada!\n");
702+
printf("\nThis cell is already marked!\n");
705703
if (getchar() != NULL);
706704
continue;
707705
}
@@ -716,7 +714,7 @@ int main(int argc, char* argv[])
716714
moveTo(0, 0);
717715
restoreConsole();
718716
gridPrinter(grid, 5);
719-
printf("\nJogador %i venceu!", player);
717+
printf("\nPlayer %i wins!", player);
720718
win = 1;
721719
break;
722720
}
@@ -727,7 +725,7 @@ int main(int argc, char* argv[])
727725
if (freeCellsReturn[0][0] == 3)
728726
{
729727
gridPrinter(gridTiedReturner(grid, 1), 2);
730-
printf("\nDeu velha...\n");
728+
printf("\nTie...\n");
731729
tie = 1;
732730
break;
733731
}
@@ -736,13 +734,13 @@ int main(int argc, char* argv[])
736734
{
737735
memcpy(grid, gridTiedReturner(grid, 1), sizeof(grid));
738736
gridPrinter(gridTiedReturner(grid, 1), 2);
739-
printf("\nDeu velha...\n");
737+
printf("\nTie...\n");
740738
tie = 1;
741739
break;
742740
}
743741
}
744742
}
745-
printf("\nContinuar Jogando?\n s- Sim n- Não\n");
743+
printf("\nContinue playing?\n y- yes n- no\n");
746744
if(getchar() == '\n');
747745
if (scanf("%c", &keepPlaying) == 1);
748746
player = 0;
@@ -752,7 +750,7 @@ int main(int argc, char* argv[])
752750
if (player == 1)
753751
{
754752
int difficulty;
755-
printf("Selecione sua dificuldade: 1- Fácil, 2- Normal, 3- Impossível\n");
753+
printf("Select your difficulty: 1- Easy, 2- Normal, 3- Impossible\n");
756754
if (scanf(" %i", &difficulty) == 1);
757755
difficulty--;
758756
aiStart(grid, -symbolPreference);
@@ -769,16 +767,18 @@ int main(int argc, char* argv[])
769767
gridPrinter(grid, 0);
770768
win = 0;
771769
tie = 0;
772-
tieFlag = 0;
773770
while (win == 0 && tie == 0)
774771
{
775-
printf("\033[2J"); //funciona como system("clear") ou system("cls");
772+
setupConsole();
773+
clearScreenToTop();
774+
moveTo(0, 0);
775+
restoreConsole();
776776
if (player == 3)
777777
player = 1;
778778
if (player == 1)
779779
{
780780
gridPrinter(grid, 2);
781-
printf("Jogue, Jogador!\n");
781+
printf("Play, Player!\n");
782782

783783
if (scanf("%i", &playPosition) == 1);
784784
memcpy(playCoordinates, convertToCoordinate(playPosition), sizeof(playCoordinates));
@@ -787,7 +787,7 @@ int main(int argc, char* argv[])
787787
break;
788788
if (grid[playCoordinates[0]][playCoordinates[1]] != 0)
789789
{
790-
printf("\nEssa casa já foi marcada!\n");
790+
printf("\nThis cell is already marked!\n");
791791
if (getchar() != NULL);
792792
continue;
793793
}
@@ -797,7 +797,7 @@ int main(int argc, char* argv[])
797797
if (freeCellsReturn[0][0] == 3)
798798
{
799799
gridPrinter(grid, 2);
800-
printf("\nDeu velha...\n");
800+
printf("\nTie...\n");
801801
tie = 1;
802802
break;
803803
}
@@ -811,9 +811,9 @@ int main(int argc, char* argv[])
811811
{
812812
gridPrinter(grid, 5);
813813
if (player == 1)
814-
printf("\nVocê venceu!");
814+
printf("\nYou win!");
815815
if (player == 2)
816-
printf("\nVocê Perdeu!\n");
816+
printf("\nYou lose!\n");
817817
win = 1;
818818
break;
819819
}
@@ -824,7 +824,7 @@ int main(int argc, char* argv[])
824824
if (freeCellsReturn[0][0] == 3)
825825
{
826826
gridPrinter(grid, 2);
827-
printf("\nDeu velha...\n");
827+
printf("\nTie...\n");
828828
tie = 1;
829829
break;
830830
}
@@ -833,13 +833,13 @@ int main(int argc, char* argv[])
833833
{
834834
memcpy(grid, gridTiedReturner(grid, 1), sizeof(grid));
835835
gridPrinter(gridTiedReturner(grid, 1), 2);
836-
printf("\nDeu velha...\n");
836+
printf("\nTie...\n");
837837
tie = 1;
838838
break;
839839
}
840840
}
841841
}
842-
printf("\nContinuar Jogando?\n s- Sim n- Não\n");
842+
printf("\nContine playing?\n y- yes n- no\n");
843843
if (getchar() == '\n');
844844
if (scanf("%c", &keepPlaying) == 1);
845845
}

0 commit comments

Comments
 (0)