Exemplo n.º 1
0
int main(void)
{
   srand(time(NULL));
   GuessGamAnswer answer;
   answer.randomGenerate();

   showRules();

   // allow 10 guesses at maximum
   for (int i = 0; i < 10; ++i)
   { 
      std::string input;
      do
      {
         input = getInput();
      } while (!isInputLegal(input));

      int match1 = 0, match2 = 0;
      answer.evaluateGuess(input, match1, match2);
      if (match1 < 4)
         showGuessResults(match1, match2);
      else
	 showWin();
   }

   showLose(answer);
}
Exemplo n.º 2
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , m_ui(new Ui::MainWindow)
    , m_model(0)
    , m_controller(0)

{
    // instantiate settings once here
    new Settings(this);

    // acces them later on via instance()
    /*Settings* s = Settings::instance();

    qDebug() << "***** Current settings *****";
    qDebug() << "Player name" << s->playerName();
    qDebug() << "Player color" << s->playerColor();
    qDebug();
    qDebug() << "AI name" << s->aiName();
    qDebug() << "AI color" << s->aiColor();
    qDebug() << "AI level" << s->aiLevel();
    qDebug();*/

    m_ui->setupUi(this);
    m_ui->statusbar->setVisible(false);

    //connect actions to functions
    connect(m_ui->actionExit, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
    connect(m_ui->action640x480, SIGNAL(triggered()), this, SLOT(resolutionChange()));
    connect(m_ui->action800x600, SIGNAL(triggered()), this, SLOT(resolutionChange()));
    connect(m_ui->action1920x1080, SIGNAL(triggered()), this, SLOT(resolutionChange()));
    connect(m_ui->actionPlayer, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
    connect(m_ui->actionNew_Game, SIGNAL(triggered()), this, SLOT(newGame()));

    connect(m_ui->actionQuicksave, SIGNAL(triggered()), this, SLOT(quickSave()));
    connect(m_ui->actionQuickload, SIGNAL(triggered()), this, SLOT(quickLoad()));
    connect(m_ui->actionImpressum_2, SIGNAL(triggered()), this, SLOT(showImpressum()));
    connect(m_ui->actionHow_to_play, SIGNAL(triggered()), this, SLOT(showRules()));

    setupGame();
}
Exemplo n.º 3
0
int main(void)
{
	/* Welcome Message*/	
	GWindow window = newGWindow(WIDTH, HEIGHT);			// instantiates a window
	setWindowTitle(window, "Tic-Tac-Toe");
	welcome(window);
	
	/* Mode Selection */	
	int mode = selectMode(window);
	
	
	/*  Show Rules */
	showRules(mode, window);
	
	/* Play Game */
	play(mode, window);
	
	/* End Message */
	endMessage(window);
	
	waitForClick();
	closeGWindow(window);
    return 0;		   
}
Exemplo n.º 4
0
int main( int argc, char **argv ) {

    inStruct Sentries = ( paramIn* )malloc( sizeof( paramIn ) );


    /**to print QUERY_STRING remove  the blank between STAR and SLASH * /
    fprintf(stdout, "Content-type: text/html%c%c",10,10);fflush(stdout);
    fprintf(stdout, "<HTML>\n<HEAD>\n<TITLE>iRODS Rule Administration</TITLE>\n</HEAD>\n<BODY bgcolor=#FFFFFF>\n");
    fprintf(stdout, "<CENTER> <B><FONT COLOR=#FF0000>iRODS Rule Base</FONT></B></CENTER>\n");
    fprintf(stdout, "QUERY=%s\n",getenv("QUERY_STRING"));
    fflush(stdout);
    fprintf(stdout, "</BODY></HTML>\n");
    exit(0);
    /****/
    /*** make below as comment for commandline
     testing by PUTTING space between last star and slash in this line **/
    getEntries( Sentries );
    /******/
    /*** uncomment below for commandline testing of APPLYRULE
     by REMOVING  space between last star and slash in this line ** /
    strcpy(Sentries->entries[0].name,"func");
    strcpy(Sentries->entries[1].name,"objPath");
    strcpy(Sentries->entries[2].name,"rescName");
    strcpy(Sentries->entries[3].name,"dataSize");
    strcpy(Sentries->entries[4].name,"dataType");
    strcpy(Sentries->entries[5].name,"dataOwner");
    strcpy(Sentries->entries[6].name,"host");
    strcpy(Sentries->entries[7].name,"action");
    strcpy(Sentries->entries[8].name,"ruleSet");
    strcpy(Sentries->entries[9].name,"dataUser");
    strcpy(Sentries->entries[10].name,"dataAccess");

    Sentries->entries[0].val = strdup("applyRule");
    Sentries->entries[1].val = strdup("/home/collections.nvo/2mass/images/foo");
    Sentries->entries[2].val = strdup("unix-sdsc");
    Sentries->entries[3].val = strdup("100");
    Sentries->entries[4].val = strdup("fits image");
    Sentries->entries[5].val = strdup("moore@sdsc");
    Sentries->entries[6].val = strdup("multivac.sdsc.edu");
    Sentries->entries[7].val = strdup("delete_data");
    Sentries->entries[8].val = strdup("raja,core");
    Sentries->entries[9].val = strdup("raja@sdsc|z1");
    Sentries->entries[10].val = strdup("delete");
    Sentries->m = 11;

    /******/
    /** uncomment below for commandline testing of SHOWRULES
    by REMOVING  space between last star and slash in this line ** /
    strcpy(Sentries->entries[0].name,"func");
    Sentries->entries[0].val = strdup("showRules");
    strcpy(Sentries->entries[1].name,"ruleSet");
    Sentries->entries[1].val = strdup("core");
    Sentries->m = 2;
    /******/
    if ( !strcmp( Sentries->entries[0].val, "showRules" ) ) {
        showRules( Sentries );
    }
    else if ( !strcmp( Sentries->entries[0].val, "applyRule" ) ) {
        performAction( Sentries );
    }
    free( Sentries );
    return 0;
}
Exemplo n.º 5
0
int main(int argc, char** argv) {
	
	std::string user_response;			// used to hold user responses
	
	Board gameOfLife;				// the game board

	// Intro
	showIntroArt();
	enterToContinue();

	// Calibration
	std::cout << std::endl;
	std::cout << "IMPORTANT: Please calibrate your window." << std::endl;
	std::cout << "I will show you a " << BOARD_LIMIT_X << " by " << BOARD_LIMIT_Y + 2
			  << " box. If you do not see a box full of '+' signs," << std::endl;
	std::cout << "please adjust your window and type 'again'." << std::endl;
	std::cout << "Type 'done' when you are finished." << std::endl;

	std::cout << std::endl;
	enterToContinue();

	calibrateWindow();

	// menu
	// loop until user quits
	while (user_response != "quit") {
		showMenu();
		std::cout << "Please choose an option: ";
		std::getline(std::cin, user_response);

		// std::cout << "user_response = " << user_response << std::endl;
		if (user_response == "calibrate") {
			calibrateWindow();
		} else if (user_response == "art") {
			showIntroArt();
			enterToContinue();
		} else if (user_response == "rules") {
			showRules();
			enterToContinue();
		} else if (user_response == "start") {
			// the game loop
			while (user_response != "quit") {
				showGameMenu();	
				
				// get user response
				std::cout << "Please choose an option: ";
				std::getline(std::cin, user_response);
				while (!(checkGameMenuValidity(user_response))) {
					std::cout << "Sorry, that isn't a valid option." << std::endl;
					std::cout << "Please choose an option: ";
					std::getline(std::cin, user_response);
				}

				// execute menu option
				if (user_response.find("show board") != std::string::npos) {
					gameOfLife.showBoard();

				} else if (user_response.find("add cell") != std::string::npos) {
					// extract number from response
					int amt = extractNumber(user_response);

					// check for no number
					if (amt == 0) {
						amt = 1;
					}

					// prompt user for cells
					for (int i=0; i<amt; i++) {
						// storage for user vars
						int x, y;

						std::cout << "NEW CELL # " << i+1 << std::endl;
						
						// prompt user
						std::cout << "Enter a x value: ";
						while (!(std::cin >> x)) {
							std::cin.clear();
							std::cin.ignore(256, '\n');
							std::cout << "That's not a valid value." << std::endl;
							std::cout << "Enter a x value: ";
						}

						std::cout << "Enter a y value: ";
						while (!(std::cin >> y)) {
							std::cin.clear();
							std::cin.ignore(256, '\n');
							std::cout << "That's not a valid value." << std::endl;
							std::cout << "Enter a y value: ";
						}

						// check if cell at coord
						if (gameOfLife.isAnyCellAtCoord(x, y)) {
							std::cout << "That coordinate is not available!" << std::endl;
							i--;
						} else {
							gameOfLife.addCell(Cell(x, y));
							std::cout << "New cell added at (" << x
									  << ", " << y << ")." << std::endl;
						}
						
						// clear cin
						std::cin.clear();
						std::cin.ignore(256, '\n');
						std::cout << std::endl;
					}

				} else if (user_response.find("add randoms") != std::string::npos) {
					int amt = extractNumber(user_response);

					if (amt == 0) {
						// no number, default value is 60
						for (int i=0; i<60; i++) {
							Cell c1;
							if (gameOfLife.isAnyCellAtCoord(c1.getX(), c1.getY())) {
								i--;
							} else {
								gameOfLife.addCell(c1);
							}
						}

						gameOfLife.showBoard();

						std::cout << "60 random cells added." << std::endl;
						enterToContinue();

					} else {
						// go by number
						for (int i=0; i<amt; i++) {
							Cell c1;
							if (gameOfLife.isAnyCellAtCoord(c1.getX(), c1.getY())) {
								i--;
							} else {
								gameOfLife.addCell(c1);
							}
						}
						std::cout << amt << " random cells added." << std::endl;
					}

				} else if (user_response.find("advance") != std::string::npos) {
					// extract number from response
					int amt = extractNumber(user_response);
					
					// iterate the board
					if (amt != 0) {
						gameOfLife.iterateGeneration(amt);
					} else {
						gameOfLife.iterateGeneration();
					}

					// pause on board view
					enterToContinue();

				} else if (user_response == "pattern") {
					showPatternMenu();

					std::cout << "Select a pattern: ";
					std::getline(std::cin, user_response);

					while ((user_response != "pinwheel") && (user_response != "big wheel") 
						&& (user_response != "glider") && (user_response != "glider gun") 
						&& (user_response != "o")) {
						std::cout << "That's not a valid pattern." << std::endl;
						std::cout << "Select a pattern: ";
						std::getline(std::cin, user_response);
					}

					int x, y;

					std::cout << "Where should the top left of the pattern be?" << std::endl;

					std::cout << "Enter a x value: ";
					while (!(std::cin >> x)) {
						std::cin.clear();
						std::cin.ignore(256, '\n');
						std::cout << "That's not a valid value." << std::endl;
						std::cout << "Enter a x value: ";
					}

					std::cout << "Enter a y value: ";
					while (!(std::cin >> y)) {
						std::cin.clear();
						std::cin.ignore(256, '\n');
						std::cout << "That's not a valid value." << std::endl;
						std::cout << "Enter a y value: ";
					}

					if (user_response == "pinwheel") {
						addPinwheel(x, y, gameOfLife);
					} else if (user_response == "big wheel") {
						addBigWheel(x, y, gameOfLife);
					} else if (user_response == "glider") {
						addGlider(x, y, gameOfLife);
					} else if (user_response == "glider gun") {
						addGliderGun(x, y, gameOfLife);
					} else if (user_response == "o") {
						addO(x, y, gameOfLife);
					}

					// clear cin
					std::cin.clear();
					std::cin.ignore(256, '\n');
					std::cout << std::endl;

					// display board
					gameOfLife.showBoard();

					// pause board
					enterToContinue();

				} else if (user_response.find("finish") != std::string::npos) {
Exemplo n.º 6
0
int main(int argc, const char * argv[])
{
	Bool result = TRUE;

	if ((argc < 2) || (argc > 3))
	{
		printf(USAGE);
		return -1;
	}


	if (strcmp(argv[1], LOAD_RULES) == 0)
	{
		if (argc != 3)
		{
			printf("A path to a rules file must be specified in order to load rules.\n");
			return -1;
		}
		else
		{
			result = loadRules(argv[2]);
			if (!result)
			{
				return -1;
			}
			return 0;
		}
	}
	else if (strcmp(argv[1], LOAD_HOSTS) == 0)
	{
		if (argc != 3)
		{
			printf("A path to a hosts file must be specified in order to load hosts.\n");
			return -1;
		}
		else
		{
			result = loadHosts(argv[2]);
			if (!result)
			{
				return -1;
			}
			return 0;
		}
	}
	else if (argc != 2)
	{
		printf("Any action other than %s, %s must not take any parameters.\n", LOAD_RULES, LOAD_HOSTS);
		return -1;
	}

	if (strcmp(argv[1], ACTIVATE) == 0)
	{
		result = activate();
	}
	else if (strcmp(argv[1], DEACTIVATE) == 0)
	{
		result = deactivate();
	}
	else if (strcmp(argv[1], SHOW_RULES) == 0)
	{
		result = showRules();
	}
	else if (strcmp(argv[1], CLEAR_RULES) == 0)
	{
		result = clearRules();
	}
	else if (strcmp(argv[1], SHOW_LOG) == 0)
	{
		result = showLog();
	}
	else if (strcmp(argv[1], CLEAR_LOG) == 0)
	{
		result = clearLog();
	}
	else if (strcmp(argv[1], SHOW_CONNECTION_TABLE) == 0)
	{
		result = showConnectionTable();
	}
	else if (strcmp(argv[1], SHOW_HOSTS) == 0)
	{
		result = showHosts();
	}
	else
	{
		printf("The only valid actions are: %s, %s, %s, %s, %s, %s, %s, %s\n",
			   ACTIVATE, DEACTIVATE, SHOW_RULES, CLEAR_RULES, LOAD_RULES, SHOW_LOG, 
			   CLEAR_LOG, SHOW_CONNECTION_TABLE, SHOW_HOSTS, LOAD_HOSTS);
	}

	if (result)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}