Exemple #1
0
int user() {
	CLEAR_SCREEN
	printf(KCYN"Welcome to the Virtual Cinema\n\n"RESET);
	printf("Available options:\n");	
	while(TRUE)
	{
		printUserMenu();
		int c=getint(KBLU"Enter the desired option (number): "RESET);
		switch(c)
		{
			case 1: 
					buyTicketsFront();
					break;
			case 2:
					cancelTicketsFront();
					break;
			case 3:
					checkAvailabilityFront();
					break;
			case 4:
					getBoardFront();
					break;
			case 5:
					return 0;
			default:
					printf(KRED"Invalid command\n"KRED);
					break;
		}

	}

	return 0;
}
Exemple #2
0
State onPlayersTurn(Game* game) {
  /* added clear screen -Cesar 1/27 */
  char cmd[255];
  char choice = 0;
  char userInput[255];
  char promotionChoice;
  char maxTurnUserInput;
  int result;
  int ox, oy, dx, dy;
  clearScreen();
  assert(game);
  printBoard(game);
  printf("Turn number: %d, ", game->turn+1);
  if(game->turn%2 == 0)
	  printf("WHITE's turn\n");
  else
	  printf("BLACK's turn\n");
  printUserMenu(game);
  getGameInput(cmd);
  choice = cmd[0];
  
  if(check500Turns(game))
	  return MainMenu;


  /* added by Cesar 1/26 */
  switch(choice)
    {
    case '0':
      return MainMenu;
    case '1':
      printHints(game);
      return TurnPlayer;
    case '2':
      redo(game);
      return TurnPlayer;
	case '3':
	  printLog(game);
	  return TurnPlayer;
    case '4':
      replay(game);
      return TurnPlayer;
    case '5':
	  printf("Enter the file name you want to save \n");
	  scanf("%s", userInput);
      saveLog(game, userInput);
      fseek(stdin,0,SEEK_END);
	  return TurnPlayer;
	case '6':
	  printf("Enter the file name you want to save: ");
	  scanf("%s", userInput);
	  printf("\n");
      fseek(stdin,0,SEEK_END);
	  saveGame(game, userInput);
	  return TurnPlayer;
	case '7':
		gameOptions(game);
		return TurnPlayer;
    default:
      break;
    }
  
  
	ox = cmd[0] - 97;
	oy = cmd[1] - 49;
	dx = cmd[2] - 97;
	dy = cmd[3] - 49;
	if((!checkBoarder(ox, oy))||(!checkBoarder(dx, dy)) || (isValidMove(game, ox, oy, dx, dy) <= 0))
	{
		printf("INVALID MOVE DETECTED");
		if(game->setting->allowIllegalMove == 1)
		{
			printf(", TRY AGAIN\n\n");
			return TurnPlayer;
		}
		else
		{
			printf(", GAME OVER!\n\n");
			return MainMenu;
		}
	}

  
  result = gameLogic(game, cmd);
  if(result == 9 || result == 10)
  {
	  promotionChoice = ' ';
	  while(promotionChoice != 'Q' && promotionChoice != 'R' && promotionChoice != 'N' && promotionChoice != 'B')
	  {
		  printf("Pawn promotion, enter the promotion choice (char to represent piece): ");
		  scanf("%c", &promotionChoice);
		  fseek(stdin,0,SEEK_END);
		  if(promotionChoice=='q') promotionChoice='Q';
		  else if(promotionChoice=='r') promotionChoice='R';
		  else if(promotionChoice=='n') promotionChoice='N';
		  else if(promotionChoice=='b') promotionChoice='B';
		  printf("%c\n",promotionChoice);
		  if(promotionChoice != 'Q' && promotionChoice != 'R' && promotionChoice != 'N' && promotionChoice != 'B')
			  printf("Invalid input, try again.\n");
	  }
      result = promotion(game, cmd, promotionChoice);
  }
  if(result == 7)
  {
	  printf("CHECKMATE\n");
	  getchar();
	  return MainMenu;
  }
  else if(result == 8)
  {
	  printf("STALEMATE\n");
	  getchar();
	  return MainMenu;
  }

  if(game->setting->gameMode == 0)
    return TurnAI;
  else if(game->setting->gameMode == 1)
    return TurnPlayer;
  else
    return MainMenu; /* game logic returns 0 meaning the game is end */
}