-
Notifications
You must be signed in to change notification settings - Fork 2
/
gamesetting.c
119 lines (107 loc) · 2.44 KB
/
gamesetting.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <Windows.h>
#include <stdio.h>
#include "declaration.h"
#include "gamesetting.h"
#pragma warning (disable:4996)
extern const int PLAYER1_TURN;
extern const int PLAYER2_TURN;
extern const int SUCCESS;
extern const int FAILURE;
extern Player_Info player1;
extern Player_Info player2;
char checkSymbol(int current_player)
{
if (current_player == PLAYER1_TURN)
{
return player1.symbol;
}
else
{
return player2.symbol;
}
}
void checkTurn(int current_player)
{
if (current_player == PLAYER1_TURN)
{
printf("%s Type any digit from 1-9 to fill your response:- ", player1.name);
}
else
{
printf("%s Type any digit from 1-9 to fill your response:- ", player2.name);
}
}
void chooseSymbol(void)
{
const int CORRECT = 1;
const int INCORRECT = 0;
char get_symbol[10];
int menu_input = INCORRECT;
int right_input;
while (menu_input == INCORRECT)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("\n\n\t%s choose the X or O:", player1.name);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
scanf("%s", get_symbol);
right_input = setSymbol(get_symbol);
if (right_input)
{
menu_input = CORRECT;
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
printf("\n\tPlease enter either X or O only \n\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
menu_input = INCORRECT;
}
}
}
/* 대문자, 소문자 모두 입력을 허락함 */
int isRightInput(char* player_symbol, char* capital_letter, char* small_letter)
{
int string_same;
string_same = strcmp(player_symbol, capital_letter);
if (string_same == 0)
{
return SUCCESS;
}
string_same = strcmp(player_symbol, small_letter);
if (string_same == 0)
{
return SUCCESS;
}
return FAILURE;
}
int setSymbol(char* player1_symbol)
{
int is_player_symbol;
is_player_symbol = isRightInput(player1_symbol, "X", "x");
if (is_player_symbol)
{
player1.symbol = 'X';
player2.symbol = 'O';
return SUCCESS;
}
is_player_symbol = isRightInput(player1_symbol, "O", "o");
if (is_player_symbol)
{
player1.symbol = 'O';
player2.symbol = 'X';
return SUCCESS;
}
return FAILURE;
}
/* 플레이어가 번갈아 가며 게임을 진행한다 */
int changePlayer(int current_player)
{
if (current_player == PLAYER1_TURN)
{
return PLAYER2_TURN;
}
else
{
return PLAYER1_TURN;
}
}