Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef HEADER_H_INCLUDED
- #define HEADER_H_INCLUDED
- #include <fstream>
- #include<string>
- #include<vector>
- using namespace std;
- int getRandomNumber(int level,int lines[])
- {
- int low, high;
- if(level == 1)
- {
- low = 2;
- high = lines[1];
- }
- else if(level == 2)
- {
- low = lines[1]+1;
- high = lines[2];
- }
- else if(level == 3)
- {
- low = lines[2]+1;
- high = lines[3];
- }
- srand ( time(NULL) );
- int line = rand() % (high - low) + low;
- return line;
- }
- string getWord(const char fileName[], int level, int lines[])
- {
- ifstream fd(fileName);
- string temp;
- for(int i = 1; i<=getRandomNumber(level, lines); i++)
- {
- getline(fd,temp);
- }
- return temp;
- }
- void fileRead(int lines[], const char fileName[])
- {
- ifstream fin(fileName);
- for(int i = 0; i<4; i++)
- {
- fin >> lines[i];
- }
- }
- int selectLevel()
- {
- int temp;
- cout << "Iveskite norima sunkumo lygi(1-3): " << endl;
- cin >> temp;
- if(temp <1 || temp >3) selectLevel();
- else return temp;
- }
- char enterGuess(char &guess)
- {
- string temp;
- cout << "Enter your guess: " << endl;
- getline(cin, temp);
- if(temp.size()>1)
- {
- cout << "Error! Tip: Enter only 1 letter" << endl;
- enterGuess(guess);
- }
- else guess = temp[0];
- }
- bool isCorrect(string word, char guess, string &text)
- {
- bool temp = false;
- for(int i = 0; i <word.size(); i++)
- {
- if(word[i] == guess){
- text[i] = guess;
- temp = true;
- }
- }
- if(temp == true) return true;
- return false;
- }
- void drawGuesses(char guesses[], int gIndex)
- {
- for(int i = 0; i <=gIndex;i++)
- {
- if(guesses[i] >= 97 && guesses[i] <=122){
- cout << guesses[i];
- }
- }
- }
- void draw(int &lives, string word, char guesses[], int &gIndex, string &text)
- {
- system("cls");
- cout << text << endl;
- cout << "\t Lives: " << lives << endl;
- cout << "\t Guesses: ";
- drawGuesses(guesses, gIndex);
- cout << endl;
- char guess;
- enterGuess(guess);
- isCorrect(word, guess, text);
- if(!isCorrect(word,guess,text)) lives--;
- guesses[gIndex] = guess;
- gIndex++;
- }
- bool isSessionOver(int lives, string text, bool &pergale)
- {
- if(lives == 0){
- pergale = false;
- return true;
- }
- else if(true){
- for(int i = 0; i<text.size();i++)
- {
- if(text[i] == '_') return false;
- }
- pergale= true;
- return true;
- }
- else return false;
- }
- void endGame(bool &gameOver)
- {
- char choice;
- cin >> choice;
- if(choice == 'Y' || choice =='y')
- {
- gameOver = false;
- }
- else if(choice == 'N' || choice =='n')
- {
- gameOver = true;
- }
- else{
- cout << "Error! Please try entering it again." << endl;
- endGame(gameOver);
- }
- }
- #endif // HEADER_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement