You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.0 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5. #include "ticTacToe.h"
  6. void printPrompt(){
  7. printf("Let's play Tic Tac Toe. You will use O, I will use X.\nJust enter the number of the field you choose as row col.\nYou start.\n");
  8. }
  9. void printField(char field[3][3]){
  10. for (int i = 0; i < 3; i++){
  11. for (int j = 0; j < 3; j++){
  12. printf("%c", field[i][j]);
  13. if (j < 2) {
  14. printf("|");
  15. }
  16. }
  17. printf("\n");
  18. }
  19. }
  20. void initField(char field[3][3]) {
  21. for (int i = 0; i < 3; i++) {
  22. for (int j = 0; j < 3; j++) {
  23. field[i][j] = '-';
  24. }
  25. }
  26. }
  27. void getPlayerInput(char field[3][3]){
  28. int row, col;
  29. printf("Enter the field as row col: ");
  30. scanf("%d %d", &row, &col);
  31. row -= 1;
  32. col -= 1;
  33. field[row][col] = 'O';
  34. }
  35. bool validateUserInput(int row, int col){
  36. if (row < 3 && row >= 0){
  37. if (col < 3 && col >= 0){
  38. return true;
  39. }
  40. }
  41. return false;
  42. }