#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>

void gotoxy(int x, int y);
void draw_board(int cols, int rows);
void move_arrow_key(int key, int *x, int *y, int x_max, int y_max);
void display_stone(int matrix[2][20][20]);

int main(void){
	int x = 1, y = 1;
	int key;
	int matrix[2][20][20] = {0};
	int turn = 0;
	char *stone[2] = {"●", "○"};
	
	while(1){
		system("cls");
		
		draw_board(19, 19);
		display_stone(matrix);
	
		display_stone(matrix);

		int board_x = (x + 1) / 2;

		if(matrix[0][board_x][y] == 0 && matrix[1][board_x][y] == 0){
    		gotoxy(x, y);
    		printf("%s", stone[turn]);
		}
	
		gotoxy(0, 20);
		printf("방향키로 이동 / 스페이스 : 돌 놓기 / ESC 종료");
		
		gotoxy(0,21);
		if(turn == 0)
			printf("현재 차려: 흑돌");
		else
			printf("현재 차려: 백돌");
		
		key = getch();
		
		if(key == 27){
			break;
		}
		else if(key == 32){
			int board_x = (x+1) /2;
			
			if(matrix[0][board_x][y] == 0 && matrix[1][board_x][y] == 0){
				matrix[turn][board_x][y] = 1;
				turn = 1 -turn;
			}
		}
		else if(key == 0 || key == 224){
			
			key = getch();
			move_arrow_key(key, &x, &y, 37, 19);
		}
	}
	
	
	return 0;
}

void gotoxy(int x, int y){
	COORD pos;
	pos.X = x;
	pos.Y = y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

void draw_board(int cols, int rows){
	int i, j;
	
	for(j=1; j<=rows; j++){
		for(i=1; i<= cols; i++){
			gotoxy(i*2-1, j);
			printf("+");
		}
	}
}

void move_arrow_key(int key, int *x, int *y, int x_max, int y_max){
	switch(key){
		case 72:
			if(*y > 0) *y-=1;
			break;
			
		case 80:
			if(*y < y_max) *y+=1;
			break;
			
		case 75:
			if(*x > 0) *x -= 2;
			break;
			
		case 77:
			if(*x < x_max) *x += 2;
			break;
		
//			if(ext == 72 && y>1) y-2;
//			if(ext == 80 && y<25) y+2;
//			if(ext == 75 && x>1) x-2;
//			if(ext == 77 && x<80) x+2;
	}
}

void display_stone(int matrix[2][20][20]){
	int color, x, y;
	char *stone[2] = {"●", "○"};
	for(color=0; color<2; color++){
		for(x=1; x<20; x++){
			for(y=1; y<20; y++){
				if(matrix[color][x][y] == 1){
					gotoxy(x*2-1, y);
					printf("%s", stone[color]);
				}
			}
		}
	}
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: