Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
void fun_com(); //The commands processing function
void fun_graph(); //The scene graph
void fun_prompt(); //Receiving orders
void fun_clearline(); //Clean lines for replies
enum boolean
{
false,
true
};
//The first variables of the scene
enum boolean holding=false;
int tboxes=10,sboxes=0;
char *where="truck";
char *commands;
int you=1;
void main()
{
fun_graph(); //Drawing the scene
while(true)
{
fun_prompt(); //Receiving orders
fun_com(); //Orders processing and making reactions
}
}
//The commands processing function
void fun_com()
{
//The truck direction order
if(!stricmp(commands,"goto truck"))
if(!stricmp(where,"truck"))
{
fun_clearline();
printf("You're already beside the truck.");
}
else
{
where="truck";
gotoxy(10,6);
printf(" ");
gotoxy(38,6);
printf("%c",(char)you);
}
//The store direction order
else if(!stricmp(commands,"goto store"))
if(!stricmp(where,"store"))
{
fun_clearline();
printf("You're already on the store.");
}
else
{
where="store";
gotoxy(38,6);
printf(" ");
gotoxy(10,6);
printf("%c",(char)you);
}
//Where you're order
else if(!stricmp(commands,"where am I"))
if(!stricmp(where,"truck"))
{
fun_clearline();
printf("You're beside the truck.");
}
else
{
fun_clearline();
printf("You're on the store.");
}
//The bringing up order
else if(!stricmp(commands,"bring up"))
if(holding==false && !stricmp(where,"truck") && tboxes>0)
{
tboxes--;
holding=true;
}
else if(holding==false && !stricmp(where,"store") && sboxes>0)
{
sboxes--;
holding=true;
}
else if(holding==false && !stricmp(where,"truck") && tboxes==0)
{
fun_clearline();
printf("There's no boxes in the truck.");
}
else if(holding==false && !stricmp(where,"store") && sboxes==0)
{
fun_clearline();
printf("There's no boxes on the store.");
}
else
{
fun_clearline();
printf("You're already have a box.");
}
//The putting down order
else if(!stricmp(commands,"put down"))
if(holding==true && !stricmp(where,"truck"))
{
tboxes++;
holding=false;
}
else if(holding==true && !stricmp(where,"store"))
{
sboxes++;
holding=false;
}
else
{
fun_clearline();
printf("You don't hold any box.");
}
//What I've order
else if(!stricmp(commands,"what I've"))
if(holding==true)
{
fun_clearline();
printf("You're holding a box.");
}
else
{
fun_clearline();
printf("You're not holding any box.");
}
//The how many order
else if(!stricmp(commands,"how many"))
{
fun_clearline();
printf("Truck boxes = %d, Store boxes = %d",tboxes,sboxes);
}
//The termination order
else if(!stricmp(commands,"exit"))
exit(0);
else
{
fun_clearline();
printf("You entered uncorrect order.");
}
}
//The scene graph
void fun_graph()
{
int u_left_cor=201;
int u_right_cor=187;
int d_left_cor=200;
int d_right_cor=188;
int horizontal=205;
int vertical=186;
int counter;
clrscr();
//The big box
gotoxy(1,1);
printf("%c",(char)u_left_cor);
for(counter=2;counter<60;counter++)
{
gotoxy(counter,1);
printf("%c",(char)horizontal);
}
gotoxy(60,1);
printf("%c",(char)u_right_cor);
for(counter=2;counter<12;counter++)
{
gotoxy(60,counter);
printf("%c",(char)vertical);
}
gotoxy(60,12);
printf("%c",(char)d_right_cor);
for(counter=59;counter>1;counter--)
{
gotoxy(counter,12);
printf("%c",(char)horizontal);
}
gotoxy(1,12);
printf("%c",(char)d_left_cor);
for(counter=11;counter>1;counter--)
{
gotoxy(1,counter);
printf("%c",(char)vertical);
}
//The truck
//The trunck
gotoxy(40,4);
printf("%c",(char)u_left_cor);
for(counter=41;counter<50;counter++)
{
gotoxy(counter,4);
printf("%c",(char)horizontal);
}
gotoxy(49,4);
printf("%c",u_right_cor);
gotoxy(49,5);
printf("%c",(char)vertical);
gotoxy(49,6);
printf("%c",(char)d_right_cor);
gotoxy(48,6);
printf("%c",(char)horizontal);
gotoxy(47,6);
printf("*");
for(counter=46;counter>42;counter--)
{
gotoxy(counter,6);
printf("%c",(char)horizontal);
}
gotoxy(42,6);
printf("*");
gotoxy(41,6);
printf("%c",(char)horizontal);
gotoxy(40,6);
printf("%c",(char)d_left_cor);
gotoxy(40,5);
printf("%c",(char)vertical);
//The truck head
gotoxy(51,4);
printf("%c",(char)u_left_cor);
for(counter=52;counter<55;counter++)
{
gotoxy(counter,4);
printf("%c",(char)horizontal);
}
gotoxy(55,4);
printf("%c",(char)u_right_cor);
gotoxy(55,5);
printf("%c",(char)vertical);
gotoxy(55,6);
printf("%c",(char)d_right_cor);
gotoxy(54,6);
printf("%c",(char)horizontal);
gotoxy(53,6);
printf("*");
gotoxy(52,6);
printf("%c",(char)horizontal);
gotoxy(51,6);
printf("%c",(char)d_left_cor);
gotoxy(51,5);
printf("%c",(char)vertical);
gotoxy(50,6);
printf("%c",(char)horizontal);
//The store
gotoxy(5,3);
printf("%c",(char)u_left_cor);
for(counter=6;counter<18;counter++)
{
gotoxy(counter,3);
printf("%c",(char)horizontal);
}
gotoxy(18,3);
printf("%c",(char)u_right_cor);
for(counter=4;counter<6;counter++)
{
gotoxy(18,counter);
printf("%c",(char)vertical);
}
for(counter=7;counter<9;counter++)
{
gotoxy(18,counter);
printf("%c",(char)vertical);
}
gotoxy(18,9);
printf("%c",(char)d_right_cor);
for(counter=17;counter>5;counter--)
{
gotoxy(counter,9);
printf("%c",(char)horizontal);
}
gotoxy(5,9);
printf("%c",(char)d_left_cor);
for(counter=8;counter>3;counter--)
{
gotoxy(5,counter);
printf("%c",(char)vertical);
}
//You
gotoxy(38,6);
printf("%c",(char)you);
//The command list
gotoxy(62,1);
printf("Commands:");
gotoxy(62,3);
printf("\"goto store\"");
gotoxy(62,4);
printf("\"goto truck\"");
gotoxy(62,5);
printf("\"where am I\"");
gotoxy(62,6);
printf("\"bring up\"");
gotoxy(62,7);
printf("\"put down\"");
gotoxy(62,8);
printf("\"how many\"");
gotoxy(62,9);
printf("\"what I've\"");
gotoxy(62,10);
printf("\"exit\"");
}
void fun_prompt()
{
int counter;
for(counter=1;counter<81;counter++)
{
gotoxy(counter,15);
printf(" ");
}
gotoxy(1,15);
printf(">");
gets(commands);
}
void fun_clearline()
{
int counter;
for(counter=1;counter<81;counter++)
{
gotoxy(counter,16);
printf(" ");
}
gotoxy(1,16);
}