Exemple #1
0
int main(){

    numRounds = 1;
    
    //ask for number of players
    numberOfPlayers();
    //ask players to choose a level
    selectLevel();
    //play game
    playGame();

    
    int round = playAgain();
    while (round == 1){
        reset();
        numRounds++;
        playGame();
        round = playAgain();
    }
    
    if (round == 0){
        displayFinalScore();
    }
    return 0;
}
Exemple #2
0
bool mainMenu() {
    
    characterInfo player;
    
    int menuSelect;
    
    system("cls");
    
    cout<< "(1)New game" <<endl;
    cout<< "(2)Load game" <<endl;
    cout<< "(3)Exit" <<endl;
    cout<< "What would you like to do? ";
    cin>>menuSelect;
    
    switch(menuSelect) {
        case 1:
            system("cls");
            player = characterInit(1);
            playGame(player);
            break;
        case 2:
            system("cls");
            player = characterInit(2);
            playGame(player);
            break;
        case 3:
            return false;
            break;
        default:
            return true;
            break;
    }
}
int playGame(int* board, int left, int right) {
	if (left > right) return 0;
	int& ret = cache[left][right];
	if (ret != EMPTY_VALUE) return ret;
	ret = max(board[left] - playGame(board, left+1, right), board[right] - playGame(board, left, right - 1));
	if (right - left + 1 >= 2) {
		ret = max(ret, -playGame(board, left + 2, right));
		ret = max(ret, -playGame(board, left, right - 2));
	}
	return ret;
}
Exemple #4
0
void GameMenu::getPlayer(int i)
{
    if(i == 0)
    {
        this->hide();
        glView->setFocus();
        emit playGame(0);
        return;
    }
    bool ok;
    QInputDialog *dialog1 = new QInputDialog();
    QString name = dialog1->getText(this, 
                    tr(std::string("Player" + std::to_string(i)).c_str()),
                    tr("Name:"), 
                    QLineEdit::Normal, QDir::home().dirName(),
                    &ok);
    if (ok && !name.isEmpty())
    {
        glView->p1.name = name.toStdString();
        glView->p1.score = 0;
        glView->p1.winner = false;
    }
    else ok = false;

    if(i > 1)
    {
        QInputDialog *dialog2 = new QInputDialog();
        QString name = dialog2->getText(this, 
                    tr(std::string("Player" + std::to_string(i)).c_str()),
                    tr("Name:"), 
                    QLineEdit::Normal, QDir::home().dirName(),
                    &ok);
        if (ok && !name.isEmpty())
        {
            glView->p2.name = name.toStdString();
            glView->p2.score = 0;
        
        }
        else ok = false;
    }
    else
    {
        glView->p2.name = "Computer";
        glView->p2.score = 0;
        glView->p2.winner = false;
    }

    this->hide();
    glView->setFocus();

    emit playGame(i);

}
bool playGame(vector<int> a, vector<int>& visited, int &index) {
	
	visited[index] = 1;

	// Validate 

	if(visited[index]) return false;
	if(a[index] == 0) return TRUE;
	bool leftRetVal = playGame(a, visited, index + a[index]);
	bool rightRetVal = playGame(a, visited, index - a[index]);
	return (leftRetVal || rightRetVal);
}
void Game::run()
{
	int selection;
	string filename, tester;
	ifstream testStream;
	
	display("\nWelcome to the adventure game!\n");
	
	do {
		display("\nWhat will you do? (enter the number corresponding to your selection)\n 1. New game\n 2. Load game\n 0. Quit game\n");
		selection = getSelection();
		switch (selection) {
			case 1:
				cout << '\n';
				if (loadDefaultData() == OK)
					playGame();
				break;
			case 0:
				break;
			case 2:
				display("\nWhat is the name of your save file? (press enter to cancel)\n");
				getline(cin, filename);
				
				testStream.open(filename.c_str());
				getline(testStream, tester);
				if (filename != "") {
					if (tester != "start_save_file") {
						stringstream output;
						output << "\nSorry, " << filename << " is not the name of a valid save file.  Try again.\n";
						display(output.str());
						selection = -1;
						break;
					}
					testStream.close();
				
					if (loadGame(filename) == ERROR)
						cout << "Error: something went wrong with loadGame().\n";
					else {
						cout << '\n';
						playGame(filename);
					}
				}
				break;
			default:
				display("Invalid selection. Try again.\n");
				break;
		}
	} while (selection != 0);
	
	display("\nGood bye! Thanks for playing!\n\n");
}
Exemple #7
0
int main() {

    // Room names array. Static, but dynamically assigned to each room.
    // There must be more names here than MAX_ROOMS!
    //
    char *roomNames[10] = {  
        "Mozart",
        "Schubert",
        "Beethoven",
        "Bach",
        "Wagner",
        "Vivaldi",
        "Pachelbel",
        "Satie",
        "Berg",
        "Chopin" };

    // Array holding Room names read in from files (see readRooms()).
    //
    char *readRoomNames[MAX_ROOMS] = {0}; 

    // Array of pointers to Rooms. This array is first used to set up
    // Rooms to be output to files (see setupRooms()), then it is reused
    // to read in Rooms from files (see readRooms()).
    //
    struct Room *prooms[MAX_ROOMS];

    // Holds the name of the output file directory.
    //
    char dirName[30];       

    // Create the output file directory. The name is hardcoded to include
    // my ONID username (ratclier), then ".rooms.", then the PID of the
    // running program. This directory is not removed at the end of the
    // game, per assignment guidelines.
    //
    sprintf(dirName, "%s.%ld", "ratclier.rooms", (long) getpid());
    mkdir(dirName, 0755); // File permissions: u = rwx, g = r-x, o = r-x
                          //                       421      4-1      4-1
                          //                        7        5        5

    // Set up the Room files.
    //
    setupRooms(prooms, dirName, roomNames);

    // Read the Room data in from files.
    //
    readRooms(prooms, dirName, readRoomNames);

    // Play the game.
    //
    playGame(prooms, readRoomNames);

    // Clean up Room struct pointers.
    //
    cleanRooms(prooms);

    return 0;

}
Exemple #8
0
int main() {
    hideCursor();
    char title[] = "Simple Game Demo";
    setTitle(title);

    int opt = displayMainMenu();
    while (opt != 3) {
        clrscr();
        if (opt == 0) {
            char msg[] = "Let's play a game\nEat the # to win the game";
            displayMsg(0, 0, msg);
            Sleep(1000);
            clrscr();
            playGame();
        } else if (opt == 1) {
            printf("This is load");
        } else if (opt == 2) {
            printf("This is setting");
        }
        clrscr();
        opt = displayMainMenu();
    }

    return 0;
}
Exemple #9
0
int
main(int argc, char *argv[])
{	
	int i;
	int board_size;
	int **board;

	printf("===================================\n");
	printf("Welcome to verTIC-horizonTAC-TOE!\n");
	printf("===================================\n");
	printf("Please select the size of the board: ");

	/* take input for the size of board, exit program if input not valid */
	if (scanf("%d", &board_size) != 1) {
		printf ("Input Error!\n");
    	return EXIT_FAILURE;
	}

	/* allocate memory to the board array */
	board =  calloc(board_size, sizeof *board);
	for (i=0; i<board_size; i++) {
		board[i] = calloc(board_size, sizeof *board[i]);
	}

	/* start playing tic-tac-toe */
	playGame(board, board_size);

	return 0;
}
Exemple #10
0
int main()
{
    FILE *fp = fopen("dictionary.txt", "r");
    CVector** dict = malloc(MAX_WORD_SIZE * sizeof(CVector*));
    for (int i = 0; i < MAX_WORD_SIZE; i++) {
        dict[i] = NULL;
    }
    readDict(fp, dict);
    fclose(fp);
    char replay = 1;
    while (replay == 1) {
        int wordLength = chooseWordLength(dict);
        CVector *wordVec = dict[wordLength];
        playGame(wordVec, wordLength);
        printf("Do you want to replay (Y/N)? ");
        char *s = malloc(MAX_WORD_SIZE);
        scanf("%s", s);
        if (strcmp(s, "y") == 0 || strcmp(s, "Y") == 0) replay = 1;
        else {
            replay = 0;
            free(wordVec);
        }
    }
    for (int i = 0; i < MAX_WORD_SIZE; i++) {
        cvec_dispose(dict[i]);
//        if (dict[i] != NULL) {
//            cvec_dispose(dict[i]);
//        }
    }
    free(dict);
    
    return 0;
}
Exemple #11
0
int main(int argc, char *argv[]){
    struct BSTree *tree = newBSTree();
    startScreen();
    buildTree(tree);
    playGame(tree);
    return 0;
}
Exemple #12
0
void printMenu(char choice[],char path[],char input[])
{
    system("clear");
    printf("********************************\n");
    printf("*                              *\n");
    printf("*          Hang Man!            *\n");
    printf("*                              *\n");
    printf("*        **************        *\n");
    printf("*        *   Play!     *        *\n");
    printf("*        **************        *\n");
    printf("*                              *\n");
    printf("*        **************        *\n");
    printf("*        *  Settings!  *        *\n");
    printf("*        **************        *\n");
    printf("*                              *\n");
    printf("*                              *\n");
    printf("********************************\n");
    scanf("%s",input);
    
    if(strcmp(input,"play")== 0||strcmp(input,"Play")== 0)
    {       
        playGame(path);
    }
    else if(strcmp(input,"settings")== 0||strcmp(input,"Settings")== 0)
    {       
        printSettings();
    }
   
    
}
Exemple #13
0
void GameApp::run()
{
	loadedSurface = IMG_Load("res/arrow.png");
	if(!loadedSurface) {
    	printf("no image...IMG_Load: %s\n", IMG_GetError());
    	// handle error
	}
    sheep = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
	
    if(sheep == NULL)
    {
        printf("Unable to create ship texture! SDL Error: %s\n", SDL_GetError());
        quit=true;
    }
    SDL_FreeSurface(loadedSurface);
	
	loadedSurface = IMG_Load("res/rightm.png");
	rocket = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
	if(rocket == NULL)
	{
		printf("Unable to create rocket texture! SDL Error: %s\n", SDL_GetError());
		quit=true;
	}
	SDL_FreeSurface(loadedSurface);

	//printf("Calling createPlayers() function...\n");


	createPlayers();

	//printf("Calling playGame() function...\n");
    playGame();
}
Exemple #14
0
void GP::selfImprovePop()
{
  int results;
  //Thread Here
  for(unsigned int i=0;i<pop.size();i++)
  {
    mutant[i]=pop[i];
    do
    {
      results=rand()%mutant[i].early.size();
      mutant[i].early[results]=rand()%6;
    }
    //ensure that its changed
    while(mutant[i].early[results] == pop[i].early[results]);
    do
    {
      results=rand()%mutant[i].late.size();
      mutant[i].late[results]=rand()%6;
    }
    //ensure that its changed
    while(mutant[i].late[results] == pop[i].late[results]);

    if(!playGame(pop[i],mutant[i],host,results))
    {
      cerr<<"GAIB: playGame failed during mutation step"<<endl;
    }
    mutant[i].turnSwap=rand()%6+247;
    //if the original LOST
    if(results<0)
    {
      cout<<"TOPTEIR Someone was selfImproved"<<endl;
      pop[i]=mutant[i];
    }
  } 
}
Exemple #15
0
int main(int argc,char* argv[])
{
	Hashtable* theTable = readWordList("pairs.txt");
	playGame(theTable);
	destroyHTable(theTable);
	return 0;
}
Exemple #16
0
/*****************************************************************************
 Function: playGame
 Inputs:   node for this board, plus player (to get to this board)
 Returns:  nothing
 Description: play the game of TTT
 *****************************************************************************/
void playGame (NodeP node, char player) {

  int bestChild;   /* which of the children to move to */
  NodeP nextNode;  /* the node for that child */

  if (!gameOver(node)) { /* if we're not yet done */

    printNode(node);     /* print the board and scores */

    printf("Next move by player %c\n", player);
    
    lookahead(node, player, DEPTH);      /* construct the lookahead tree */

    bestChild = bestMove(node, player);  /* the best move for the player */
    nextNode = node->offspring[bestChild];

    /**** should free offspring of bestChild, plus all the other children */

    MoveCount++;
    playGame(nextNode, opponent(player));  /* recurse */
  }

  else {  /* game is over */
    printf("Final board is: \n");
    printNode(node);
  }

} /* end playGame */
Exemple #17
0
void XeenEngine::outerGameLoop() {
	if (_loadSaveSlot != -1)
		// Loading savegame from launcher, so Skip menu and go straight to game
		_gameMode = GMODE_PLAY_GAME;

	while (!shouldQuit() && _gameMode != GMODE_QUIT) {
		GameMode mode = _gameMode;
		_gameMode = GMODE_NONE;
		assert(mode != GMODE_NONE);

		switch (mode) {
		case GMODE_STARTUP:
			showStartup();
			break;

		case GMODE_MENU:
			showMainMenu();
			break;

		case GMODE_PLAY_GAME:
			playGame();
			break;

		default:
			break;
		}
	}
}
Exemple #18
0
void printSettings()
{
    system("clear");
    char userInput[Size];
    printf("********************************\n");
    printf("*                              *\n");
    printf("*                              *\n");
    printf("*      Enter file or folder    *\n");
    printf("*                              *\n");
    printf("*                              *\n");
    printf("*                              *\n");
    printf("*                              *\n");
    printf("*                              *\n");
    printf("*                              *\n");
    printf("********************************\n");
    scanf("%s",userInput);
    if(strstr(userInput,"back"))
    {
        
    }
    else
    {
         playGame(userInput);
    }
    
}
Exemple #19
0
// -----------------------------------------------------------------------
// main:
//  The main program parses commandline arguments and starts a game.
//
int main (int argc, char *argv[])
{
  Gmp *gmp;
  
  Load_Arguments (argc, argv);
  
  joseki_count  = Pattern_Load_Text_File (joseki_list,  MAX_PATTERNS, joseki_file);
  pattern_count = Pattern_Load_Text_File (pattern_list, MAX_PATTERNS, pattern_file);
  
  srand(time(NULL));
  gmp = gmp_create(0, 1);

  while (1)
  {
    gmp_startGame (gmp, -1, -1, 5.5, -1, -1);  // This allows the other side to set the parameters.
    waitForNewGame(gmp);
    
    if (gmp_handicap(gmp) > 9)
    {
      fprintf(stderr, "I don't know how to play handicap games greater than 9.\n");
      exit(1);
    }
    
    playGame(gmp, gmp_size(gmp), gmp_handicap(gmp), gmp_iAmWhite(gmp));
  }
  
  fclose (debug);
  exit(0);
}   // main
Exemple #20
0
int main(int argc, char** argv){
	Parameters param(argc, argv);
	srand(param.seed);

	RAMFeatures ramFeatures;
	BPROFeatures bproFeatures(param.gameName);

	vector<vector<vector<float> > > w;

	loadWeights(param, &bproFeatures, w);

	ALEInterface ale(0);
	ale.setInt  ("random_seed"               , param.seed);
	ale.setInt  ("max_num_frames_per_episode", 18000     );
	ale.setBool ("color_averaging"           , true      );
	ale.setFloat("frame_skip"                , 1         );
	ale.setFloat("repeat_action_probability" , 0.00      );

	ale.loadROM(param.romPath.c_str());

	for(int i = 0; i < 2 * NUM_BITS; i++){
		frequency.push_back(0.0);
	}

	int totalNumFrames = 0;
	for(int episode = 0; totalNumFrames < MAX_NUM_FRAMES; episode++){
		totalNumFrames = playGame(ale, &ramFeatures, &bproFeatures, w, param, totalNumFrames, episode);
		totalNumFrames += ale.getEpisodeFrameNumber();
	}

	return 0;
}
Exemple #21
0
int main(){
 srand(time(NULL));
 start = time(NULL);
 flag_password = rand() % 999999;
 printf("\nSeed value = %d\n", flag_password);
 fflush(stdout);
 playGame();
 return 0;
}
Exemple #22
0
void TetrisModel::startGame(int level)
{
    // assign level value
    m_curLevel = level;
    
    // 
    playGame();
    
}
Exemple #23
0
// Controls the display when user wins the game
void win(){
	unsigned char end[] = "You Win!";
	info (end);
	sleep(1);
	unsigned char re[] = "Restarting ...";
	info (re);
	sleep(2);
	playGame();
}
Exemple #24
0
// Controls the display when user loses the game
void gameOver(){
		unsigned char end[] = "Bye";
		info (end);
		sleep(1);
		unsigned char re[] = "Restarting ...";
		info (re);
		sleep(2);
		playGame();
}
Exemple #25
0
int main (int argc, char *argv[])
{
	array* a = initArray (7, 5);
	array* b = initArray (7, 5);
	playGame (a, b);
	freeArray (a);
	freeArray (b);

	return 0;
}
Exemple #26
0
int main(int argc, char *argv[])
{
#if defined(__ANDROID__)
    __android_log_print(ANDROID_LOG_INFO, "Gigalomania", "started main");
#endif

    playGame(argc, argv);
#if defined(__ANDROID__)
    __android_log_print(ANDROID_LOG_INFO, "Gigalomania", "about to exit main");
#endif
    return 0;
}
Exemple #27
0
int main( ) {
  char ans;
  bool done = false;
  while ( ! done ) {
         playGame();   // YOU MUST WRITE THIS FUNCTION
         cout << " Play again (y/n) ? ";
         cin >> ans;
         if ( ans == 'y' || ans == 'Y') done = true;
             else done = false;
  }
  return 0;
}
Exemple #28
0
void gameOver() {
    system("cls");
    SetPos(17, 10); cout << "Game over";
    SetPos(13, 11); cout << "Press space to replay...";
    while(_kbhit() || !_kbhit()) {
        if(CTRL_SPACE == _getch()) {
            break;
        }
    }
    initialize();
    playGame();
}
int main() {

	do {

		initCurses();
		drawBoard();

	} while (playGame());

	endwin();
	return(0);
}
int main( )
{
	char answer;
	char result;

	Menu( );

	// ***********Answer to playing*************
	while( answer = playAgain( ) )
	{
		switch( answer ) // The user decides to play the game
		{
			case 'y':
					printf( "Alright! Lets Play!\n\n" );

					Instructions( ); // Will jump to the Instuctions Function
					result = playGame( ); // Will jump to rhe playGame Function

				// ****************RESULT OF GAME*************************


					if( result == 'w' ) // After the function playGame returns 'w', the user then won the game.
					{
						printf( "\n\nHurray! You Win!\n\n\n" );	
					}

					if( result == 'l' ) // Vise versa with the function playGame if it returns 'l'.
					{
						printf( "Awwww. I'm sorry but you Lose!\n\n\n" );
					}

					break;
			case 'n':
					printf( "Too Bad! Maybe next time!\n" ); //The user decides to not play the game thus the program terminates
					
					return 0;

			case 'v':
					filePrint( );
				
					break;

			default:
					printf( "That was not one of the choices. Please try again.\n\n" );

					break;
				
		}

		Menu( );
	}
}