Created
February 9, 2022 07:30
-
-
Save armm29393/d3a9150d26da995b2700b153ab5a3406 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| //#include <stdio.h> | |
| #include <conio.h> | |
| using namespace std; | |
| int m,w,num,guess,i; | |
| int maxplay; | |
| char mSelect[1],txt[10]; | |
| void count(); | |
| void gametitle(); | |
| void welcome(); | |
| void lose(); | |
| void win(); | |
| void level(); | |
| int play(); | |
| //void play(); | |
| void mode(); | |
| void thx(); | |
| void changelog(); | |
| main(){ | |
| system("mode con:cols=151 lines=41"); | |
| system("title Guess the number game by Arm"); | |
| char P1[10],P2[10]; | |
| srand(time(NULL)); | |
| system((rand()%2!=0)?"COLOR 0E":"COLOR 0A"); | |
| welcome(); | |
| char g=getch(); | |
| if (g=='l') changelog(); | |
| if (g=='x') exit(0); | |
| play: | |
| mode(); | |
| system("COLOR F9"); | |
| system("cls"); | |
| gametitle(); | |
| if (m==2) | |
| { | |
| cout << "\n\n\tEnter player 1 name: "; | |
| cin >> P1; | |
| cout << "\n\tEnter player 2 name: "; | |
| cin >> P2; | |
| } else { | |
| cout << "\n\n\tEnter your name: "; | |
| cin >> P1; | |
| } | |
| w=0; | |
| maxplay=10; | |
| //if (m==2) maxplay /= 2; | |
| count(); | |
| system("cls"); | |
| if (m==2 && guess%2!=0) //optional | |
| { | |
| cout << " user is swaped! [mod(2)!=0]\n"; //test | |
| i=0;while((txt[i]=P1[i]) != '\0'){++i;} | |
| i=0;while((P1[i]=P2[i]) != '\0'){++i;} | |
| i=0;while((P2[i]=txt[i]) != '\0'){++i;} | |
| } | |
| cout << " guess=" << guess << "\n maxplay=" << maxplay << "\n (For Debug Only!)"; //test | |
| gametitle(); | |
| int cp; | |
| while( (maxplay>0) || (cp!=1) ) { | |
| maxplay--; | |
| system("COLOR 5F"); | |
| cout << "\n\n\t[�] " << P1 << "'s turn : "; | |
| cp=play(); | |
| if (cp==1){ | |
| i=0;while((txt[i]=P1[i]) != '\0'){++i;} | |
| win(); | |
| } | |
| if (m==2 && w!=1){ | |
| system("COLOR 8F"); | |
| cout << "\n\n\t[�] " << P2 << "'s turn : "; | |
| cp=play(); | |
| if (cp==1){ | |
| i=0;while((txt[i]=P2[i]) != '\0'){++i;} | |
| win(); | |
| } | |
| } | |
| if(maxplay!=0 && w!=1){ | |
| cout << "\n\t\t\t\t\t\t\t\t * " << maxplay << " time(s) to guess *" << endl; | |
| } else if(maxplay==0 && w!=1){ | |
| lose();break; | |
| } if(w==1){ | |
| win();break; | |
| } | |
| } | |
| cout << "\n\n\n\n\n\n\t\t Play again? : [ ] (Y/N)\b\b\b\b\b\b\b\b"; | |
| char p; | |
| p=getche(); | |
| system("pause>nul"); | |
| //gets(p); | |
| switch(p){ | |
| case 'y':case'Y': goto play; | |
| default:thx(); | |
| } | |
| } | |
| void mode(){ | |
| mode: | |
| m=0; | |
| system("COLOR 9F"); | |
| system("cls"); | |
| gametitle(); | |
| cout << "\n\n"; | |
| cout << "\n\t--------------------------------------------"; | |
| cout << "\n\t- Select mode -"; | |
| cout << "\n\t--------------------------------------------"; | |
| cout << "\n\n\t [1] - 1 Player"; | |
| cout << "\n\n\t [2] - 2 Players"; | |
| cout << "\n\n\t--------------------------------------------"; | |
| cout << "\n\n\t [X] - EXiT"; | |
| cout << "\n\n\n\t\t Select = [ ]\b\b"; | |
| //cin >> m; | |
| //mSelect[0]='\0'; | |
| gets(mSelect); | |
| //m=getche(); | |
| //system("pause>nul"); | |
| /*if(m==1||m==2) | |
| else if(m==88||m==120) | |
| system("exit"); | |
| else | |
| goto mode;*/ | |
| switch(mSelect[0]){ | |
| case '1':m=1;level();break; | |
| case '2':m=2;level();break; | |
| case 'x':case 'X':exit(1);break; //88.120 | |
| default:goto mode;break; | |
| } | |
| } | |
| void level(){ | |
| level: | |
| int maxguess; | |
| system("COLOR E0"); | |
| system("cls"); | |
| gametitle(); | |
| cout << "\n\t\t\t\t\t\t\t\t [ " << m << " Player(s) Mode ]"; | |
| cout << "\n\t--------------------------------------------"; | |
| cout << "\n\t- Select level -"; | |
| cout << "\n\t--------------------------------------------"; | |
| cout << "\n\n\t [1] - Very Easy [1-10] (NOOB!)"; | |
| cout << "\n\n\t [2] - Easy [1-20]"; | |
| cout << "\n\n\t [3] - Normal [1-50]"; | |
| cout << "\n\n\t [4] - Hard [1-100]"; | |
| cout << "\n\n\t [5] - EXTREME HARD!! [1-500]"; | |
| cout << "\n\n\t--------------------------------------------"; | |
| cout << "\n\n\t [X] - EXiT"; | |
| cout << "\n\n\n\t\t Select = [ ]\b\b"; | |
| //cin >> l; | |
| //l = getche(); | |
| char l[1]; | |
| gets(l); | |
| //system("pause>nul"); | |
| switch(l[0]){ | |
| case '1':maxguess=10;break; | |
| case '2':maxguess=20;break; | |
| case '3':maxguess=50;break; | |
| case '4':maxguess=100;break; | |
| case '5':maxguess=500;break; | |
| case 'x':case 'X':exit(1);break; | |
| default:goto level;break; | |
| } | |
| srand(time(NULL)); | |
| guess = rand() % maxguess + 1; | |
| } | |
| int play(){ | |
| int a; | |
| cin >> num; | |
| if(num<guess){ | |
| cout << "\t[>] Greater than " << num << endl; | |
| a=0; | |
| } else if(num>guess){ | |
| cout << "\t[<] Less than " << num << endl; | |
| a=0; | |
| } else if(num=guess){ | |
| win(); | |
| a=1; | |
| w=1; | |
| } | |
| return a; | |
| } | |
| void gametitle(){ // Guess the Number GAME! | |
| cout << "\n"; | |
| cout << "\n ������+ ��+ ��+ �������+ �������+ �������+ ��������+ ��+ ��+ �������+ ���+ ��+ ��+ ��+ ���+ ���+ ������+ �������+ ������+ "; | |
| cout << "\n ��+----+ ��� ��� ��+----+ ��+----+ ��+----+ +--��+--+ ��� ��� ��+----+ ����+ ��� ��� ��� ����+ ����� ��+--��+ ��+----+ ��+--��+"; | |
| cout << "\n ��� ���+ ��� ��� �����+ �������+ �������+ ��� �������� �����+ ��+��+ ��� ��� ��� ��+����+��� ������++ �����+ ������++"; | |
| cout << "\n ��� ��� ��� ��� ��+--+ +----��� +----��� ��� ��+--��� ��+--+ ���+��+��� ��� ��� ���+��++��� ��+--��+ ��+--+ ��+--��+"; | |
| cout << "\n +������++ +������++ �������+ �������� �������� ��� ��� ��� �������+ ��� +����� +������++ ��� +-+ ��� ������++ �������+ ��� ���"; | |
| cout << "\n +-----+ +-----+ +------+ +------+ +------+ +-+ +-+ +-+ +------+ +-+ +---+ +-----+ +-+ +-+ +-----+ +------+ +-+ +-+"; | |
| cout << "\n"; | |
| cout << "\n\t\t\t\t\t\t ������+ �����+ ���+ ���+ �������+ ��+"; | |
| cout << "\n\t\t\t\t\t\t ��+----+ ��+--��+ ����+ ����� ��+----+ ���"; | |
| cout << "\n\t\t\t\t\t\t ��� ���+ �������� ��+����+��� �����+ ���"; | |
| cout << "\n\t\t\t\t\t\t ��� ��� ��+--��� ���+��++��� ��+--+ +-+"; | |
| cout << "\n\t\t\t\t\t\t +������++ ��� ��� ��� +-+ ��� �������+ ��+"; | |
| cout << "\n\t\t\t\t\t\t +-----+ +-+ +-+ +-+ +-+ +------+ +-+"; | |
| cout << "\n\n"; | |
| for(int i=0;i<151;i++) cout << "="; | |
| } | |
| void welcome(){ // Welcome To | |
| system("cls"); | |
| cout << "\n\t\t\t\t��+ ��+ �������+ ��+ ������+ ������+ ���+ ���+ �������+ ��������+ ������+ "; | |
| cout << "\n\t\t\t\t��� ��� ��+----+ ��� ��+----+ ��+---��+ ����+ ����� ��+----+ +--��+--+ ��+---��+"; | |
| cout << "\n\t\t\t\t��� �+ ��� �����+ ��� ��� ��� ��� ��+����+��� �����+ ��� ��� ���"; | |
| cout << "\n\t\t\t\t������+��� ��+--+ ��� ��� ��� ��� ���+��++��� ��+--+ ��� ��� ���"; | |
| cout << "\n\t\t\t\t+���+���++ �������+ �������+ +������+ +������++ ��� +-+ ��� �������+ ��� +������++"; | |
| cout << "\n\t\t\t\t +--++--+ +------+ +------+ +-----+ +-----+ +-+ +-+ +------+ +-+ +-----+ "; | |
| gametitle(); | |
| cout << "\n\t\t\t\t\t\t [-] This game written in C++ [-]"; | |
| cout << "\n\t\t\t\t\t\t [-] [-]"; | |
| cout << "\n\t\t\t\t\t\t [-] by Pawarit Thong-ek (5911020660022) [-]"; | |
| cout << "\n\n\n\n\tPress any key to Start or Press [X] to quit.."; | |
| cout << "\n\n\n\n\n\n\n"; | |
| cout << "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; | |
| cout << " Version 1.1.2"; | |
| cout << "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; | |
| cout << " Press [L] to view changelog"; | |
| cout << "\n"; | |
| //system("pause>nul"); | |
| } | |
| void changelog(){ // Changelog | |
| system("COLOR 3F"); | |
| system("cls"); | |
| //gametitle(); | |
| cout << "\n\t\t\t\t\t\t\t\t | Guess Number Game! ]\n\n\t\t\t\t\t\t\t\t\t [ Changelog ]"; | |
| cout << "\n\n\t\t Version 1.1.2\t(Release)\t[08-11-2016 7:18AM]"; | |
| cout << "\n\t\t [-] Changed: Exit menu"; | |
| cout << "\n\t\t [!] Fixed: Minor Bug"; | |
| cout << "\n\n\t\t Version 1.1\t(Release)\t[08-11-2016 1:10AM]"; | |
| cout << "\n\t\t [+] Added: Changelog screen < This screen :) >"; | |
| cout << "\n\n\t\t Version 1.06\t(Alpha)\t\t[07-11-2016]"; | |
| cout << "\n\t\t [+] Added: \'Press [X] to exit\'"; | |
| cout << "\n\t\t [!] Fixed: Selection submit bug (Press number and enter)"; | |
| cout << "\n\n\t\t Version 1.02\t(Alpha)\t\t[06-11-2016 Evening]"; | |
| cout << "\n\t\t [!] Fixed: Some BUG!"; | |
| cout << "\n\n\t\t Version 1.0b\t(Release)\t[06-11-2016 Morning]"; | |
| cout << "\n\t\t [�] First Release version :)"; | |
| cout << "\n\n\t\t Version 0.9\t(Beta)\t\t[05-11-2016]"; | |
| cout << "\n\t\t [!] Fixed: Gameplay bug - infinite loop :("; | |
| cout << "\n\t\t [-] Changed: Welcome Screen 2 Colors"; | |
| cout << "\n\n\t\t Version 0.2\t(Alpha)\t\t[04-11-2016]"; | |
| cout << "\n\t\t [+] Added: Welcome Screen"; | |
| cout << "\n\t\t [+] Added: Main Gameplay Function"; | |
| cout << "\n\t\t [+] Added: Multiplayer Function"; | |
| cout << "\n\t\t [+] Added: Mode selection"; | |
| cout << "\n\n\t\t Version 0.1\t(Pre-alpha)\t[03-11-2016]"; | |
| cout << "\n\t\t [+] Added: \'You WIN!\' & \'GAME OVER!\' Screen"; | |
| cout << "\n\n\n\n\t Press any key to START GAME!! or Press [X] to quit.."; | |
| //system("pause>nul"); | |
| char x; | |
| x=getch(); | |
| if (x=='x'||x=='X') { | |
| exit(0); | |
| } else { | |
| //goto play; | |
| } | |
| } | |
| void win(){ // You WIN! | |
| system("COLOR 2F"); | |
| system("cls"); | |
| cout << "\n\n\n\n\n\n\n\n\n\n\n"; | |
| cout << "\n\t\t\t\t\t /$$ /$$ /$$ /$$ /$$$$$$ /$$ /$$ /$$ /$$"; | |
| cout << "\n\t\t\t\t\t| $$ /$$/ | $$ /$ | $$|_ $$_/| $$$ | $$ | $$| $$"; | |
| cout << "\n\t\t\t\t\t \\ $$ /$$//$$$$$$ /$$ /$$ | $$ /$$$| $$ | $$ | $$$$| $$ | $$| $$"; | |
| cout << "\n\t\t\t\t\t \\ $$$$//$$__ $$| $$ | $$ | $$/$$ $$ $$ | $$ | $$ $$ $$ | $$| $$"; | |
| cout << "\n\t\t\t\t\t \\ $$/| $$ \\ $$| $$ | $$ | $$$$_ $$$$ | $$ | $$ $$$$ |__/|__/"; | |
| cout << "\n\t\t\t\t\t | $$ | $$ | $$| $$ | $$ | $$$/ \\ $$$ | $$ | $$\\ $$$ "; | |
| cout << "\n\t\t\t\t\t | $$ | $$$$$$/| $$$$$$/ | $$/ \\ $$ /$$$$$$| $$ \\ $$ /$$ /$$"; | |
| cout << "\n\t\t\t\t\t |__/ \\______/ \\______/ |__/ \\__/|______/|__/ \\__/ |__/|__/"; | |
| cout << "\n\n\n\t\t\t\t\t\t\t\t " << txt << " is the winner!!"; | |
| } | |
| void lose(){ // GAME OVER! | |
| system("COLOR 4F"); | |
| system("cls"); | |
| cout << "\n\n\n\n\n\n\n\n\n"; | |
| cout << "\n\t\t\t\t @@@@@@@@ @@@@@@ @@@@@@@@@@ @@@@@@@@ @@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@ @@@ "; | |
| cout << "\n\t\t\t\t@@@@@@@@@ @@@@@@@@ @@@@@@@@@@@ @@@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@@ @@@ "; | |
| cout << "\n\t\t\t\t!@@ @@! @@@ @@! @@! @@! @@! @@! @@@ @@! @@@ @@! @@! @@@ @@! "; | |
| cout << "\n\t\t\t\t!@! !@! @!@ !@! !@! !@! !@! !@! @!@ !@! @!@ !@! !@! @!@ !@ "; | |
| cout << "\n\t\t\t\t!@! @!@!@ @!@!@!@! @!! !!@ @!@ @!!!:! @!@ !@! @!@ !@! @!!!:! @!@!!@! @!@ "; | |
| cout << "\n\t\t\t\t!!! !!@!! !!!@!!!! !@! ! !@! !!!!!: !@! !!! !@! !!! !!!!!: !!@!@! !!! "; | |
| cout << "\n\t\t\t\t:!! !!: !!: !!! !!: !!: !!: !!: !!! :!: !!: !!: !!: :!! "; | |
| cout << "\n\t\t\t\t:!: !:: :!: !:! :!: :!: :!: :!: !:! ::!!:! :!: :!: !:! :!: "; | |
| cout << "\n\t\t\t\t ::: :::: :: ::: ::: :: :: :::: ::::: :: :::: :: :::: :: ::: :: "; | |
| cout << "\n\t\t\t\t :: :: : : : : : : : :: :: : : : : : :: :: : : : ::: "; | |
| cout << "\n\n\n\t\t\t\t\t\t\t\t Correct Number is " << guess; | |
| } | |
| void thx(){ // Thanks for Playing! | |
| system("mode con:cols=170 lines=14"); | |
| system("cls"); | |
| cout << "\n ________ __ __ ______ _______ __ __ __ "; | |
| cout << "\n | \\| \\ | \\ / \\ | \\ | \\ | \\ | \\"; | |
| cout << "\n \\$$$$$$$$| $$____ ______ _______ | $$ __ _______ | $$$$$$\\ ______ ______ | $$$$$$$\\| $$ ______ __ __ \\$$ _______ ______ | $$"; | |
| cout << "\n | $$ | $$ \\ | \\ | \\ | $$ / \\ / \\ | $$_ \\$$ / \\ / \\ | $$__/ $$| $$ | \\ | \\ | \\| \\| \\ / \\ | $$"; | |
| cout << "\n | $$ | $$$$$$$\\ \\$$$$$$\\| $$$$$$$\\| $$_/ $$| $$$$$$$ | $$ \\ | $$$$$$\\| $$$$$$\\ | $$ $$| $$ \\$$$$$$\\| $$ | $$| $$| $$$$$$$\\| $$$$$$\\ | $$"; | |
| cout << "\n | $$ | $$ | $$ / $$| $$ | $$| $$ $$ \\$$ \\ | $$$$ | $$ | $$| $$ \\$$ | $$$$$$$ | $$ / $$| $$ | $$| $$| $$ | $$| $$ | $$ \\$$"; | |
| cout << "\n | $$ | $$ | $$| $$$$$$$| $$ | $$| $$$$$$\\ _\\$$$$$$\\ | $$ | $$__/ $$| $$ | $$ | $$| $$$$$$$| $$__/ $$| $$| $$ | $$| $$__| $$ __ "; | |
| cout << "\n | $$ | $$ | $$ \\$$ $$| $$ | $$| $$ \\$$\\| $$ | $$ \\$$ $$| $$ | $$ | $$ \\$$ $$ \\$$ $$| $$| $$ | $$ \\$$ $$ | \\"; | |
| cout << "\n \\$$ \\$$ \\$$ \\$$$$$$$ \\$$ \\$$ \\$$ \\$$ \\$$$$$$$ \\$$ \\$$$$$$ \\$$ \\$$ \\$$ \\$$$$$$$ _\\$$$$$$$ \\$$ \\$$ \\$$ _\\$$$$$$$ \\$$"; | |
| cout << "\n | \\__| $$ | \\__| $$ "; | |
| cout << "\n \\$$ $$ \\$$ $$ "; | |
| cout << "\n \\$$$$$$ \\$$$$$$ "; | |
| cout << "\n"; | |
| system("COLOR 0E"); | |
| system("timeout 3 >nul"); | |
| } | |
| void count(){ | |
| system("timeout 1 >nul"); | |
| cout << "\n\n\t\t\t\t\t\t\t\t\t....: 3 :....\a"; | |
| system("timeout 1 >nul"); | |
| cout << "\n\n\t\t\t\t\t\t\t\t\t....: 2 :....\a"; | |
| system("timeout 1 >nul"); | |
| cout << "\n\n\t\t\t\t\t\t\t\t\t....: 1 :....\a"; | |
| system("timeout 1 >nul"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment