티스토리 뷰
#define _CRT_SECURE_NO_WARNINGS
#include<windows.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void printboard() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 63);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED);
printf(" ");
printf("\n");
}
void printboard2() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 63);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE);
printf(" ");
printf("\n");
}
COORD boardposition = { 18, 8 };
void print1() {
COORD print1position = { 29, 7 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print1position);
printf("O");
}
void print2() {
COORD print2position = { 39, 7 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print2position);
printf("O");
}
void print3() {
COORD print3position = { 49,7 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print3position);
printf("O");
}
void print4() {
COORD print4position = { 29,12 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print4position);
printf("O");
}
void print5() {
COORD print5position = { 39,12 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print5position);
printf("O");
}
void print6() {
COORD print6position = { 49,12 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print6position);
printf("O");
}
void print7() {
COORD print7position = { 29,17 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print7position);
printf("O");
}
void print8() {
COORD print8position = { 39,17 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print8position);
printf("O");
}
void print9() {
COORD print9position = { 49,17 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), print9position);
printf("O");
}
int main() {
system("mode con cols=80 lines=25");
system("color 3F");
int input = 0;
int columns = 80;
int rows = 25;
char title[] = "###TIC-TAC-TOC GAME###";
int titlelength = strlen(title);
COORD titleposition = { (80 - titlelength) / 2,2 };
printf("%d", (80 - titlelength) / 2);
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), titleposition);
printf("%s\n\n\n", title);
for (int i = 0; i < 5; i++) {
printboard();
}
for (int i = 0; i < 5; i++) {
printboard2();
}
for (int i = 0; i < 5; i++) {
printboard();
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 63);
printf("Press Enter to Start");
if (getc(stdin) == '\n') {
printf("Let's Start!");
}
system("cls");
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), titleposition);
printf("%s\n\n\n", title);
for (int i = 0; i < 5; i++) {
printboard();
}
for (int i = 0; i < 5; i++) {
printboard2();
}
for (int i = 0; i < 5; i++) {
printboard();
}
printf("원하는 칸 번호를 입력해 주세요");
scanf("%d", &input);
switch (input) {
case 1: print1();
break;
case 2: print2(); break;
case 3: print3(); break;
case 4: print4(); break;
case 5: print5(); break;
case 6: print6(); break;
case 7: print7(); break;
case 8: print8(); break;
case 9: print9(); break;
}
system("pause");
return 0;
}
'PL > C' 카테고리의 다른 글
[C] for문의 동작 순서 (0) | 2019.05.31 |
---|---|
[C언어] C언어로 전화번호부 만들기 (0) | 2018.11.05 |
typedef 쓰기 (0) | 2018.10.05 |
구조체 (0) | 2018.10.05 |
[C Language] 문자열 정리 (0) | 2018.09.21 |