Rick Clark
Posted in reply to Rick Clark
| Here is the silly little C program I am trying to convert to D. The console functions are what I am after: positon the cursor in the console, write different colors and clear the console screen. These might already be in the language, but I couldn't find them.
Thanks!
Rick Clark
// *************************************************************
// Original Program by Kevin Diggins
// *************************************************************
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
COORD cursor;
HANDLE hConsole;
int color_fg = 7;
int color_bg = 0;
static char A[2048];
static char B[2048];
static char C[2048];
void cls(void);
void color (int fg, int bg);
void locate (int row,int col,int show);
void Dance (char *A, char *B, char *C, int Dlay );
int main(void)
{
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
cls();
color (3,0);
locate (6,23,0);
printf("%s\n","The Ascii Macarena Dance");
while(1)
{
color (9,0 );
locate (8,26,0);
printf("%s\n","Press Any Key to Quit");
Sleep(500);
// ---------- Step One ------------
strcpy(A," o ");
strcpy(B,"^|\\");
strcpy(C," /\\");
Dance(A,B,C,3);
// --------- Step Two --------------
strcpy(A," o ");
strcpy(B,"^|^");
strcpy(C," >\\");
Dance(A,B,C,4);
// --------- Step Three -------------
strcpy(A," o ");
strcpy(B,"v|^");
strcpy(C,"/< ");
Dance(A,B,C,5);
// --------- Step Four ---------------
strcpy(A," o ");
strcpy(B,"v|^");
strcpy(C," >\\");
Dance(A,B,C,4);
// --------- Step Five ----------------
strcpy(A," o ");
strcpy(B,"|/^");
strcpy(C,"/< ");
Dance(A,B,C,3);
// ---------- Step Six -----------------
strcpy(A," o ");
strcpy(B,"|-|");
strcpy(C," >\\");
Dance(A,B,C,4);
// ----------- Step Seven ---------------
strcpy(A," <o ");
strcpy(B,"//| ");
strcpy(C,"/< ");
Dance(A,B,C,5);
// ----------- Step Eight -----------------
strcpy(A,"<o> ");
strcpy(B," | ");
strcpy(C," >//");
Dance(A,B,C,4);
// ----------- Step Nine ------------------
strcpy(A," o> ");
strcpy(B," // ");
strcpy(C,"/< ");
Dance(A,B,C,3);
// ----------- Step Ten ------------------
strcpy(A," o ");
strcpy(B," x ");
strcpy(C," >\\");
Dance(A,B,C,4);
// ----------- Step Eleven ---------------
strcpy(A," o ");
strcpy(B,"</ ");
strcpy(C,"/< ");
Dance(A,B,C,5);
// ----------- Step Twelve ------------------
strcpy(A," o ");
strcpy(B,"<|>");
strcpy(C," >\\");
Dance(A,B,C,4);
// ----------- Step Thirteen ----------------
strcpy(A," o ");
strcpy(B,"</>");
strcpy(C,"/< ");
Dance(A,B,C,3);
// ----------- Step Fourteen ---------------
strcpy(A," o ");
strcpy(B,"<\\>");
strcpy(C," >\\");
Dance(A,B,C,4);
// ----------- Step Fifteen ---------------
strcpy(A," o ");
strcpy(B,"<)>");
strcpy(C," >>");
Dance(A,B,C,4);
// ----------- Step Sixteen ----------------
strcpy(A," o ");
strcpy(B," )\\");
strcpy(C," LL");
Dance(A,B,C,5);
}
return 0;
}
void locate (int row,int col,int show)
{
CONSOLE_CURSOR_INFO cci;
cursor.X = col-1;
cursor.Y = row-1;
SetConsoleCursorPosition(hConsole,cursor);
cci.bVisible = show;
SetConsoleCursorInfo(hConsole,&cci);
}
void cls (void)
{
DWORD ret;
register int attr;
cursor.X = 0;
cursor.Y = 0;
FillConsoleOutputCharacter(hConsole,32,4000,cursor,&ret);
attr = color_fg + color_bg * 16;
FillConsoleOutputAttribute (hConsole,attr,4000,cursor,&ret);
locate(1,1,1);
}
void color (int fg, int bg)
{
SetConsoleTextAttribute (hConsole,fg+bg*16);
color_fg = fg;
color_bg = bg;
}
void Dance (char *A, char *B, char *C, int Dlay)
{
static int Kolor;
memset(&Kolor,0,sizeof(Kolor));
if(kbhit())
{
locate (1,1,1);
color (7,0 );
cls();
fflush(stdout);
ExitProcess(0);
}
color (4,0 );
color (6,0 );
locate (12,33,0);
printf("%s\n",A);
color (4,0 );
locate (13,33,0);
printf("%s\n",B);
color (9,0 );
locate (14,33,0);
printf("%s\n",C);
Sleep(Dlay*100);
locate (24,12,0);
Kolor+=1;
if(Kolor==0)
{
Kolor++;
}
if(Kolor==15)
{
Kolor=1;
}
color (15,0 );
locate (8,26,0);
printf("%s\n","Press Any Key to Quit");
}
|