Ejemplo n.º 1
0
/* Calls relevant functions to play the game and allows user to guess letter after letter
 * and checks if the user has won or lost after each guess.*/
void userLoop(){
    createLists(); // This reads the dictionary and generates an array of all lists of all word lengths
    char guess;    // This is the variable where the current letter being guessed is kept
    int next=0;    // Prevents duplication of code on first pass.
    int won=0;     // Keeps track of whether the game has been won or lost
    int hard= difficulty();  //User chosen difficulty level
    int numberOfLetter=numberOfLetters();
    //number of wrong guesses left before game is over
    int guessNumber=numberOfGuesses();
    
    
    printf("To play, type in a single letter as a guess.\n");
    printf("You have %i guesses remaining.\n", guessNumber);
    // game plays while the user still has some  guesses left and has not won
    
    guess = obtainGuess();      //Gets first guess from user
    insertInList(&head, guess );//Puts guessed letter in list of guessed letters
                                //All word families of user defined length are created
    generateDescriptions(&lists[numberOfLetter],numberOfLetter,guess);
    currentStatus();            // The status of game is shown to the user
    getNewList(hard);               /*Finds the biggest members list from current
                                *families and makes it the new main list of possible words*/
    
    
   //This is the loop that allows the game to proceed. The first part of the loop is similar to above.
    while ((guessNumber)>0 && won==0) {
        if (next==1) {// prevents and initial duplication
            printf("You have %i guesses remaining.", guessNumber);
            // prints the status of the uncovered letters
            guess = obtainGuess();       //Gets first guess from user
            insertInList(&head, guess ); //Adds the guessed letter to the list containing all guessed letters
            currentFamily=NULL;          //Resets list of current families
            
            //All word families of user defined length are created
            generateDescriptions(&currentWordList,numberOfLetter,guess);
            //All word families of user defined length are created
            /*Finds the biggest members list from current
             *families and makes it the new main list*/
            getNewList(hard);
            currentStatus();
        }
        // Allows the first part of the loop to be run on all subsequent guesses.
        next=1;
        
        // Lets the use know if they uncovered a letter.
        if (checkIfFound(guess,numberOfLetter)) {
            printf("\n \n \n Wrong!\n");
        }
        else {
            printf("\n \n \n Correct.\n");
            
        }
        //  The number of  guesses remaining decreases after each guess
        guessNumber--;
        // Checks to see if the user has uncovered all letters
        if (checkWin(numberOfLetter)) {
            printf("You Win!!");
            won=1;
        }
        
    }
    printf("Game over. You uncovered:");
    //Shows final game state
    currentStatus();
    //Shows user a word that fits the currently visible letter pattern.
    printf("The word was: %s\n",currentFamily->members->word);
    
}
Ejemplo n.º 2
0
void l_safe(void)
{
    char response;
    pob newitem;
    int attempt = 0;
    response = cinema_interact("pfqi",
                               "You have discovered a safe!",
                               "Pick the lock [p], Force the door [f], or ignore [ESCAPE]",
                               NULL);

    if (response == 'p')
        attempt = (2*Player.dex + Player.rank[THIEVES]*10 - random_range(100))/10;
    else if (response == 'f')
        attempt = (Player.dmg - random_range(100))/10;
    if (attempt > 0) {
        Player.alignment -= 4;
        gain_experience(50);
        print2("The door springs open!");
        Level->site[Player.x][Player.y].locchar = FLOOR;
        Level->site[Player.x][Player.y].p_locf = L_NO_OP;
        lset(Player.x, Player.y, CHANGED);
        if (random_range(2) == 1) {
            print1("You find:");
            do {
                newitem = create_object(difficulty());
                print2(itemid(newitem));
                morewait();
                gain_item(newitem);
            } while (random_range(3) == 1);
        }
        else print2("The safe was empty (awwwww....)");
    }
    else {
        print3("Your attempt at burglary failed!");
        if (attempt == -1) {
            print1("A siren goes off! You see flashing red lights everywhere!");
            morewait();
            if (Last_Environment == E_CITY) {
                print2("The city guard shows up! They collar you in no time flat!");
                change_environment(E_CITY);
                morewait();
                send_to_jail();
            }
        }
        else if (attempt == -2) {
            print1("There is a sudden flash!");
            p_damage(random_range(25),FLAME,"a safe");
            print2("The safe has self-destructed.");
            Level->site[Player.x][Player.y].locchar = RUBBLE;
            Level->site[Player.x][Player.y].p_locf = L_RUBBLE;
            lset(Player.x, Player.y, CHANGED);
        }
        else if (attempt == -3) {
            print1("The safe jolts you with electricity!");
            lball(Player.x,Player.y,Player.x,Player.y,30);
        }
        else if (attempt < -3) {
            print1("You are hit by an acid spray!");
            if (Player.possessions[O_CLOAK] != NULL) {
                print2("Your cloak is destroyed!");
                conform_lost_object(Player.possessions[O_CLOAK]);
                p_damage(10,ACID,"a safe");
            }
            else if (Player.possessions[O_ARMOR] != NULL) {
                print2("Your armor corrodes!");
                Player.possessions[O_ARMOR]->dmg-=3;
                Player.possessions[O_ARMOR]->hit-=3;
                Player.possessions[O_ARMOR]->aux-=3;
                p_damage(10,ACID,"a safe");
            }
            else {
                print2("The acid hits your bare flesh!");
                p_damage(random_range(100),ACID,"a safe");
            }
        }
    }
}
Ejemplo n.º 3
0
void install_specials(void)
{
  int i,j,x,y;

  for(x=0;x<Level->level_width;x++)
    for(y=0;y<Level->level_length;y++)
      if ((Level->site[x][y].locchar == FLOOR) &&
	  (Level->site[x][y].p_locf == L_NO_OP) &&
	  (random_range(300) < difficulty())) {
	i = random_range(100);
	if (i < 10) {
	  Level->site[x][y].locchar = ALTAR;
	  Level->site[x][y].p_locf = L_ALTAR;
	  Level->site[x][y].aux = random_range(10);
	}
	else if (i < 20) {
	  Level->site[x][y].locchar = WATER;
	  Level->site[x][y].p_locf = L_MAGIC_POOL;
	}
	else if (i < 35) {
	  Level->site[x][y].locchar = RUBBLE;
	  Level->site[x][y].p_locf = L_RUBBLE;
	}
	else if (i < 40) {
	  Level->site[x][y].locchar = LAVA;
	  Level->site[x][y].p_locf = L_LAVA;
	}
	else if (i < 45) {
	  Level->site[x][y].locchar = FIRE;
	  Level->site[x][y].p_locf = L_FIRE;
	}
	else if ((i < 50) && (Current_Environment != E_ASTRAL)) {
	  Level->site[x][y].locchar = LIFT;
	  Level->site[x][y].p_locf = L_LIFT;
	}
	else if ((i < 55) && (Current_Environment != E_VOLCANO)) {
	  Level->site[x][y].locchar = HEDGE;
	  Level->site[x][y].p_locf = L_HEDGE;
	}
	else if (i < 57) {
	  Level->site[x][y].locchar = HEDGE;
	  Level->site[x][y].p_locf = L_TRIFID;
	}
	else if (i< 70) {
	  Level->site[x][y].locchar = STATUE;
	  if (random_range(100) < difficulty()) 
	    for (j=0;j<8;j++) {
	      if (Level->site[x+Dirs[0][j]][y+Dirs[1][j]].p_locf != L_NO_OP)
		Level->site[x+Dirs[0][j]][y+Dirs[1][j]].locchar = FLOOR;
	      Level->site[x+Dirs[0][j]][y+Dirs[1][j]].p_locf = 
		L_STATUE_WAKE;
	    }
	}
	else {
	  if (Current_Environment == E_VOLCANO) {
	    Level->site[x][y].locchar = LAVA;
	    Level->site[x][y].p_locf = L_LAVA;
	  }
	  else if (Current_Environment == E_ASTRAL) {
	    if (Level->depth == 1) {
	      Level->site[x][y].locchar = RUBBLE;
	      Level->site[x][y].p_locf = L_RUBBLE;
	    }
	    else if (Level->depth == 2) {
	      Level->site[x][y].locchar = FIRE;
	      Level->site[x][y].p_locf = L_FIRE;
	    }
	    else if (Level->depth == 3) {
	      Level->site[x][y].locchar = WATER;
	      Level->site[x][y].p_locf = L_WATER;
	    }
	    else if (Level->depth == 4) {
	      Level->site[x][y].locchar = ABYSS;
	      Level->site[x][y].p_locf = L_ABYSS;
	    }
	  }
	  else {
	    Level->site[x][y].locchar = WATER;
	    Level->site[x][y].p_locf = L_WATER;
	  }
	}
      }
}