void AskID()
{
    printf("Now you are going to register an ID!\nThere are some notice,attention please!\n\n");
    printf("(1)You can choose your ID freely.\n\n");
    printf("(2)But the ID must consist of 2 letters and 4 numbers!\nFor example AB1234.\n\n");
    printf("(3)You can set your password freely.\n\n");
    printf("(4)But the password must consist 6 numbers!\nFor example 123456.\n\n");

    printf("Please enter your ID you choose:\n");
    gets(idnum);

    if(isvalidInt(idnum)==TURE)
    {
      printf("Please enter your password you choose:\n");
      gets(password);

      if(isvalidint(password)==TURE)
      {
	    IDnum=idnum;
    	Password=password;

	    outFile=fopen(IDnum,"w+");
        if(outFile==NULL)
        {
	      printf("\nFail to open the file.\n");
	      exit(1);
        }
        fprintf(outFile,"%-10s %-20s\n",IDnum,Password);
        fclose(outFile);

        char IDnum1[10];
        char Password1[10];
        inFile=fopen(IDnum,"r");
        if(inFile==NULL)
        {
	      printf("\nFail to open the file.\n");
	      exit(1);
        }
        while(fscanf(inFile,"%s %s",&IDnum1,&Password1)!=EOF);
        printf("%10s %10s\n",IDnum1,Password1);
        fclose(inFile);
		printf("You have successfully ask an ID!");
		main();
      }
      else
      {printf("You choose the wrong password!");
      askID();}
    }
    else
    {printf("You choose the wrong ID!");
    askID();}
}
int main()
{
  int num;
  printf("Welcome to our surpermarket!\n(1)Register an ID\n(2)Start\n(3)Exit\n");
  printf("Please enter the number in which the program you want:");
  scanf("%d",&num);
  getchar();

  switch(num)
  {
    case 1:
     askID();
     break;
   case 2:
     Start();
     break;
   case 3:
     exit(1);
     break;
    default:
    printf("\nPlease enter the right number!");
    break;
   }

   return 0;
}
示例#3
0
void StartScreen::askWhatYouWannaDo()
{
	sf::Event Event;
		_screenText.setString("WhatYouWannaDo?");
		_screenText.setOrigin(_screenText.getGlobalBounds().width*0.5f,_screenText.getGlobalBounds().height*0.5f);
		bool done = false;
		while(!done)
		{
		while(_window.pollEvent(Event))
		{
			switch(Event.type)
			{
			case sf::Event::Closed:
				_window.close();
				break;
			case sf::Event::KeyPressed:
			
				if(Event.key.code == sf::Keyboard::Escape)
					_window.close();

				if(Event.key.code == sf::Keyboard::Left)
				{
					if(_option != HOSTPLAY)
						_option--;
					else
						_option = HOST;
				}
				if(Event.key.code == sf::Keyboard::Right)
				{

					if(_option != HOST)
						_option++;
					else
						_option = HOSTPLAY;
				}

				if(Event.key.code == sf::Keyboard::Return)
				{

				_LeftBlock.setFillColor(sf::Color::Transparent);
				_CenterBlock.setFillColor(sf::Color::Transparent);
				_RightBlock.setFillColor(sf::Color::Transparent);
				_blockText.setString("");
					switch(_option)
					{
					case HOSTPLAY:
						askID();
						done = true;
						break;
					case PLAY:
						askID();
						askIP();
						done = true;
						break;

					case HOST:
						done = true;
						break;

					}
				}

	
			}

			}
		switch(_option)
			{
			case HOSTPLAY:
				_LeftBlock.setFillColor(sf::Color::Green);
				_CenterBlock.setFillColor(sf::Color::White);
				_RightBlock.setFillColor(sf::Color::White);
				_blockText.setPosition(_LeftBlock.getPosition());
				_blockText.setString("HostPlay");
				break;
			case PLAY:
				_LeftBlock.setFillColor(sf::Color::White);
				_CenterBlock.setFillColor(sf::Color::Green);
				_RightBlock.setFillColor(sf::Color::White);
				_blockText.setPosition(_CenterBlock.getPosition());
				_blockText.setString("Play");
				break;
			case HOST:
				_CenterBlock.setFillColor(sf::Color::White);
				_RightBlock.setFillColor(sf::Color::Green);
				_LeftBlock.setFillColor(sf::Color::White);
				_blockText.setPosition(_RightBlock.getPosition());
				_blockText.setString("Host");
				break;

		}
		draw();
		}

}