예제 #1
0
void prog()
{
 char word[25],meaning[100],hword[25];
 int menuchoice,rep,l,h;
 node *temp;
 node *t;
 FILE *fp;

 clrscr();

 temp=treefromfile();

 if(temp==NULL)
   {
    printf("File does not exist or dictionary is empty...");
    getch();
   }
 while(1)
   {
    clrscr();
    menuchoice=showmenu();

   // scanf("%d",&menuchoice);

    switch(menuchoice)
      {
	case 1:{
		frame();
		printf("\nEnter word : \n");
		scanf("%s",word);
		printf("\nEnter meaning : " );
		flushall();
		gets(meaning);

		if(temp==NULL)
		  {
		   temp=maketree(word,meaning);
		  }
		else
		  {
		   addword(temp,word,meaning);
		  }
		break;
		}
	case 2:{
		frame();
		if(temp==NULL)
		  {
		   printf("\nThe dictionary is empty...\n");
		  }
		else
		  {
		   printf("\nFind meaning of : \n");
		   flushall();
		   gets(word);
		   t=csearch(temp,word);

		   if(t==NULL)
		     {
		      printf("\nWord not found...\n");
		      printf("\nDo you want to add this word to database: \n1>yes\n2>No\n");

		      scanf("%d",&rep);

		      if(rep==1)
			{
			 frame();
			 printf("\nEnter word : %s\n",word);
			 //scanf("%s",word);
			 printf("\nEnter meaning : " );
			 flushall();
			 gets(meaning);

			 if(temp==NULL)
			   {
			    temp=maketree(word,meaning);
			   }
			 else
			   {
			    addword(temp,word,meaning);
			   }
			 }
		      else
			{
			 printf("\nReturning to main menu...\n");
			}
		      }
		   else
		     {
		      printf("\n%s : ",t->word);
		      puts(t->meaning);
		     }
		  }
		getch();
		break;
		}
	case 3:{
		frame();
		if(temp==NULL)
		   printf("Dictionary is empty...");
		else
		   displayall(temp);
		getch();
		break;
		}
	case 4:{
		clrscr();
		printf("\n\n\tEnter word: ");
		scanf("%s",word);
		printf("\n\tEnter meaning: ");
		gets(meaning);
		change(temp,word,meaning);
		break;
	       }
	case 5:
	       {
		clrscr();
		frame();

		printf("\nHow many last searched words to be displayed:");
		scanf("%d",&h);

		fp=fopen("c:\\history.txt","r" );

		if(fp==NULL)
		  {
		   printf("\nUnable to read history file...\n");
		   printf("\n\n\tThere is no history of searched words...\n");
		  }
		else
		  {
		    gotoxy(1,20);
		    for(l=0;l<15;l++)
		      {
		       printf("||||");
		      }
		    gotoxy(1,1);
		    printf("\n\t\tHISTORY\n\n");
		    printf("\nLast %d words which were searched are:\n\n",h);

		    for(l=0;l<h;l++)
		     {
			fscanf(fp,"%s",hword);
			printf("\t%d>\t%s",l+1,hword);

		     }
		   }
	       fclose(fp);
	       getch();
	       break;
	       }
	case 6:{
		filefromtree(temp);

		end();

		exit(1);

		break;
	       }
	default:{
		  printf("Wrong!! Enter Again");
		  delay(1000);
		  prog();
		  break;
		}
  }
 }
}
예제 #2
0
파일: COLONY.C 프로젝트: jbailhache/log
int gameloop(void)
{

	int viewx, viewy, ex = 0, option, redraw = 1, nx, ny, mb;

	viewx = men.x - (WIN_X-1)/2 /*10*/;
	if( viewx < 0 ) viewx = 0;
	if( viewx > DIM_X-WIN_X+1/*40*/ ) viewx = DIM_X-WIN_X+1/*40*/;

	viewy = men.y - (WIN_Y-1)/2 /*5*/;
	if( viewy < 0 ) viewy = 0;
	if( viewy > DIM_Y-WIN_Y+1/*20*/ ) viewy = DIM_Y-WIN_Y+1/*20*/;

	while(ex==0)
	{

		if(redraw > 0)
		{
			display_map( viewx, viewy );
			redraw = 0;
		}

		displaymen( viewx, viewy );

		processing( viewx, viewy );

		clearmen( viewx, viewy);

		mb = m_button();

		if(mb==1)
		{

			if(m_ypos() < 180)
			{
				nx = ((men.x - viewx)*16) - m_xpos();
				ny = ((men.y - viewy)*16) - m_ypos();

				if( (nx > 0) & (checkmap( men.x-1, men.y ) > 0) ) men.x--;
				if( (nx < -16) & (checkmap( men.x+1, men.y ) > 0) ) men.x++;
				if( (ny > 0) & (checkmap( men.x, men.y-1 ) > 0) ) men.y--;
				if( (ny < -16) & (checkmap( men.x, men.y+1 ) > 0) ) men.y++;

				redraw=1;
			}
			else
			{
				nx = m_xpos();
				if( nx > 220 & nx < 240 ) fenceit( viewx, viewy );
				if( nx > 240 & nx < 260 ) homeit(viewx, viewy );
				if( nx > 260 & nx < 280 )
				{
					displayall();
					redraw = 2;
				}
				if( nx > 280 & nx < 300 ) ex=1;
			}

			delay(250);
		}

		if(bioskey(1)!=0)
		{
			option = bioskey(0);
		}
		else
		{
			option = 0;
		}

		switch(option)
		{
		case 283:
			ex = 1;
			break;

		case 19712:

			if( (men.x < DIM_X-1/*59*/) & (checkmap( men.x + 1 , men.y ) > 0) )
				men.x++;
			redraw = 1;
			break;

		case 19200:

			if( (men.x > 0) & (checkmap( men.x - 1 , men.y ) > 0) )
				men.x--;
			redraw = 1;
			break;

		case 20480:

			if( (men.y < DIM_Y/*30*/) & (checkmap( men.x , men.y + 1 ) > 0) )
				men.y++;
			redraw = 1;
			break;

		case 18432:

			if( (men.y > 0) & (checkmap( men.x , men.y - 1 ) > 0) )
				men.y--;
			redraw = 1;
			break;

		case 18688:

			displayall();
			redraw = 2;
			break;

		case 20992:

			fenceit( viewx, viewy );
			break;

		case 18176:

			homeit( viewx, viewy );
			break;

		default:

			break;

		}

		check_greble( viewx, viewy );

		if( redraw == 1 )
		{
			redraw = 0;

			if( ( men.x - 2 ) < viewx )
			{
				viewx = men.x - (WIN_X-1)/2 /*10*/;
				if( viewx < 0 ) viewx = 0;
				redraw = 1;
			}

			if( ( men.x + 2 ) > ( viewx + WIN_X-1/*20*/ ) )
			{
				viewx = men.x - (WIN_X-1)/2 /*10*/;
				if( viewx > DIM_X-WIN_X+1/*40*/ ) viewx = DIM_X-WIN_X+1/*40*/;
				redraw = 1;
			}

			if( ( men.y - 2 ) < viewy )
			{
				viewy = men.y - (WIN_Y-1)/2 /*5*/;
				if( viewy < 0 ) viewy = 0;
				redraw = 1;
			}

			if( ( men.y + 2 ) > ( viewy + WIN_Y-1/*10*/ ) )
			{
				viewy = men.y - (WIN_Y-1)/2 /*5*/;
				if( viewy > DIM_Y-WIN_Y+1 /*20*/ ) viewy = DIM_Y-WIN_Y+1 /*20*/;
				redraw = 1;
			}
		}
	}
}