示例#1
0
文件: bs.c 项目: a565109863/src
int
main(int argc, char *argv[])
{
    if (pledge("stdio rpath tty", NULL) == -1)
        err(1, "pledge");

    do_options(argc, argv);

    intro();
    do {
	initgame();
	while(awinna() == -1)
	{
	    if (!blitz)
	    {
		if (!salvo)
		{
	    	    if(turn)
			(void) cputurn();
		    else
			(void) plyturn();
		}
		else  /* salvo */
		{
		    int i;

		    i = scount(turn);
		    while (i--)
		    {
			if (turn)
			{
			    if (cputurn() && awinna() != -1)
				i = 0;
			}
			else
			{
			    if (plyturn() && awinna() != -1)
				i = 0;
			}
		    }
		}
	    }
	    else  /* blitz */
	    	while(turn ? cputurn() : plyturn())
		{
		    if (turn)   /* Pause between successive computer shots */
		    {
			(void)refresh();
			(void)sleep(1);
		    }
		    if (awinna() != -1)
		     break;
		}
	    turn = OTHER;
	}
    } while
	(playagain());
    uninitgame(0);
    return 0;
}
示例#2
0
int main (void) {
  intro ();
  loadmemory ();
  do playgame (); while (playagain ());
  if (memory[0] > 1) savememory ();
  printf ("\nPress ENTER to continue...");
  getchar ();
  return 0;
}
示例#3
0
int main (void) {
  puts ("Reflex\n------\n\n"
  "How's your reflexes? In this game see how accurately you can tell how\n"
  "much time has elapsed. The computer will give you a number of seconds.\n"
  "When you are ready press ENTER to start the timer, then press ENTER\n"
  "again when you think the given amount of time has elapsed.\n");
  srand (time(NULL));
  do playgame (); while (playagain ());
  exit (0);
}
示例#4
0
	void snake::collision()
	{
		gotoxy(1,24);
		delline();
		gotoxy(35,24);
		color();
		cprintf("GAME OVER");
		gotoxy(1,25);
		textcolor(7);
		cprintf("The snake collided with the wall or with itself!");
		gotoxy(70,24);
		color();
		cprintf("SCORE=");
		cout<<score;
		getch();
		playagain();	
	}
示例#5
0
int
main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");

    do_options(argc, argv);

    intro();
    do {
	initgame();
	while (awinna() == -1) {
	    if (!blitz) {
		if (!salvo) {
		    if (turn)
			(void) cputurn();
		    else
			(void) plyturn();
		} else {
		    register int i;

		    i = scount(turn);
		    while (i--) {
			if (turn) {
			    if (cputurn() && awinna() != -1)
				i = 0;
			} else {
			    if (plyturn() && awinna() != -1)
				i = 0;
			}
		    }
		}
	    } else
		while ((turn ? cputurn() : plyturn()) && awinna() == -1)
		    continue;
	    turn = OTHER;
	}
    } while
	(playagain());
    uninitgame(0);
    /*NOTREACHED */
}
示例#6
0
int
main(int argc, char **argv)
{
    do_options(argc, argv);

    intro();
    do {
		initgame();
		while(awinna() == -1) {
		    if (!blitz) {
				if (!salvo) {
		    	    if (turn)
		    	    	cputurn();
		    	    else plyturn();
				} else {
				     register int i;

				     i = scount(turn);
				     while (i--) {
					 	if (turn)
					 	    if (cputurn())
							 	if (awinna() != -1)
							     	i = 0;
					 	else
					 	    if(plyturn())
							 	if (awinna() != -1)
							     	i = 0;
				 	}
			    }
		    } else {
		    	while((turn) ? cputurn() : plyturn());
		    }
		    turn = OTHER;
		}
    } while(playagain());
    uninitgame();
    exit(0);
}
示例#7
0
文件: bs.c 项目: kusumi/DragonFlyBSD
int
main(int argc, char **argv)
{
	int ch;

	/* revoke */
	setgid(getgid());

	while ((ch = getopt(argc, argv, "bsc")) != -1) {
		switch (ch) {
			case 'b':
				blitz = 1;
				break;
			case 's':
				salvo = 1;
				break;
			case 'c':
				closepack = 1;
				break;
			case '?':
			default:
				usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (blitz && salvo)
		usage();

    intro();

	do {
		initgame();
		while(awinna() == -1) {
			if (blitz) {
				while(turn ? cputurn() : plyturn())
					continue;
			} else if (salvo) {
				int i;

		   		i = scount(turn);
		   		while (i--) {
					if (turn) {
		   				if (cputurn() && awinna() != -1)
						i = 0;
					} else {
		   				if (plyturn() && awinna() != -1)
						i = 0;
					}
		   		}
			} else {	/* Normal game */
				if(turn)
					cputurn();
		   		else
					plyturn();
			}
	   		turn = OTHER;
		}
	} while (playagain());

    uninitgame();
    exit(0);
}
示例#8
0
/*****************************
*函 数 名:analyse_num
*函数功能:解析玩家猜测的字符串是否正确,游戏是否结束
*作    者:王阁阁
*日    期:2011-09-03
*******************************/
int analyse_num(char *str, char *correctnum)
{
    int result;
    int i = 0;
    int j = 0;
    int count_same = 0;             //数字相同且位置相同的数字个数
    int count_diff = 0;             //数字相同但位置不同的数字个数
    char answer[100];               //是否再完一局

    if(strcmp(str,"exit")==0)        //玩家结束游戏
    {
        printf("thank you for using\n");
        printf("the correct num is %s\n",correctnum);
	return 0;
    }
   
    if((strlen(str) > 4) || (is_digital(str) == 0)) //判断输入是否合法
    {
        printf("Invalid input\n");
        return 1;
    }

    //解析玩家字符串正确情况
    for(i = 0; i < strlen(correctnum); i++)
    {
        for(j = 0; j < strlen(str); j++) 
	{
            if(correctnum[i] == str[j])	
	    {
	        if(i==j)                      //数字相同且位置相同
		{
	            count_same++;	
		}
		else                          //数字相同但位置不同
		{
		    count_diff++;
		}
	    }
	}
    }

    if((count_same>0) && (count_same < 4))        //打印本次猜测的结果
    {
        printf("%dA",count_same);              //数字相同位置也相同用A的个数表示
    }
    else if(count_same == 4)                   //猜测结果正确
         {
	     printf("congratulations ,you win!\n"); 
	     printf("Do you want play again ? please answer yes or no.\n");
	     fgets(answer, sizeof(answer), stdin);//是否再玩一次
	     answer[strlen(answer) - 1] = '\0';
	     if(strcmp(answer, "no")==0)         //游戏结束
	     {
	         printf("thank you for using~!\n");
	         return 0; 
	     }
	     else if(strcmp(answer, "yes") == 0)  //游戏继续
	          {
		      memset(correctnum,'0',sizeof(correctnum)); //重新初始化游戏
		      playagain(correctnum); 
		      return 1;
		  }
		  else
		  {
		      printf("please input yes or no!\n");
		  }
	 }

    if(count_diff>0)
    {
        printf("%dB",count_diff);  
    }
    printf("\n");
//    printf("%s\n",numstr);
 
    return 1;
}