#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<string>
#include<conio.h>
using namespace std;
string maps[60][60];
void reset_board(int size);
void draw_board();
void gotoxy(int x,int y);
void move();
void change(int chr);
int board_size;
int x = 2, y = 1;
int main(void)
{
int select_retry;
select_retry = 3;
while(select_retry !=2)
{
cout << " -Map size- " << endl;
cout << "1. Easy(8*8)" << endl;
cout << "2. Nomal(13*13)" << endl;
cout << "3. Hard(19*19)" << endl;
cout << ": ";
select_retry = getchar() - '1';
getchar();
if(select_retry >= 0 && select_retry <= 2)
{
const int board_size[] = {8, 13, 19};
reset_board(board_size[select_retry]);
draw_board();
break;
}
}
while(1)
{
gotoxy(x,y);
printf("[]");
if(_kbhit())
{
move();
}
draw_board();
}
system("pause");
return 0;
}
void reset_board(int size)
{
for(int i = 0; i < 60; ++i)
for(int j = 0; j < 60; ++j)
maps[i][j] = "";
board_size = size;
int i = 0;
int j = 0;
maps[i][j++] = "┏";
for(;j < size * 2 - 1; ++j)
{
maps[i][j++] = "━";
maps[i][j] = "┳";
}
maps[i][++j] = "━";
maps[i++][++j] = "┓";
while(i < size * 2 - 1)
{
j = 0;
maps[i][j++] = "┃";
for(; j < size * 2 - 1; ++j)
{
maps[i][j++] = " ";
maps[i][j] = "┃";
}
maps[i][++j] = " ";
maps[i++][++j] = "┃";
j = 0;
maps[i][j++] = "┣";
for(; j < size * 2 - 1; ++j)
{
maps[i][j++] = "━";
maps[i][j] = "╋";
}
maps[i][++j] = "━";
maps[i++][++j] = "┫";
}
j = 0;
maps[i][j++] = "┃";
for(; j < size * 2 - 1; ++j)
{
maps[i][j++] = " ";
maps[i][j] = "┃";
}
maps[i][++j] = " ";
maps[i++][++j] = "┃";
j = 0;
maps[i][j++] = "┗";
for(; j < size * 2 - 1; ++j)
{
maps[i][j++] = "━";
maps[i][j] = "┻";
}
maps[i][++j] = "━";
maps[i][++j] = "┛";
}
void draw_board()
{
system("cls");
int i, j;
for(i = 0; i < board_size * 2 + 2; ++i)
{
for(j = 0; j < board_size * 2 + 2; ++j)
{
cout << maps[i][j];
}
cout << endl;
}
}
void gotoxy(int x,int y)
{
COORD Pos = {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Pos);
}
void move()
{
int a;
a = getch();
if(a == 0 || a == 224)
{
a = getch();
if(a == 72) //up
{
y -= 2;
if(y < 1) y = 1;
}
if(a == 80) //down
{
y += 2;
if(y > board_size * 2 - 1)
{
y = board_size * 2 - 1;
}
}
if(a == 75) //left
{
x -= 4;
if(x < 1) x = 2;
}
if(a == 77) //right
{
x += 4;
if(x > board_size * 4 - 2)
{
x = board_size * 4 - 2;
}
}
}
else
{
change(a);
}
}
void change(int chr)
{
if(x % 2 == 0 && y%2 == 0 && x < board_size * 4 && y < board_size * 2 && chr == 49)
maps[y - 1][x - 1] = "!!";
if(x % 2 == 0 && y%2 == 0 && x < board_size * 4 && y < board_size * 2 && chr == 50)
maps[y - 1][x - 1] = "??";
if(x % 2 == 0 && y%2 == 0 && x < board_size * 4 && y < board_size * 2 && chr == 51)
maps[y - 1][x - 1] = " ";
}
내가 이때까지 배운 이론들로선 문제가 없는거같은데 왜이러냐
즉 키패드 '1'을 누르면 x y 가 각각 2 2 에 있었다하면 maps[1][1] 칸의 " "가 ㅡ> "!!"로 바껴야하는데
뭐가문제냐
ㅈㅅ 제가 좀 잡다하게배워서 c 언어를 배우고있었는데...ㅋㅋㅋㅋㅋㅋ
내가 만들어준 함수는 왜 안쓰고 예전것 쓰지?
니가 이럴줄 알고 만들어 놓은건데.
그 돌놓는 코드???
응.
그래도 typedef 은 배우기전이라 아는내에서 한번 해보려햇지 근데 아직은 보고배워야 하려나
그 코드에서 typedef 는 정말 아무것도 아닌데. 좌표 변환하는 구조체를 타잎으로 선언해 놓은 것 뿐
아진짜??? 일단 자고 내일 아침에 코드 써놓은거 연구해볼게 오늘 일좀보고오느라 좀 피곤하네
http://dblack.tk
커뮤니티 사이트 입니다 많은 이용 부탁 드립니다.