// Dibuat untuk memenuhi tugas dari Bapak Partogi.. YEAHH!! Love it..
// Tiba" waktu sakit dapet pencerahan.. haha..
#include
#include
#include
#include
int angka;
int x1=1;
int y1=1;
struct data{
int x;
int y;
int hrf;
int warna;
struct data *next,*prev;
}*head,*tail,*curr;
void delay()
{
for (int i=0;i<=50000000;i++);
}
void pushhuruf() // Memasukkan koordinat warna dan huruf kedalam linked list
{
int x;
int y;
int hrf=65;
int warna;
srand(time(NULL));
do{
printf("Masukkan angka [3...26] : ");
scanf("%d",&angka);fflush(stdin);
}while(angka<3||angka>26);
clrscr();
for(int i=1;i<=angka;i++)
{
curr=(struct data*)malloc(sizeof(struct data));
x=rand()%80+1;
y=rand()%25+1;
warna=rand()%15;
curr->x = x;
curr->y = y;
curr->hrf = hrf;
hrf++;
curr->warna = warna;
if(head==NULL)
head=tail=curr;
else{
tail->next=curr;
curr->prev=tail;
tail=curr;
}
}
head->prev=tail->next=NULL;
}
void cetak() // mencetak output huruf yang udah masuk linked list
{
curr=head;
while(curr!=NULL)
{
gotoxy(curr->x,curr->y);
textcolor(curr->warna);
cprintf("%c",curr->hrf);
curr=curr->next;
}
}
void pop() //Menghapus Data yang sudah di makan Ular
{
if(x1==head->x && y1==head->y)
{
head=head->next;
free(curr);
curr=head;
//head->prev=NULL;
}
}
void jalan() //Menjalankan ular untuk mencari koordinatnya
{
do
{
//cetak();
curr=head;
if(x1
{
for(int j=x1;j
{
x1++;
gotoxy(x1,y1);
printf(">");
gotoxy(x1-1,y1);
printf(" ");
delay();
printf(" ");
cetak();
}
pop();
}
else if(x1>head->x)
{
for(int j=x1;j>head->x;j--)
{
x1--;
gotoxy(x1,y1);
printf("<");
gotoxy(x1+1,y1);
printf(" ");
delay();
printf(" ");
cetak();
}
pop();
}
if(y1
{
for(int k=y1;k
{
y1++;
gotoxy(x1,y1);
printf("V");
gotoxy(x1,y1-1);
printf(" ");
delay();
printf(" ");
cetak();
}
}
else if(y1>head->y)
{
for(int k=y1;k>head->y;k--)
{
y1--;
gotoxy(x1,y1);
printf("^");
gotoxy(x1,y1+1);
printf(" ");
delay();
printf(" ");
cetak();
}
}
pop();
}while (curr!=NULL);
if(curr==NULL)
{
clrscr();
gotoxy(35,10);
printf("GAME OVER");
}
}
void main()
{
pushhuruf();
jalan();
getchar();
}
Tidak ada komentar:
Posting Komentar