Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. /* Variables info table*/
  2. //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!)
  3. //char p1[35] = player 1's name.
  4. //char p2[35] = player 2's name.
  5. //char p1marker = 'X'
  6. //char p2marker = 'O'
  7. //int row = board row selected by the player
  8. //int column = board column selected by the player
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. void matrixzeroed(char board[3][3]); //Function that zeroes all the positions of the board matrix.
  14. 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.
  15. void skynet(char board[3][3], char p1marker, char p2marker, int row, int column);
  16.  
  17. int main ()
  18. {
  19. char board[3][3], p1[35], p2[] = {"SkyNet"}, p1marker = 'X', p2marker = 'O';
  20. int i,j,row,column, cont;
  21. matrixzeroed(board);
  22. printf ("Type in Player 1's name:");
  23. gets (p1);
  24.  
  25. while(cont < 9){
  26. printf ("\nPlayer 1's name is: %s\t\t Player 2's name is: %s\n\n\t\t\t ", p1, p2);
  27. for (i=0;i<3;i++)
  28. {
  29. printf ("C %d",i+1);
  30. if (i<2) printf ("|");
  31. }
  32. printf ("\n\n");
  33. for (j=0;j<3;j++)
  34. {
  35. printf ("\t\t\tR %d ",j+1);
  36. for (i=0;i<3;i++)
  37. {
  38. printf (" %c ", board[j][i]);
  39. if (i<2) printf ("|");
  40. }
  41. if (j <2) printf("\n\t\t\t ___________\n");
  42. }
  43.  
  44. printf("\n\nIt's your time!\n");
  45. printf("\nType the number of the row that you want to mark: \n");
  46. scanf("%d", &row);
  47. if (row > 3){
  48. while (row > 3){
  49. printf("\nThis position does not exist, please try again: \n");
  50. scanf("%d", &row);
  51. }
  52. }
  53.  
  54. row = row - 1;
  55. printf("\nType the number of the column that you want to mark: \n");
  56. scanf("%d", &column);
  57. if (column > 3){
  58. while (column > 3){
  59. printf("\nThis position does not exist, please try again: \n");
  60. scanf("%d", &column);
  61. }
  62. }
  63. column = column - 1;
  64.  
  65. markboard(board, p1marker, p2marker, row, column);
  66. skynet(board, p1marker, p2marker, row, column);
  67. system("cls");
  68. }
  69. return 0;
  70. }
  71.  
  72. 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.
  73. {
  74. board[0][0] = '.'; board[0][1] = '.'; board[0][2] = '.';
  75. board[1][0] = '.'; board[1][1] = '.'; board[1][2] = '.';
  76. board[2][0] = '.'; board[2][1] = '.'; board[2][2] = '.';
  77. }
  78.  
  79.  
  80. void markboard(char board[3][3], char p1marker, char p2marker, int row, int column)
  81. {
  82.  
  83. if (board[row][column] == '.')
  84. board[row][column] = p1marker;
  85.  
  86. else{
  87. printf("\nThis position is occupied by either X or O, try another position: \n");
  88. printf("\nType the number of the row that you want to mark: \n");
  89. scanf("%d", &row);
  90. row = row -1;
  91. printf("\nType the number of the column that you want to mark: \n");
  92. scanf("%d", &column);
  93. column = column - 1;
  94. markboard(board, p1marker, p2marker, row, column);
  95. }
  96.  
  97. }
  98.  
  99. void skynet(char board[3][3], char p1marker, char p2marker, int row, int column)
  100. {
  101.  
  102.  
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement