/*
#include<stdio.h>
#include <string.h>
#define SIZE 5
int queue[SIZE]= {};
int front=0, rear=0;
void enqueue(int data)
{
rear=(rear+1)%SIZE;
queue[rear]=data;
}
int dequeue()
{
if(rear != front)
{
front=(front+1)%SIZE;
return queue[front];
}
}
int main()
{
int a, b, c;
int sum=0;
while(1)
{
printf("1. enqueue \ 2. dequeue \ 3. view \ 4. stop >> ");
scanf("%d",&a);
if(a==1)
{
if((rear+1)%SIZE==front)
{
printf("큐 저장량이 꽉 찼습니다 enqueue 불가능!!\n");
continue;
}
printf("enqueue할 데이터를 입력하세요 >> ");
scanf("%d",&b);
enqueue(b);
}
else if(a==2)
{
if(rear==front)
{
printf("큐가 비었습니다! dequeue 불가능!\n");
continue;
}
{
dequeue();
}
}
else if(a==4)
{
printf("exit 키를 눌렀습니다. 창을 닫습니다.");
break;
}
else
{
printf("queue >> ");
for(int i=0; i<SIZE; i++){
if(i==front) printf("X ");
else printf("%d ",queue[i]);
}
printf("\n front : %d rear : %d\n",front,rear);
}
}
}
*/
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
#define SIZE 12
int x, y; // circle 위치
char map[100][100]={};
void gotoxy(int x,int y)
{
COORD pos= {y*3,x*2};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void setColor(unsigned short text) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), text);
}
void printmap(){
//system("cls");
setColor(6);
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);
}
void printCircle(){
gotoxy(x,y);
printf("○");
gotoxy(7,14);
printf("x : %d y : %d",x,y);
}
void makeCircle(){
x = rand()%(SIZE-2)+1;// 1부터 11까지 랜덤 수
y = rand()%(SIZE-2)+1;
}
void view(){
gotoxy(3,14);
printf("게임 설명");
gotoxy(4,14);
printf("다섯번 마다 아이템의 위치가 바뀝니다!");
}
void start_print(){
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□\n");
printf("□□■■■□□□□□■□□□□■□□□■□□■■■■□\n");
printf("□■□□□□□□□■□■□□□■■□■■□□■□□□□\n");
printf("□■□□■■□□■□□□■□□■□■□■□□■■■□□\n");
printf("□■□□□■□□■■■■■□□■□□□■□□■□□□□\n");
printf("□□■■■□□□■□□□■□□■□□□■□□■■■■□\n");
printf("□□□□□□□□□□□□□□□□□□□□□□□□□□□");
gotoxy(10,40);
Sleep(500);
system("cls");
}
enum {
BLACK,
DARK_BLUE,
DARK_GREEN,
DARK_SKYBLUE,
DARK_RED,
DARK_VOILET,
DAKR_YELLOW,
GRAY,
DARK_GRAY,
BLUE,
GREEN,
SKYBLUE,
RED,
VIOLET,
YELLOW,
WHITE,
};
int main()
{
srand(time(NULL));
char c;
int i=1,j=1; // 플레이어 좌표
system("mode con:cols=80 lines=25");
int cnt=0;
int s=0;
int max = 0;
start_print();
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>1) i--;//UP
else if(c==75&&j>1) j--;// LEFT
else if(c==77&&j<SIZE-2) j++;// RIGHT
else if(c==80&&i<SIZE-2) i++; // DOWN
printmap();
gotoxy(i,j);
setColor(5);
printf("■");
}
if(cnt%5==0){
makeCircle();
}
if(cnt>=5) printCircle();
view();
if(i==x&&j==y) //
{
s++;
gotoxy(10,14); printf("점수: %d", s);
}
if(max<s)
{
max = s;
gotoxy(11,14); printf("최고 점수: %d", max);
}
}
}
}