Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Variables info table*/
- //char board[3][3] = the game board (!has to be printed as a string rather than a char, or else the p1marker and p2marker chars will not be printed correctly!)
- //char p1[35] = player 1's name.
- //char p2[35] = player 2's name.
- //char p1marker = 'X'
- //char p2marker = 'O'
- //int row = board row selected by the player
- //int column = board column selected by the player
- #include <stdio.h>
- #include <stdlib.h>
- void matrixzeroed(char board[3][3]); //Function that zeroes all the positions of the board matrix.
- void markboard(char board[3][3], char p1marker, char p2marker, int row, int column);// This one checks whether or not the position chosen by the player has already been marked, if not, marks that position with his marker.
- void skynet(char board[3][3], char p1marker, char p2marker, int row, int column);
- int main ()
- {
- char board[3][3], p1[35], p2[] = {"SkyNet"}, p1marker = 'X', p2marker = 'O';
- int i,j,row,column, cont;
- matrixzeroed(board);
- printf ("Type in Player 1's name:");
- gets (p1);
- while(cont < 9){
- printf ("\nPlayer 1's name is: %s\t\t Player 2's name is: %s\n\n\t\t\t ", p1, p2);
- for (i=0;i<3;i++)
- {
- printf ("C %d",i+1);
- if (i<2) printf ("|");
- }
- printf ("\n\n");
- for (j=0;j<3;j++)
- {
- printf ("\t\t\tR %d ",j+1);
- for (i=0;i<3;i++)
- {
- printf (" %c ", board[j][i]);
- if (i<2) printf ("|");
- }
- if (j <2) printf("\n\t\t\t ___________\n");
- }
- printf("\n\nIt's your time!\n");
- printf("\nType the number of the row that you want to mark: \n");
- scanf("%d", &row);
- if (row > 3){
- while (row > 3){
- printf("\nThis position does not exist, please try again: \n");
- scanf("%d", &row);
- }
- }
- row = row - 1;
- printf("\nType the number of the column that you want to mark: \n");
- scanf("%d", &column);
- if (column > 3){
- while (column > 3){
- printf("\nThis position does not exist, please try again: \n");
- scanf("%d", &column);
- }
- }
- column = column - 1;
- markboard(board, p1marker, p2marker, row, column);
- skynet(board, p1marker, p2marker, row, column);
- system("cls");
- }
- return 0;
- }
- void matrixzeroed(char board[3][3]) // The cleaning order has been organized to better resemble the look of the board, making it easier to understand the code.
- {
- board[0][0] = '.'; board[0][1] = '.'; board[0][2] = '.';
- board[1][0] = '.'; board[1][1] = '.'; board[1][2] = '.';
- board[2][0] = '.'; board[2][1] = '.'; board[2][2] = '.';
- }
- void markboard(char board[3][3], char p1marker, char p2marker, int row, int column)
- {
- if (board[row][column] == '.')
- board[row][column] = p1marker;
- else{
- printf("\nThis position is occupied by either X or O, try another position: \n");
- printf("\nType the number of the row that you want to mark: \n");
- scanf("%d", &row);
- row = row -1;
- printf("\nType the number of the column that you want to mark: \n");
- scanf("%d", &column);
- column = column - 1;
- markboard(board, p1marker, p2marker, row, column);
- }
- }
- void skynet(char board[3][3], char p1marker, char p2marker, int row, int column)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement