Code:
#include <stdio.h>
#include <time.h>
#include <windows.h>
#define MAX 25
#define LASTY 30 //separates words from the skyline below
//LASTY, words should destroy the skyline they contact.
#define VRT 179
#define HRZ 196
#define TLC 218
#define TRC 191
#define BLC 192
#define BRC 217
#define LHC 180
#define RHC 195
void menu(char *words[MAX]);
void Gotoxy(short x, short y);
int skyline(void);
int main() {
char *words[MAX]={
"Golf","Bravo","Kilo","Alfa","Delta",
"Echo","India","Whiskey","Romeo","Tango",
"Zulu","Juliet","Mike","Sierra","Victor",
"Hotel","Lima","Quebec","Papa","Tango",
"X-Ray","Oscar","Uniform","Charlie","Foxtrot"
};
menu(words);
printf("\n");
return 0;
}
/* corners are numbers 1--A--2
| | |
E: straight D--F--B
connector | | |
4--C--3
T's: A-E, 4-Way: F
Lay out the skyline you want in the char array s[] below. Refer to the above
diagram to use the right char. The switch statement will transfer these one
char "drawing" chars, into one of the defines at the top of the program.
*/
int skyline(void) {
int i,j,x=1,y=LASTY+1;
unsigned char s[7][78]=
{
{" "},
{" 1--2 1--2 1---2 1--2 "},
{" | | 1---2 1--B | | | | | 1-2 "},
{" D--B 1--B | | | | 1---B | | | | | "},
{" | | | | | | | | | | | | | | | "},
{" | | | | | | | | | | | | | | | "},
{" | 4-3 | 4--3 | 4--3 | 4-3 4-3 | "}
};
for(i=0;i<7;i++) {
for(j=0;j<78;j++) {
switch(s[i][j]) {
case '1': s[i][j]=TLC; break;
case '2': s[i][j]=TRC; break;
case '3': s[i][j]=BRC; break;
case '4': s[i][j]=BLC; break;
case 'B': s[i][j]=LHC; break;
case 'D': s[i][j]=RHC; break;
}
}
}
Gotoxy(x,y);
for(i=0;i<7;i++) {
printf("%s\n",s[i]);
}
getchar();
return 0;
}
void menu(char *words[MAX]) {
int i;
printf(" Welcome to the Main Menu\n");
do {
printf("\n\tEnter '1' to play Word Invaders, \n\tor '2' to Quit: ");
fflush(stdout);
scanf(" %d",&i);
if(i==1) { //play the game
//intro: briefly, how to play the game
//print score at top, keep the position so you
//can get back and update it quickly
skyline();
//begin descending words and keyboarding, etc.
}else if(i==2)
break;
}while(i<1 || i>2);
}
void Gotoxy(short x, short y) {
COORD c={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}