#include<math.h>
#include<time.h>
#include<window
#define SIZE 12s.h>
#include<conio.h>
int x, y; // circle 위치 - 먹이
int i=3,j=3; // 플레이어 좌표
int cnt=0;// 움직인횟수
int s=0; //점수
int max = 0; //최대점수
char name[100]; //player name
char map[100][100]= {};
INPUT_RECORD rec;
DWORD dwNOER;
HANDLE CIN = 0;
void gotoxy2(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void gotoxy(int x,int y){
COORD pos= {y*3,x*2};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void printmap(){
system("cls");
setColor(3);
for(int k=0; k<SIZE; k++)
{
for(int l=0; l<SIZE; l++)
{
gotoxy(k,l);
if(k==0||k==SIZE-1||l==0||l==SIZE-1)
printf("☆");
else
printf(" ");
}
printf("\n");
}
setColor(11);
view();
}
void printCircle(){
gotoxy(x,y);
printf("○");
}
void makeCircle(){
x = rand()%(SIZE-2)+1;// 1부터 11까지 랜덤 수
y = rand()%(SIZE-2)+1;
}
void view(){ //오른쪽 정보 출력 판
gotoxy(1, 14);
printf("Player Name: %s", name);
gotoxy(3,14);
printf("게임 설명");
gotoxy(4,14);
printf("다섯번 마다 아이템의 위치가 바뀝니다!");
gotoxy(5,14);
printf("시작은 2, 2부터이고 벽에 닿으면 탈락입니다!");
gotoxy(7,14);
printf("목표물의 위치 x : %2d y : %2d",x,y);
gotoxy(8,14);
printf("플레이어의 위치 i : %2d j : %2d",i,j);
gotoxy(10,14);
printf("점수: %d", s);
gotoxy(11,14);
printf("최고 점수: %d", max);
gotoxy(i,j);
printf("■");
}
enum{
BLACK,
DARK_BLUE,
DARK_GREEN,
DARK_SKYBLUE,
DARK_RED,
DARK_VOILET,
DARK_YELLOW,
GRAY,
DARK_GRAY,
BLUE,
GREEN,
SKYBLUE,
RED,
VIOLET,
YELLOW,
WHITE,
};
void start_print(){
int i;
setColor(RED);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
Sleep(120);
system("cls");
setColor(DARK_YELLOW);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
Sleep(120);
system("cls");
setColor(GREEN);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
Sleep(120);
system("cls");
setColor(DARK_SKYBLUE);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
Sleep(120);
system("cls");
setColor(DARK_BLUE);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
Sleep(120);
system("cls");
setColor(VIOLET);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
Sleep(120);
system("cls");
setColor(DARK_RED);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
Sleep(120);
system("cls");
}
void setColor(unsigned short text){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), text);
}
void click(int *xx, int *yy, int *lr){
while (1)
{
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &rec, 1, &dwNOER); // 콘솔창 입력을 받아들임.
if (rec.EventType == MOUSE_EVENT) // 마우스 이벤트일 경우
{
if (rec.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED) // 좌측 버튼이 클릭되었을 경우
{
int mouse_x = rec.Event.MouseEvent.dwMousePosition.X; // X값 받아옴
int mouse_y = rec.Event.MouseEvent.dwMousePosition.Y; // Y값 받아옴
*xx=mouse_x; //x값을 넘김
*yy=mouse_y; //y값을 넘김
*lr=1; //마우스 클릭상태를 넘김
break;
}
else if(rec.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED) // 우측 버튼이 클릭되었을 경우
{
int mouse_x = rec.Event.MouseEvent.dwMousePosition.X; // X값 받아옴
int mouse_y = rec.Event.MouseEvent.dwMousePosition.Y; // Y값 받아옴
*xx=mouse_x; //x값을 넘김
*yy=mouse_y; //y값을 넘김
*lr=2; //마우스 클릭상태를 넘김
break;
}
}
}
}
void clearconsole(){
COORD Coor = { 0, 0 };
DWORD dw;
FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), ' ', 100000000 * 100000000, Coor, &dw); // 콘솔창 화면을 지운다.
}
void drawbutton(){
gotoxy2(227, 1);
printf("XXX\n");
gotoxy2(227, 2);
printf("XXX\n");
gotoxy2(227, 3);
printf("XXX");
}
void drawpen(){
for(int i=1; i<=30; i+=3)
{
if(i==1)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12);
if(i==4)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),14);
if(i==7)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
if(i==10)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11);
if(i==13)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),9);
if(i==16)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),13);
if(i==19)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),8);
if(i==22)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
if(i==25)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),3);
if(i==28)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),6);
gotoxy2(i, 58);
printf("▲\n");
gotoxy2(i, 59);
printf("□\n");
gotoxy2(i, 60);
printf("□\n");
}
setColor(15);
gotoxy2(31, 58);
printf("□\n");
setColor(7);
gotoxy2(31, 59);
printf("■\n");
setColor(15);
gotoxy2(31, 60);
printf("□\n");
}
void changeshape(){
setColor(12);
gotoxy2(162, 59);
printf("♥");
setColor(11);
gotoxy2(165, 59);
printf("♠");
setColor(10);
gotoxy2(168, 59);
printf("♣");
}
int shape=0;
INPUT_RECORD rec;
DWORD dwNOER;
int main()
{
int a;
printf("게임은 1, 그림판은 2를 눌러주세요 >> ");
scanf("%d", &a);
if(a==1)
{
srand(time(NULL));
char c;
system("mode con:cols=100 lines=25");
start_print();
setColor(WHITE);
gotoxy(6, 9);
printf("이름을 입력하세요>> ");
scanf("%s", name);
system("cls");
start:
cnt=0;
s=0;
i=3;
j=3;
view();
printmap();
while(1)
{
if (_kbhit()) //키보드 입력 확인 (true / false)
{
c= _getch();
if(c==32) //space 입력시
{
gotoxy(9,14 );
printf("space가 입력되었습니다.");
}
if (c == -32) // 방향키 입력시
{
cnt++;
c = _getch();
if(c==72&&i>0)
i--;//UP
else if(c==75&&j>0)
j--;// LEFT
else if(c==77&&j<=SIZE-2)
j++;// RIGHT
else if(c==80&&i<=SIZE-2)
i++; // DOWN
printmap();
setColor(11);
gotoxy(i,j);
printf("■");
}
if(cnt%5==0) makeCircle();
if(cnt>=5) printCircle();
if(i==0||j==0||i==SIZE-1||j==SIZE-1)
{
system("cls");
gotoxy(0, 0);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_INTENSITY);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_INTENSITY | BACKGROUND_GREEN);
printf("□□□■■■■■□□□□□□□■□□□□□□□■□□□□□■□□□□■■■■■■□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_GREEN | BACKGROUND_INTENSITY);
printf("□□■□□□□□■□□□□□■□■□□□□□□■■□□□■■□□□□■□□□□□□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE | BACKGROUND_INTENSITY | BACKGROUND_GREEN);
printf("□□■□□□□□□□□□□■□□□■□□□□□■□■□■□■□□□□■■■■□□□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE | BACKGROUND_INTENSITY);
printf("□□■□□■■■■□□□■■■■■■■□□□□■□□■□□■□□□□■□□□□□□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_INTENSITY | BACKGROUND_BLUE);
printf("□□■□□□□□■□□□■□□□□□■□□□□■□□□□□■□□□□■□□□□□□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_BLUE);
printf("□□□■■■■■□□□□■□□□□□■□□□□■□□□□□■□□□□■■■■■■□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_INTENSITY | BACKGROUND_BLUE);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_BLUE);
printf("□□□□□□□■■■■■□□□□■□□□□□□□□□■□□□□■■■■■■□□□□■■■■■□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_INTENSITY | BACKGROUND_BLUE);
printf("□□□□□□■□□□□□□■□□□■□□□□□□□■□□□□□■□□□□□□□□□■□□□□■□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE | BACKGROUND_INTENSITY);
printf("□□□□□■□□□□□□□■□□□□■□□□□□■□□□□□□■■■■□□□□□□■■■■■□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE | BACKGROUND_INTENSITY | BACKGROUND_GREEN);
printf("□□□□□■□□□□□□□■□□□□□■□□□■□□□□□□□■□□□□□□□□□■■■□□□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_GREEN | BACKGROUND_INTENSITY);
printf("□□□□□□■□□□□□■□□□□□□□■□■□□□□□□□□■□□□□□□□□□■□□■■□□□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_INTENSITY | BACKGROUND_GREEN);
printf("□□□□□□□■■■■■□□□□□□□□□■□□□□□□□□□■■■■■■□□□□■□□□□□■□□\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_INTENSITY);
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("다시 시작하려면 1, 그만하려면 2를 눌러주세요>> ");
int a;
scanf("%d", &a);
if(a==1)
{
system("cls");
goto start;
}
else if(a==2)
{
break;
}
else
{
printf("1이나 2가 아닙니다. 프로그램을 종료합니다.");
break;
}
}
if(i==x&&j==y) {
s++;
gotoxy(2 , 25);
setColor(RED);
printf("♥");
}
if(max<s) max = s;
view();
}
}
}
//////////////////////////////////////////////////////////////////////////////////
if(a==2)
{
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
//마우스 입력모드로 바꿈
system("mode con cols=700 lines=700");
DWORD CIN;
DWORD mode;
CIN = GetStdHandle(STD_INPUT_HANDLE); //마우스 재활성화
GetConsoleMode(CIN, &mode);
SetConsoleMode(CIN, mode | ENABLE_MOUSE_INPUT);
drawbutton();
drawpen();
changeshape();
int xx,yy,lr,X;
int f=0;
while (1)
{
click(&xx, &yy, &lr);
// gotoxy(xx,yy);
// printf("%2d %2d",xx,yy);
if(xx==227&&(1<=yy && yy<=3)) // 삭제버튼
{
clearconsole();
drawbutton();
drawpen();
changeshape();
}
else if(xx==1&&(58<=yy && yy<=60))
{
setColor(12);
gotoxy2(39, 59);
setColor(12);
printf("빨간색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==4&&(58<=yy && yy<=60))
{
setColor(14);
gotoxy2(39, 59);
setColor(14);
printf("노란색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==7&&(58<=yy && yy<=60))
{
setColor(10);
gotoxy2(39, 59);
setColor(10);
printf("초록색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==10&&(58<=yy && yy<=60))
{
setColor(11);
gotoxy2(39, 59);
setColor(11);
printf("하늘색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==13&&(58<=yy && yy<=60))
{
setColor(9);
gotoxy2(39, 59);
setColor(9);
printf("남색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==16&&(58<=yy && yy<=60))
{
setColor(13);
gotoxy2(39, 59);
setColor(13);
printf("보라색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==19&&(58<=yy && yy<=60))
{
setColor(8);
gotoxy2(39, 59);
setColor(8);
printf("회색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==22&&(58<=yy && yy<=60))
{
setColor(15);
gotoxy2(39, 59);
setColor(15);
printf("하얀색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==25&&(58<=yy && yy<=60))
{
setColor(3);
gotoxy2(39, 59);
setColor(3);
printf("파란색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==28&&(58<=yy && yy<=60))
{
setColor(6);
gotoxy2(39, 59);
setColor(6);
printf("황토색으로 바뀌었습니다!");
Sleep(2000);
}
else if(xx==162&&yy==59)
{
setColor(12);
gotoxy2(39, 59);
printf("하트 모양으로 바뀌었습니다!");
shape= 1 ;
}
else if(xx==165&&yy==59)
{
setColor(11);
gotoxy2(39, 59);
printf("카드 모양으로 바뀌었습니다!");
shape = 2;
}
else if(xx==168&&yy==59)
{
setColor(10);
gotoxy2(39, 59);
printf("클로버 모양으로 바뀌었습니다!");
shape = 3;
}
else if(xx==31&&(58<=yy && yy<=60))
{
gotoxy2(39, 59);
printf("지우개로 바뀌었습니다!");
shape = 4;
}
else if((1<=xx && xx<=35)&&(56<=yy && yy<=63))
{
}
else if((226<=xx && xx<=230)&&(0<=yy && yy<=5))
{
}
else if((159<=xx && xx<=172)&&(58<=yy && yy<=60))
{
}
else // 선택된 모양 그리기
{
gotoxy2(xx,yy);
if(shape==1)
printf("♥");
else if(shape==2)
printf("♠");
else if(shape==3)
printf("♣");
else if(shape==4)
printf(" ");
}
}
}
}