Creative Commons License Foxbond's Repo

/** (c) 2012 Michał (Foxbond) Chraniuk */
#include <cstdlib>
#include <time.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <conio.h>

using namespace std;

void drawSpace (int count) { for (int __i=0;count >__i;__i++)cout<<" "; }

void cls () { system("cls"); }

void sendError (string txt) {
	 //system("cls");
	 cout << txt<<"\n";
	 system("pause");
	 exit(1);
}

void drawLogo () {
	 cout << "         _________ _______ _________ _______  _        _______  _______ \n";
	 cout << "|\\     /|\\__   __/(  ____ \\\\__   __/(  ____ \\( \\      (  ____ \\(  ____ \\\n";
	 cout << "| )   ( |   ) (   | (    \\/   ) (   | (    \\/| (      | (    \\/| (    \\/\n";
	 cout << "| | _ | |   | |   | (_____    | |   | (__    | |      | (__    | |      \n";
	 cout << "| |( )| |   | |   (_____  )   | |   |  __)   | |      |  __)   | |      \n";
	 cout << "| || || |   | |         ) |   | |   | (      | |      | (      | |      \n";
	 cout << "| () () |___) (___/\\____) |___) (___| (____/\\| (____/\\| (____/\\| (____/\\\n";
	 cout << "(_______)\\_______/\\_______)\\_______/(_______/(_______/(_______/(_______/\n";
}

void drawImage (int level, bool clear=false) {
     if (clear) cls();
     if (level == 1) {
        cout << "              \n";
        cout << "              \n";
        cout << "              \n";
        cout << "              \n";
        cout << "              \n";
        cout << "              \n";
        cout << "              \n";
        cout << "              \n";
        cout << "  *           \n";
        cout << " * *          \n";
        cout << "*   *         \n"; 
     }
     else if (level == 2) {
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << " * *          \n";
        cout << "*   *         \n";
     }
     else if (level == 3) {
        cout << "  **********  \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << " * *          \n";
        cout << "*   *         \n";
     }
     else if (level == 4) {
        cout << "  **********  \n";
        cout << "  *  *        \n";
        cout << "  * *         \n";
        cout << "  **          \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << " * *          \n";
        cout << "*   *         \n";
     }
     else if (level == 5) {
        cout << "  **********  \n";
        cout << "  *  *     *  \n";
        cout << "  * *      *  \n";
        cout << "  **       0  \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << "  *           \n";
        cout << " * *          \n";
        cout << "*   *         \n";
     }
     else if (level == 6) {
        cout << "  **********  \n";
        cout << "  *  *     *  \n";
        cout << "  * *     *** \n";
        cout << "  **      *** \n";
        cout << "  *        *  \n";
        cout << "  *      *****\n";
        cout << "  *      * * *\n";
        cout << "  *        *  \n";
        cout << "  *       * * \n";
        cout << " * *     *   *\n";
        cout << "*   *         \n";
     }
     else {
        for (int __c=0;11>__c;__c++){drawSpace(14);cout<<"\n";}
     }
}

short signed int difficultyLevel = 1;
string *words = new string[1420];
int wordsCounter = -1; //nr ostatniego elementu

bool loadData () {
     
    fstream plik;
	ostringstream ss;
	ss << difficultyLevel;
	string filenum = ss.str();
    string filename = "wyrazy"+filenum+".txt";
    string *wordss = new string[1420];
    wordsCounter = -1; 
    int __f = 0;
    plik.open( filename.c_str(), ios::in );
    if( plik.good() )
    {
        while( !plik.eof() )
        {
  	 	    
            getline( plik, wordss[__f++] );
            wordsCounter++;
        }
        plik.close();
        words = wordss;
        wordss = NULL;
        return true;
    } else return false;
}

int main(int argc, char *argv[])
{
    
    short int mainAction = 0;
    srand(time(NULL));
    bool win = false;
    bool cheatActive = false;
    
    do {
        
        if (mainAction == 256) { if (cheatActive) { cheatActive = false; }else{ cheatActive = true; } }
        if (mainAction > 6) {
	   	   cls();
	   	   drawLogo();
	   	   cout << "\nNieprawidlowa wartosc! Kliknij dowolny klawisz, aby kontynuowac\n";
	   	   getch();
	   	   mainAction = 0;
	   	   cls();
		}
        
        if (mainAction != 0) {
            
            difficultyLevel = mainAction;
            if (!loadData()){sendError("Wystapil blad podczas ladowania wyrazow. Program zakonczy swoje dzialanie.");}
            int wordSelect = rand() % wordsCounter;
            string selectedWord = words[wordSelect];
            string selectedWordCopy = selectedWord;
            int charCounter = selectedWord.size();
            string usedBadWords, usedGoodWords, displayWord;
            string allowedChars = "abcdefghijklmnoqprstuwxyz";
            char selectedChar[] = "";
            int level = 0;
            for (int __d = 0;__d<charCounter;__d++) displayWord.append("*");
            do{
		  		drawImage(level);
		  		
		  		if (cheatActive) cout << "     Wyraz     : " << displayWord << " <-- "<< selectedWordCopy <<"\n";
		  		   else cout << "     Wyraz     : " << displayWord<<"\n";
		  		cout << "  Uzyte litery : " << usedBadWords <<"\n";
		  		
		  		//jesli juz odgadl
		  		if (selectedWordCopy.find(displayWord) != string::npos) {
  				   win = true;
  				   break;
  				   
				}
		  		cout << "Nastepna litera: ";
				cin >> selectedChar;
				//cin.get(selectedChar, 1);									  
				while((usedBadWords.find(selectedChar) != string::npos) || (usedGoodWords.find(selectedChar) != string::npos) || (allowedChars.find(selectedChar) == string::npos)) {
					if (allowedChars.find(selectedChar) == string::npos) {
					   cout << "Podany znak nie jest litera! Podaj inny:\n";
   		   			} else {
					  cout << "Juz sprawdzales te litere! Podaj inna:\n";
					}
					cin >> selectedChar;
			 	}
				
				if (selectedWord.find(selectedChar) == string::npos) { 
				   level++;
				   //usedBadWords[usedBadWordsC++] = selectedChar[0];
				   usedBadWords.append(selectedChar);
				}else{
				   short int pos = -1;
				   usedGoodWords.append(selectedChar);
				   do{
	   		 	   	  pos = selectedWord.find(selectedChar, pos++);
	   		 	   	  if (pos >=0) { displayWord.replace(pos, 1, selectedChar);  selectedWord.replace(pos, 1, "*"); }
				   }while(pos != -1);
				   
				}
				cls();
  		    }while (level < 6);
  		    cls();
  		    if (!win) {
            drawLogo();
            cout << "\nPrzegrales! Kliknij dowolny klawisz, aby sprobowac ponownie\n";
			}else {
	  		drawLogo();
	  		cout << "\nWygrales! Kliknij dowolny klawisz, aby sprobowac ponownie\n";
			}         
			getch();
			cls(); 
        }
        
        drawLogo();
        cout << "\nWybierz kategorie:\n1.Owoce (latwe)\n2.Panstwa\n3.Zawody\n4.Zwierzeta\n5.Imiona (bardzo trudne)\n0.Wyjscie\nWSZYSTKIE SLOWA BEZ POLSKICH LITER!\n";
        cin >> mainAction;
        cls();
    }while(mainAction != 0);
    
    
    return EXIT_SUCCESS;
}

> Back