#include <stdio.h>
#include<math.h>
#include <time.h>
#include <windows.h>
#include<conio.h>
void gotoxy(int x,int y)
{
COORD pos = {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void setColor(unsigned short text,unsigned short back)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),text|(back<<4));
}
int main()
{
int la,lb,l=0,i,o,map[101][101],p[9]= {0,4,4,4,4,1,1,1,1},t,w,ll,u=0;
srand (time(0));
for(i=1; i<=20; i++)
{
for(o=1; o<=10; o++)
{
gotoxy(i+40,o+5);
if(i%4!=0&&o%5!=0||i<4)
{
printf(" ");
map[i][o]=0;
}
if(i%4==0)
{
printf("|");
map[i][o]=9;
}
if(o%5==0)
{
printf("*");
map[i][o]=9;
}
}
}
for(i=2; i<=5; i++)
{
for(o=1; o<=4; o++)
{
p[o-1]=4;
gotoxy((i*4-3)+40,o+5);
setColor(o,o);
map[i*4-2][o]=o;
printf(" %d ",o);
}
}
setColor(2,0);
gotoxy(0,3);
for(o=1; o<=10; o++)
{
for(i=1; i<=20; i++)
{
if(map[i][o]>0&&map[i][o]<5)
{
setColor(map[i][o],map[i][o]);
printf("%d",map[i][o]);
}
else
{
setColor(2,0);
printf("%d",map[i][o]);
}
}
printf("\n");
}
for(;;)
{
gotoxy(40,20);
printf(" ");
gotoxy(40,20);
printf("기존유리병 =");
scanf("%d",&la);
gotoxy(55,20);
printf("옮길 유리병 =");
scanf("%d",&lb);
setColor(2,0);
gotoxy(1,1);
if(p[lb]<4&&p[la]>0)
{
if(la>4)
{
la=la-4;
u=1;
}
else
{
u=0;
}
if(u==1)
{
gotoxy((la*4-3)+44,15-p[la+4]);
l=map[la*4-2+4][10-p[la+4]];
map[la*4-2+4][10-p[la+4]]=0;
}
else
{
gotoxy((la*4-3)+44,10-p[la]);
l=map[la*4-2+4][5-p[la]];
map[la*4-2][5-p[la]]=0;
}
printf(" ");
p[la]--;
if(lb>4)
{
lb=lb-4;
gotoxy((lb*4-3)+44,15-p[lb+4]);
map[lb*4-2+4][5-p[lb+4]]=l;
}
else
{
gotoxy((lb*4-3)+44,10-p[lb]);
map[lb*4-2+4][5-p[lb]]=l;
}
setColor(l,l);
printf("eee");
p[lb+4]++;
setColor(2,0);
printf("[%d]",l);
}
}
return 0;
}