Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hangman by Bukz
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <stdlib.h>
- #include <time.h>
- #include <vector>
- using namespace std;
- // Sound stuff
- #ifndef __WIN32__
- #define _WIN32_WINNT 0x0500
- #include <tchar.h>
- #include <windows.h>
- #include <Wincon.h>
- #pragma comment(lib, "winmm.lib")
- // Console Colors
- #define FG_RED (FOREGROUND_RED | FOREGROUND_INTENSITY)
- #define FG_GREEN (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
- #define FG_BLUE (FOREGROUND_BLUE | FOREGROUND_INTENSITY)
- #define FG_YELLOW (FG_RED | FG_GREEN)
- #define FG_WHITE (FG_RED | FG_GREEN | FG_BLUE)
- #define FG_GRAY (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
- #define BG_RED (BACKGROUND_RED | BACKGROUND_INTENSITY)
- #define BG_GREEN (BACKGROUND_GREEN | BACKGROUND_INTENSITY)
- #define BG_BLUE (BACKGROUND_BLUE | BACKGROUND_INTENSITY)
- #define BG_YELLOW (BG_RED | BG_GREEN)
- #define BG_WHITE (BG_RED | BG_GREEN | BG_BLUE)
- #define BG_GRAY (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
- #define bg_blue_fg_white (FG_WHITE | BG_BLUE)
- #define bg_white_fg_black (BG_WHITE)
- #define bg_white_fg_red (BG_WHITE | FG_RED)
- #define bg_white_fg_green (BG_WHITE | FG_GREEN)
- #define bg_white_fg_yellow (BG_WHITE | FG_YELLOW)
- #define bg_white_fg_blue (BG_WHITE | FG_BLUE)
- #define bg_white_fg_gray (BG_WHITE | FG_GRAY)
- #define bg_red_fg_white (BG_RED | FG_WHITE)
- #define bg_green_fg_white (BG_GREEN | FG_WHITE)
- #define bg_yellow_fg_white (BG_YELLOW | FG_WHITE)
- #define bg_gray_fg_white (BG_GRAY | FG_WHITE)
- #define bg_gray_fg_blue (BG_GRAY | FG_BLUE)
- #define bg_gray_fg_yellow (BG_GRAY | FG_YELLOW)
- #define red() (SetConsoleTextAttribute(screen, bg_white_fg_red))
- #define redbg() (SetConsoleTextAttribute(screen, bg_red_fg_white))
- #define green() (SetConsoleTextAttribute(screen, bg_white_fg_green))
- #define greenbg() (SetConsoleTextAttribute(screen, bg_green_fg_white))
- #define blue() (SetConsoleTextAttribute(screen, bg_white_fg_blue))
- #define bluebg() (SetConsoleTextAttribute(screen, bg_blue_fg_white))
- #define white() (SetConsoleTextAttribute(screen, FG_WHITE))
- #define whitebg() (SetConsoleTextAttribute(screen, bg_white_fg_black))
- #define yellow() (SetConsoleTextAttribute(screen, bg_white_fg_yellow))
- #define yellowbg() (SetConsoleTextAttribute(screen, bg_yellow_fg_white))
- #define gray() (SetConsoleTextAttribute(screen, bg_white_fg_gray))
- #define graybg() (SetConsoleTextAttribute(screen, bg_gray_fg_white))
- #endif
- // Constants
- const int MAX_INCORRECT_GUESSES = 7;
- // Globals
- bool debug = false;
- bool draw = true;
- #ifndef __WIN32__
- bool sounds = true;
- #else
- bool sounds = false;
- #endif
- int incorrect;
- string word, maskedWord;
- vector <char> tried;
- vector <string> dictionary;
- vector <string> howto;
- // Protos
- void drawHangMan(int pos);
- void readWordsFile();
- void readHowToFile();
- void getInputLoop();
- void checkDigitInput(int input);
- void toggleDebug();
- void reseed(int msg = 0);
- #ifndef __WIN32__
- void toggleSound();
- #endif
- void viewDictionary();
- void about();
- void splashScreen();
- void doSpecialCommand(char input);
- bool isAlphaStr(string word);
- bool isUniqueStr(string word);
- int searchDictionary(string word);
- string genAlreadyGuessedStr();
- // Function definitions
- int rnd(int upperLimit) { return rand() % (upperLimit - 1) + 1; }
- void clearInput()
- {
- fflush(stdin);
- cin.clear();
- }
- void coutspace(string output) { cout << endl << output << endl << endl; }
- #ifndef __WIN32__
- void toggleSound()
- {
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- if(sounds) { PlaySound(NULL, 0, 0); sounds = false; red(); coutspace("Sounds disabled."); whitebg(); }
- else
- {
- sounds = true;
- green();
- coutspace("Sounds enabled.");
- whitebg();
- if(sounds) PlaySound(TEXT("sounds\\switch.wav"), NULL, SND_FILENAME | SND_ASYNC);
- }
- }
- #endif
- void readWordsFile()
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- #endif
- string line;
- ifstream file ("data\\words.txt");
- if(file.is_open())
- {
- while(file.good())
- {
- getline(file, line);
- dictionary.push_back(line);
- }
- file.close();
- #ifndef __WIN32__
- graybg();
- #endif
- cout << "Successfully read file: /data/words.txt" << endl;
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- else
- {
- #ifndef __WIN32__
- red();
- #endif
- cout << "Error opening file: \"/data/words.txt\" for reading." << endl;
- #ifndef __WIN32__
- whitebg();
- Sleep(5000);
- #endif
- exit(0);
- }
- }
- void readHowToFile()
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- #endif
- string line;
- ifstream file ("data\\howto.txt");
- if(file.is_open())
- {
- while(file.good())
- {
- getline(file, line);
- howto.push_back(line);
- }
- file.close();
- #ifndef __WIN32__
- graybg();
- #endif
- cout << "Successfully read file: /data/howto.txt" << endl << endl;
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- else
- {
- #ifndef __WIN32__
- red();
- #endif
- cout << "Error opening file: \"/data/howto.txt\" for reading." << endl;
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- }
- void howTo()
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- #endif
- if(howto.size())
- {
- #ifndef __WIN32__
- graybg();
- #endif
- cout << endl;
- for(unsigned int i = 0; i < howto.size(); i++)
- cout << "\t" << howto.at(i) << endl;
- cout << endl;
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- else
- {
- #ifndef __WIN32__
- red();
- #endif
- coutspace("Nothing in the how to for display.");
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- }
- void maskWord()
- {
- string tmp;
- for(unsigned int i = 0; i < word.length(); i++)
- tmp += '-';
- maskedWord = tmp;
- }
- string zapCase(string tmpword, int upper = 0)
- {
- string tmp;
- for(unsigned int i = 0; i < tmpword.length(); i++)
- {
- if(upper) tmp += toupper(tmpword.at(i));
- else tmp += tolower(tmpword.at(i));
- }
- return tmp;
- }
- int slen(string s) { return s.length(); }
- void newgame()
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- #endif
- splashScreen();
- #ifndef __WIN32__
- green();
- #endif
- cout << endl << "Starting Hangman...";
- #ifndef __WIN32__
- blue();
- #endif
- coutspace("Enter 0 (zero) for help...");
- #ifndef __WIN32__
- whitebg();
- #endif
- tried.clear();
- if(debug) cout << "There are " << dictionary.size() << " words to choose from." << endl;
- int wordPos = rnd(dictionary.size());
- word = zapCase(dictionary.at(wordPos), 1);
- if(debug) cout << "Word number " << wordPos + 1 << " has been randomly chosen." << endl;
- maskWord();
- incorrect = 0;
- getInputLoop();
- }
- void endGame(int won)
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- #endif
- char a = ' ';
- if(won)
- {
- #ifndef __WIN32__
- if(sounds) PlaySound(TEXT("sounds\\win.wav"), NULL, SND_FILENAME | SND_ASYNC);
- #endif
- cout<< endl;
- #ifndef __WIN32__
- greenbg();
- #endif
- cout << "You won! The word is " << word << ".";
- #ifndef __WIN32__
- whitebg();
- #endif
- cout << endl;
- }
- else
- {
- #ifndef __WIN32__
- if(sounds) PlaySound(TEXT("sounds\\lose.wav"), NULL, SND_FILENAME | SND_ASYNC);
- #endif
- cout << endl;
- #ifndef __WIN32__
- redbg();
- #endif
- cout << "You lost! The word was " << word << ".";
- #ifndef __WIN32__
- whitebg();
- #endif
- cout << endl;
- }
- while((tolower(a) != 'y') && (tolower(a) != 'n'))
- {
- clearInput();
- #ifndef __WIN32__
- blue();
- #endif
- cout << "Play again? y/n? ";
- #ifndef __WIN32__
- whitebg();
- #endif
- cin.get(a);
- }
- if(tolower(a) == 'y') newgame();
- else exit(0);
- }
- bool hasChar(char letter)
- {
- char tmp = toupper(letter);
- for(unsigned int i = 0; i < word.length(); i++)
- if(word.at(i) == tmp) { return true; break; }
- return false;
- }
- int countChars(char letter)
- {
- int times = 0;
- char tmp = toupper(letter);
- for(unsigned int i = 0; i < word.length(); i++)
- if(word.at(i) == tmp) times += 1;
- return times;
- }
- int countMaskedChars(string word)
- {
- int ctr = 0;
- for(unsigned int i = 0; i < word.length(); i++)
- if(word.at(i) == '-') ctr += 1;
- return ctr;
- }
- void updateWord(char letter)
- {
- string tmp, tmpchar;
- string oldmask = maskedWord;
- for(unsigned int i = 0; i < word.length(); i++)
- {
- if(word.at(i) == letter) tmp += word.at(i);
- else tmp += maskedWord.at(i);
- }
- maskedWord = tmp;
- if(debug)
- if(oldmask != maskedWord)
- cout << "Old mask " << oldmask << " has been updated to " << maskedWord << endl;
- }
- bool alreadyGuessed(char letter)
- {
- for(unsigned int i = 0; i < tried.size(); i++)
- if(tried.at(i) == letter) { return true; break; }
- return false;
- }
- string genAlreadyGuessedStr()
- {
- string tmp;
- for(unsigned int i = 0; i < tried.size(); i++)
- {
- tmp += tried.at(i);
- tmp += ' ';
- }
- return tmp;
- }
- void guess(char letter)
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- #endif
- char input = toupper(letter);
- if(!hasChar(input) || alreadyGuessed(input))
- {
- cout << endl;
- #ifndef __WIN32__
- redbg();
- #endif
- cout << "INCORRECT!";
- #ifndef __WIN32__
- whitebg();
- #endif
- cout << endl;
- #ifndef __WIN32__
- if(sounds) PlaySound(TEXT("sounds\\incorrect.wav"), NULL, SND_FILENAME | SND_ASYNC);
- #endif
- if(alreadyGuessed(input)) cout << endl << "You have already guessed: " << endl <<
- genAlreadyGuessedStr() << endl;
- else tried.push_back(input);
- incorrect++;
- if(draw) drawHangMan(incorrect);
- if(incorrect >= MAX_INCORRECT_GUESSES)
- {
- endGame(0);
- return;
- }
- #ifndef __WIN32__
- SetConsoleTextAttribute(screen, bg_gray_fg_yellow);
- #endif
- cout << endl << "You have " << MAX_INCORRECT_GUESSES - incorrect << " incorrect guesses remaining." << endl;
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- if(hasChar(input))
- {
- if(!alreadyGuessed(input))
- {
- cout << endl;
- #ifndef __WIN32__
- greenbg();
- #endif
- cout << "CORRECT!";
- #ifndef __WIN32__
- whitebg();
- #endif
- cout << endl;
- #ifndef __WIN32__
- if(sounds) PlaySound(TEXT("sounds\\correct.wav"), NULL, SND_FILENAME | SND_ASYNC);
- #endif
- tried.push_back(input);
- }
- updateWord(input);
- }
- if(word == maskedWord)
- {
- endGame(1);
- return;
- }
- getInputLoop();
- }
- void getInputLoop()
- {
- char input = '0';
- cout << endl << "Hint: " << maskedWord << " (" << word.length() << " characters, " <<
- word.length() - countMaskedChars(maskedWord) << " unmasked)" << endl << endl;
- while (!isalpha(input))
- {
- clearInput();
- cout << "Enter a letter (A-Z): ";
- cin.get(input);
- if(isdigit(input)) checkDigitInput(input);
- doSpecialCommand(input);
- }
- guess(input);
- }
- void checkDigitInput(int input)
- {
- char a = '0';
- string tmp;
- switch(input)
- {
- case '1': newgame(); return; break;
- case '2': toggleDebug(); break;
- case '3':
- cout << endl << "Current Game Information" << endl << "------------------------" << endl;
- cout << endl << "\tHint" << endl << "\t----" << endl << "\t" << maskedWord <<
- " (" << word.length() << " characters, " << word.length() - countMaskedChars(maskedWord) << " unmasked)" << endl << "\t----"<< endl;
- cout << endl << "\tIncorrect" << endl << "\t---------" << endl <<
- "\tYou have " << MAX_INCORRECT_GUESSES - incorrect << " incorrect guesses remaining." <<
- endl << "\t---------" << endl;
- cout << endl << "\tAlready Guessed" << endl << "\t---------------" << endl;
- if(slen(genAlreadyGuessedStr()))
- cout << "\t" << genAlreadyGuessedStr();
- else cout << "\tNONE";
- coutspace("\t---------------");
- break;
- case '4':
- #ifndef __WIN32__
- if(debug && sounds) PlaySound(TEXT("sounds\\dictionary.wav"), NULL, SND_FILENAME | SND_ASYNC);
- #endif
- viewDictionary();
- break;
- case '5':
- if(debug)
- {
- while(!isalpha(a))
- {
- clearInput();
- cout << "Enter a letter to check the current word for: ";
- cin.get(a);
- }
- if(hasChar(a)) cout << endl << "The current word has " <<
- countChars(a) << " " << a << "'s in it." << endl << endl;
- else cout << endl << "Could not find " << a << " in the current word." << endl << endl;
- }
- else coutspace("Debug mode must be on to do a letter search.");
- break;
- case '6':
- if(debug)
- {
- while(slen(tmp) < 2 || !isAlphaStr(tmp) || !isUniqueStr(tmp))
- {
- clearInput();
- coutspace("Enter a word to check the dictionary for:");
- getline(cin, tmp);
- }
- if(searchDictionary(tmp) > -1) cout << endl << "Word number " << searchDictionary(tmp) <<
- " - \"" << tmp << "\" was found in the dictionary." << endl << endl;
- else coutspace("Could not find that word in the dictionary.");
- }
- else coutspace("Debug mode must be on to do a dictionary search.");
- break;
- case '7': reseed(1); break;
- case '8':
- if(draw) { draw = false; coutspace("Draw hangman turned off."); }
- else { draw = true; coutspace("Draw hangman turned on."); }
- #ifndef __WIN32__
- if(sounds) PlaySound(TEXT("sounds\\switch.wav"), NULL, SND_FILENAME | SND_ASYNC);
- #endif
- break;
- case '9':
- #ifndef __WIN32__
- if(sounds)
- {
- coutspace("Goodbye!");
- PlaySound(TEXT("sounds\\quit.wav"), NULL, SND_FILENAME | SND_ASYNC);
- Sleep(4500);
- }
- #endif
- exit(0);
- break;
- default:
- cout << endl << "Help" << endl << "----" << endl <<
- "Enter 1 to start a new game." << endl <<
- "Enter 2 to toggle debug mode." << endl <<
- "Enter 3 to view information about the current game." << endl <<
- "Enter 4 to view the dictionary." << endl <<
- "Enter 5 to search the current word for a letter." << endl <<
- "Enter 6 to search the dictionary for a word." << endl <<
- "Enter 7 to reseed the random number generator." << endl <<
- "Enter 8 to toggle the drawing of hangman after each incorrect guess." << endl <<
- "Enter 9 to quit the game." << endl << endl <<
- "Other Special Commands" << endl << "----------------------" << endl <<
- "Enter ~ to view information about the program." << endl <<
- "Enter ! to toggle game sounds on/off." << endl <<
- "Enter ? to view a how to of the game.";
- coutspace("----------------------");
- break;
- }
- }
- void doSpecialCommand(char input)
- {
- switch(input)
- {
- case '~': about(); break;
- case '!':
- #ifndef __WIN32__
- toggleSound();
- #endif
- break;
- case '?': howTo(); break;
- default: break;
- }
- }
- bool isAlphaStr(string word)
- {
- bool valid = true;
- char curchar;
- for(unsigned int i = 0; i < word.length(); i++)
- {
- curchar = word.at(i);
- if(!isalpha(curchar)) { valid = false; break; }
- }
- return valid;
- }
- bool isUniqueStr(string word)
- {
- if(word.length())
- {
- char fchar = word.at(0);
- char curchar;
- int ctr = 0;
- for(unsigned int i = 0; i < word.length(); i++)
- {
- if(i)
- {
- curchar = word.at(i);
- if(fchar != curchar) { break; }
- else { ctr += 1; }
- }
- }
- if(ctr == (word.length() - 1)) return false;
- else return true;
- }
- return false;
- }
- void viewDictionary()
- {
- if(debug)
- {
- cout << endl << "Dictionary (" << dictionary.size() << ")" << endl << "----------" << endl;
- for(unsigned int i = 0; i < dictionary.size(); i++)
- cout << i + 1 << ". " << dictionary.at(i) << endl;
- cout << "----------" << endl;
- }
- else coutspace("To view the dictionary debug mode must be on.");
- }
- int searchDictionary(string word)
- {
- int tmp = -1;
- string tmpword = zapCase(word, 1);
- string dictword;
- for(unsigned int i = 0; i < dictionary.size(); i++)
- {
- dictword = zapCase(dictionary.at(i), 1);
- if(tmpword == dictword) { tmp = i; break; }
- }
- return tmp;
- }
- void toggleDebug()
- {
- if(debug) { debug = false; coutspace("Debug mode off."); }
- else { debug = true; coutspace ("Debug mode on."); }
- if(sounds) PlaySound(TEXT("sounds\\switch.wav"), NULL, SND_FILENAME | SND_ASYNC);
- }
- void reseed(int msg)
- {
- srand(static_cast<int>(time(NULL)));
- if(debug || msg) coutspace("Random number generator srand() has been reseeded.");
- }
- void drawHangMan(int pos)
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(screen, bg_gray_fg_blue);
- #endif
- switch(pos)
- {
- case 1:
- cout << endl << "/---------" << endl <<
- "| |" << endl <<
- "| O" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl << endl;
- break;
- case 2:
- cout << endl << "/---------" << endl <<
- "| |" << endl <<
- "| O" << endl <<
- "| |" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl << endl;
- break;
- case 3:
- cout << endl << "/---------" << endl <<
- "| |" << endl <<
- "| O" << endl <<
- "| \\|" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl << endl;
- break;
- case 4:
- cout << endl << "/---------" << endl <<
- "| |" << endl <<
- "| O" << endl <<
- "| \\|/" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl << endl;
- break;
- case 5:
- cout << endl << "/---------" << endl <<
- "| |" << endl <<
- "| O" << endl <<
- "| \\|/" << endl <<
- "| |" << endl <<
- "|" << endl <<
- "|" << endl <<
- "|" << endl << endl;
- break;
- case 6:
- cout << endl << "/---------" << endl <<
- "| |" << endl <<
- "| O" << endl <<
- "| \\|/" << endl <<
- "| |" << endl <<
- "| /" << endl <<
- "|" << endl <<
- "|" << endl << endl;
- break;
- default:
- cout << endl << "/---------" << endl <<
- "| |" << endl <<
- "| O" << endl <<
- "| \\|/" << endl <<
- "| |" << endl <<
- "| / \\" << endl <<
- "|" << endl <<
- "|" << endl << endl;
- break;
- }
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- void splashScreen()
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- red();
- if(sounds) PlaySound(TEXT("sounds\\splash.wav"), NULL, SND_FILENAME | SND_ASYNC);
- #endif
- cout << endl <<
- " _ _ __ __" << endl <<
- "| | | | | \\/ |" << endl <<
- "| |__| | __ _ _ __ __ _| \\ / | __ _ _ __" << endl <<
- "| __ |/ _` | '_ \\ / _` | |\\/| |/ _` | '_ \\" << endl <<
- "| | | | (_| | | | | (_| | | | | (_| | | | |" << endl <<
- "|_| |_|\\__,_|_| |_|\\__, |_| |_|\\__,_|_| |_|" << endl <<
- " __/ |" << endl <<
- " |___/ ";
- #ifndef __WIN32__
- blue();
- #endif
- cout << "-By Bukz" << endl;
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- void about()
- {
- #ifndef __WIN32__
- HANDLE screen;
- screen = GetStdHandle(STD_OUTPUT_HANDLE);
- red();
- #endif
- cout << endl << "\tAbout HangMan";
- coutspace("\t-------------");
- cout << "\tHangMan version 2.1" << endl;
- cout << "\tWritten in C++ by ";
- #ifndef __WIN32__
- blue();
- #endif
- cout << "Shane \"Bukz\" Pinkley" << endl << endl;
- #ifndef __WIN32__
- red();
- #endif
- cout << "\tLicensed under the Attribution-NonCommercial-ShareAlike" << endl << "\t3.0 Unported (CC BY-NC-SA 3.0) creative commons license." << endl << endl <<
- "\tFor more information about the license visit:" << endl << endl;
- #ifndef __WIN32__
- blue();
- #endif
- cout << "\t\thttp://creativecommons.org/licenses/by-nc-sa/3.0/" << endl << endl;
- #ifndef __WIN32__
- red();
- #endif
- cout << "\tAll sounds were taken from:" << endl << endl;
- #ifndef __WIN32__
- blue();
- #endif
- cout << "\t\thttp://www.freesound.org" << endl << endl;
- #ifndef __WIN32__
- red();
- #endif
- cout << "\tand are licensed under the Sampling Plus 1.0 creative" << endl << "\tcommons license." << endl << endl <<
- "\tFor more information about the license visit:" << endl << endl;
- #ifndef __WIN32__
- blue();
- #endif
- cout << "\t\thttp://creativecommons.org/licenses/sampling+/1.0/" << endl << endl;
- #ifndef __WIN32__
- red();
- #endif
- cout << "\t2011 All Rights Reserved" << endl;
- coutspace("\t-------------");
- #ifndef __WIN32__
- whitebg();
- #endif
- }
- #ifndef __WIN32__
- void screenFun()
- {
- // For console title
- SetConsoleTitle(_T("Hangman 2.1 by Bukz"));
- // For console full screen workaround
- HANDLE hOut;
- COORD NewSBSize;
- SMALL_RECT Area = {0, 0, 0, 0};
- hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- NewSBSize = GetLargestConsoleWindowSize(hOut);
- SetConsoleScreenBufferSize(hOut, NewSBSize);
- Area.Right = NewSBSize.X - 1;
- Area.Bottom = NewSBSize.Y - 1;
- SetConsoleWindowInfo(hOut, TRUE, &Area);
- // For console auto-maximize
- HWND hWnd = GetConsoleWindow();
- ShowWindow(hWnd,SW_SHOWMAXIMIZED);
- // For console colors
- system("color f0");
- }
- #endif
- void init()
- {
- #ifndef __WIN32__
- // Setup the screen
- screenFun();
- #endif
- // Read words.txt and howto.txt
- readWordsFile();
- readHowToFile();
- // Seed the random number generator
- reseed();
- newgame();
- }
- int main()
- {
- init();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment