Advertisement
joloos

3in1Arcade source code

Nov 24th, 2023 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <windows.h>    
  5. #include <string.h>
  6. #include <string>
  7. #include <vector>
  8. #include <random>
  9. #include <algorithm>
  10. #include<cstdlib>
  11. #include<chrono>
  12. #include<thread>
  13. // 3 in 1 Arcade
  14. /* Made by
  15. Julius Formilles
  16. Mico Laraccas
  17. Daniel Lachica
  18. Aaronn Advincula
  19. */
  20.  
  21.  
  22. //Functions for typing slowly the string.
  23. //************************************************************************************************************************************************************
  24.  
  25.  
  26. int typedelayfast(const std::string& str, bool flag) { //Short Sleep Time
  27.     int typespeed = 50; // Sets the typing speed
  28.    
  29.     for (size_t i = 0; i < str.length(); i++) {
  30.         Sleep(typespeed); // Gets time slept from typespeed
  31.         std::cout << str[i];
  32.     }
  33.     std::cout << std::endl;
  34.    
  35.     if (flag) {
  36.     Sleep(1000);
  37.     system("cls"); //Clears the line after flag is true which is after typing the whole line
  38.     }
  39.    
  40.     return 0;
  41. }
  42.  
  43. int typedelayslow(const std::string& str, bool flag) { //Longer Sleep Time
  44.     int typespeed = 50; // Sets the typing speed
  45.    
  46.     for (size_t i = 0; i < str.length(); i++) {
  47.         Sleep(typespeed); // Gets time slept from typespeed
  48.         std::cout << str[i];
  49.     }
  50.     std::cout << std::endl;
  51.    
  52.     if (flag) {
  53.     Sleep(2000);
  54.     system("cls"); //Clears the line after flag is true which is after typing the whole line
  55.     }
  56.    
  57.     return 0;
  58. }
  59.  
  60.  int typedelayxtraslow(const std::string& str, bool flag) { //Longer Sleep Time
  61.     int typespeed = 120; // Sets the typing speed
  62.    
  63.     for (size_t i = 0; i < str.length(); i++) {
  64.         Sleep(typespeed); // Gets time slept from typespeed
  65.         std::cout << str[i];
  66.     }
  67.     std::cout << std::endl;
  68.    
  69.     if (flag) {
  70.     Sleep(2000);
  71.     system("cls"); //Clears the line after flag is true which is after typing the whole line
  72.     }
  73.    
  74.     return 0;
  75. }
  76. //*************************************************************************************************************************************************************
  77.  
  78.  
  79. //**********************
  80. //Word Bomb            *
  81. //Made by Nixie Lachica*
  82. //**********************
  83.  const int TIMER_DURATION = 5;
  84.  
  85.     std::string randomword() {
  86.     const std::string words[] = { "transgress", "obeisance", "characteristic", "misanthrope", "preponderance", "articulation", "forbearance", "quintessential", "legislation", "parsimonious", "convalescent", "predecessor", "representative", "irrefragable", "gullibility", "nonagenarian", "adulation", "electrolysis", "installation", "onomatopoeia", "malignant"
  87. ,"centrifugal", "neurological.", "idiosyncratic", "xylophonist", "surreptitiously", "indomitable", "sacrilegious", "absenteeism", "pertinacious" };
  88.  
  89.     int index = rand() % (sizeof(words) / sizeof(words[0]));
  90.     return words[index];
  91. }
  92.  
  93. bool Iscorrect(const std::string& generatedWord, const std::string& playerWord) {
  94.  
  95.     return generatedWord == playerWord;
  96. }
  97.  
  98. void wordbomb() {
  99.     system("Color 0D");
  100.     srand(static_cast<unsigned>(time(0)));
  101. while (true){
  102.  
  103.         system("cls");
  104.  
  105. std::cout<<"__    __ ____ _____  ____    _____  ____  __  __ _____ "<<std::endl;
  106. std::cout<<"\\ \\/\\/ // () \\| () )| _) \\   | () )/ () \\|  \\/  || () )"<<std::endl;
  107. std::cout<<" \\_/\\_/ \\____/|_|\\_\\|____/   |_()_)\\____/|_|\\/|_||_()_)"<<std::endl;
  108.         std::cout << std::endl;
  109.         typedelayslow("Welcome to the Word Ticking Game!!", true);
  110.         typedelayslow("Enter 'exit' to exit at any point during the game.", false);
  111.         Sleep(1000);
  112.         typedelayslow("You have exactly " + std::to_string(TIMER_DURATION) + " seconds to type the word shown ", false);
  113.         typedelayslow("If you get a spelling mistake, the game will end.", false);
  114.         Sleep(1000);
  115.         system("cls");
  116.         while (true) {
  117.         std::string generatedWord = randomword();
  118.         std::cout << "Given Word: " << generatedWord << std::endl;
  119.  
  120.         auto start = std::chrono::steady_clock::now();
  121.         std::string playerWord;
  122.         std::cout << "Type the word shown: ";
  123.         std::cin >> playerWord;
  124.         if(playerWord=="exit"||playerWord=="Exit")
  125.         return;
  126.  
  127.         auto end = std::chrono::steady_clock::now();
  128.         auto elapsedSeconds = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
  129.  
  130.         if (elapsedSeconds <= TIMER_DURATION && Iscorrect(generatedWord, playerWord)) {
  131.             system("cls");
  132.             std::cout << "Correct! Next word: " << std::endl;
  133.             Sleep(500);
  134.         }
  135.         else {
  136.             std::cout << "Time is up! Try again by typing anything!  Type Exit to exit the game." << std::endl;
  137.             std::cin >> playerWord;
  138.             if(playerWord=="exit"||playerWord=="Exit" || playerWord == "EXIT")
  139.             return;
  140.             break;
  141.  
  142.             if (playerWord == "Exit" || playerWord == "exit" || playerWord == "EXIT") {
  143.                 std::cout << "Try again soon!" << std::endl;
  144.                 return;
  145.             }
  146.         }
  147.     }
  148.  
  149.     }
  150. }
  151.  
  152. //*****************************
  153. //Wordle                      *
  154. //Made by Aaron Advincula     *
  155. //*****************************
  156. // Function to randomly choose a word from the word bank
  157. const int wordLength = 5;
  158.  
  159. std::string getRandomWord() {
  160.     const std::string words[] = {"apple", "happy", "grape", "cloud", "music", "beach", "robot", "smile", "alert", "guess", "bread", "chair", "crown", "breed", "broad", "chase", "brief", "cycle", "cheap", "curve", "daily", "acute", "actor", "abuse", "admit", "craft", "miner", "minor", "heavy", "drama", "fault", "flash", "local", "enjoy", "fluid", "known", "label", "logic", "loose", "might", "never", "radio", "paper", "north", "novel", "noise", "occur", "ocean", "offer", "pride", "price", "print", "spare", "speed", "split", "spent", "table", "taken", "track", "teeth", "theme", "upset", "upper", "wound", "waste", "write", "whole", "worth", "vital", "visit", "value", "virus", "valid"};
  161.     int index = rand() % (sizeof(words) / sizeof(words[0]));
  162.     return words[index];
  163. }
  164.  
  165. bool IsCorrect(const std::string& generatedWord, const std::string& playerWord) {
  166.     return generatedWord == playerWord;
  167. }
  168.  
  169. void displayFeedback(const std::string& hiddenWord, const std::string& guess) {
  170.     for (int i = 0; i < hiddenWord.length(); ++i) {
  171.         if (guess[i] == hiddenWord[i]) {
  172.             std::cout << 'O';  // Correct letter in correct position
  173.         } else if (find(hiddenWord.begin(), hiddenWord.end(), guess[i]) != hiddenWord.end()) {
  174.             std::cout << 'X';  // Correct letter in the wrong position
  175.         } else {
  176.             std::cout << '-';  // Incorrect letter
  177.         }
  178.     }
  179.     std::cout << std::endl;
  180. }
  181.  
  182. void wordle() {
  183.    
  184.     // Seed the random number generator with the current time
  185.     system("Color 0C");
  186.     while(true){
  187.     srand(static_cast<unsigned int>(time(0)));
  188.     std::string hiddenWord = getRandomWord();
  189.     int maxAttempts = 8;
  190.  std::cout << " ____ ____ ____ ____ ____ ____ "<<std::endl;
  191.  std::cout << "||W |||o |||r |||d |||l |||e ||"<<std::endl;
  192.  std::cout << "||__|||__|||__|||__|||__|||__||"<<std::endl;
  193.  std::cout << "|/__\\|/__\\|/__\\|/__\\|/__\\|/__\\|"<<std::endl;
  194.     typedelayslow("Welcome to Wordle! Try to guess the " + std::to_string(wordLength) + "-letter word.", false);
  195.     typedelayslow("The hidden word has " + std::to_string(wordLength) + " letters.", false);
  196.    typedelayslow("Enter exit at any point during the game to exit.", false);
  197.    typedelayslow("Press Enter to start.", false);
  198.     std::cin.ignore();
  199.     system("cls");
  200.     for (int attempt = 1; attempt <= maxAttempts; ++attempt) {
  201.         std::string guess;
  202.  
  203.         std::cout << "\nAttempt " << attempt << "/" << maxAttempts << ": ";
  204.         std::getline(std::cin, guess);
  205.         if(guess=="exit"||guess=="Exit"||guess=="EXIT")
  206.         return;
  207.  
  208.         if (guess.length() != wordLength) {
  209.             std::cout << "Invalid guess. Please enter a " << wordLength << "-letter word." << std::endl;
  210.             --attempt;
  211.             continue;
  212.         }
  213.  
  214.         if (IsCorrect(hiddenWord, guess)) {
  215.             std::cout << "You guessed the word in " << attempt << " attempts. Well done!" << std::endl;
  216.             Sleep(3000);
  217.             break;
  218.         } else {
  219.             std::cout << "Incorrect guess. Here is the feedback:" << std::endl;
  220.             displayFeedback(hiddenWord, guess);
  221.             // You can add additional logic or messages here as needed
  222.             Sleep(500);
  223.         }
  224.     }
  225.  
  226.     if (maxAttempts == 8) {
  227.         std::cout << "Sorry, you've run out of attempts. The correct word was: " << hiddenWord << std::endl;
  228.     }
  229.     }
  230.     return;
  231. }
  232.  
  233. //*************************************
  234. //*Rock Paper Scissors Game           *
  235. //*Made by Julius Andrei Formilles    *
  236. //*************************************
  237.  
  238. void janken(){
  239. system("Color 0B");
  240. std::string userinputstring;
  241. while (userinputstring != "exit"&& userinputstring != "Exit"){
  242.  
  243.     int userinputint = 0;
  244.     int computerinputint = 0;
  245.     std::string computerinputstring;
  246.     userinputstring.clear(); // Clears userinputstringdata so that the program doesn't read the data from the last iteration.
  247.  
  248. std::cout<<"                  _                                             _                       "<<std::endl;
  249. std::cout<<"                 | |                                           (_)                       "<<std::endl;
  250. std::cout<<"   _ __ ___   ___| | __  _ __   __ _ _ __   ___ _ __   ___  ___ _ ___ ___  ___  _ __ ___ "<<std::endl;
  251. std::cout<<"  | '__/ _ \\ / __| |/ / | '_ \\ / _` | '_ \\ / _ \\ '__| / __|/ __| / __/ __|/ _ \\| '__/ __|"<<std::endl;
  252. std::cout<<"  | | | (_) | (__|   <  | |_) | (_| | |_) |  __/ |    \\__ \\ (__| \\__ \\__ \\ (_) | |  \\__ \\"<<std::endl;
  253. std::cout<<"  |_|  \\___/ \\___|_|\\_\\ | .__/ \\__,_| .__/ \\___|_|    |___/\\___|_|___/___/\\___/|_|  |___/"<<std::endl;
  254. std::cout<<"                        | |         | |                                                  "<<std::endl;
  255. std::cout<<"                        |_|         |_|                                                  "<<std::endl;
  256. Sleep(2350);
  257.  
  258.  
  259.     std::cout<<std::endl <<std::endl<<"Press enter to start the game.";
  260.  
  261.     std::cin.ignore();
  262.     system("cls");
  263.     typedelayfast("Enter 'exit' at any point during the game to exit.",false);
  264.     Sleep(3000);
  265.     system("cls");
  266.  
  267.  
  268.     while(userinputstring != "Rock"&& userinputstring != "rock" && userinputstring != "Paper" && userinputstring != "paper"&& userinputstring != "Scissors"&& userinputstring !=  "scissors" && userinputstring != "exit" && userinputstring != "Exit"){
  269.         // Loops until the correct input has been made
  270.         // Coded in a way so that it isnt case sensitive
  271.  
  272.  
  273.     typedelayfast("Rock Paper or Scissors?", false);
  274.     std::cout<<std::endl;
  275.     std::getline (std::cin, userinputstring);
  276.     system("cls");
  277.  
  278.  
  279.     if(userinputstring != "Rock"&& userinputstring != "rock" && userinputstring !=  "Paper"&& userinputstring !=  "paper"&& userinputstring !=  "Scissors"&& userinputstring !=  "scissors" && userinputstring != "exit" && userinputstring != "Exit"){
  280.     typedelayfast("Input a correct choice", true);
  281.     }
  282.         else{
  283.  
  284.          if (userinputstring=="Rock"|| userinputstring=="rock")
  285.             userinputint=1;
  286.          else if(userinputstring=="Paper"|| userinputstring == "paper")
  287.             userinputint=2;
  288.          else if(userinputstring=="Scissors"|| userinputstring== "scissors")
  289.             userinputint=3;
  290.          else if (userinputstring == "Exit" || userinputstring == "exit"|| userinputstring=="EXIT")
  291.             userinputint=4;
  292.     }
  293.     }
  294.  
  295. switch (userinputint){
  296. case 1:
  297. std::cout<<"     _______"<<std::endl;
  298. std::cout<<" ---'   ____)  "<<std::endl;
  299. std::cout<<"       (_____)  "<<std::endl;
  300. std::cout<<"       (_____)  "<<std::endl;
  301. std::cout<<"       (____)"<<std::endl;
  302. std::cout<<" ---.__(___)  "<<std::endl;
  303. std::cout<<" '''  "<<std::endl;
  304. break;
  305.  
  306. case 2:
  307. std::cout<<"    _______"<<std::endl;
  308. std::cout<<"---'   ____)____"<<std::endl;
  309. std::cout<<"          ______)"<<std::endl;  
  310. std::cout<<"          _______)"<<std::endl;  
  311. std::cout<<"         _______)"<<std::endl;
  312. std::cout<<"---.__________)"<<std::endl;  
  313. std::cout<<"'''"<<std::endl;
  314. break;
  315.  
  316. case 3:
  317. std::cout<<"    _______"<<std::endl;
  318. std::cout<<"---'   ____)____"<<std::endl;
  319. std::cout<<"          ______)"<<std::endl;  
  320. std::cout<<"       __________)"<<std::endl;  
  321. std::cout<<"      (____)"<<std::endl;
  322. std::cout<<"---.__(___)"<<std::endl;  
  323. std::cout<<"'''"<<std::endl;  
  324. break;
  325.  
  326. case 4:
  327. return; //Goes back to main(); on the line after the function was called.
  328.                 }
  329.  
  330. typedelayslow("You have chosen " + userinputstring + ".", true); //Types what the user has chosen
  331. typedelayfast("Rock! Paper! Scissors! Shoot!", true);
  332.    
  333.    
  334.    
  335.             srand(time(NULL));                 //Initializes RNG. By initializing, you set the starting point to the current time which ensures that the
  336.                                                //the number is different every time you run it.
  337.             computerinputint = rand() % (3 - 1 + 1) + 1; // RNG. 3 is the upper limit and 1 is the lower limit
  338.                                                          // (upperLimit - lowerLimit + 1) + lowerLimit;
  339.             switch (computerinputint){
  340.             case 1:
  341.             computerinputstring = "Rock";
  342. std::cout<<"    _______"<<std::endl;
  343. std::cout<<" ---'   ____)  "<<std::endl;
  344. std::cout<<"       (_____)  "<<std::endl;
  345. std::cout<<"       (_____)  "<<std::endl;
  346. std::cout<<"       (____)"<<std::endl;
  347. std::cout<<" ---.__(___)  "<<std::endl;
  348. std::cout<<" '''  "<<std::endl;
  349.             break;
  350.  
  351.             case 2:
  352.             computerinputstring = "Paper";
  353. std::cout<<"    _______"<<std::endl;
  354. std::cout<<"---'   ____)____"<<std::endl;
  355. std::cout<<"          ______)"<<std::endl;  
  356. std::cout<<"          _______)"<<std::endl;  
  357. std::cout<<"         _______)"<<std::endl;
  358. std::cout<<"---.__________)"<<std::endl;  
  359. std::cout<<"'''"<<std::endl;
  360.             break;
  361.  
  362.             case 3:
  363.             computerinputstring = "Scissors";
  364. std::cout<<"    _______"<<std::endl;
  365. std::cout<<"---'   ____)____"<<std::endl;
  366. std::cout<<"          ______)"<<std::endl;  
  367. std::cout<<"       __________)"<<std::endl;  
  368. std::cout<<"      (____)"<<std::endl;
  369. std::cout<<"---.__(___)"<<std::endl;  
  370. std::cout<<"'''"<<std::endl;  
  371.             break;
  372.  
  373.             default:
  374.             std::cout<<"something went work xd";
  375.             break;
  376.             }
  377.  
  378.     typedelayfast("The computer has chosen " + computerinputstring + ".",true);
  379.  
  380.  
  381.  
  382.  
  383. if(userinputint == computerinputint) //Result of the game Determiner
  384. typedelayslow("It is a tie. Go again.", true);
  385.  
  386. else if(userinputint == 1){
  387.     if (computerinputint==2)
  388.     typedelayfast("Paper beats Rock. You have lost.", true);
  389.     else if (computerinputint==3)
  390.     typedelayslow("Rock beats Scissors. You have won!", true);
  391.     Sleep(2000);
  392. }
  393.  
  394. else if(userinputint == 2){
  395.     if (computerinputint==1)
  396.     typedelayfast("Paper beats Rock. You have won!", true);
  397.     else if (computerinputint==3)
  398.     typedelayslow("Scissors beats Paper . You have lost.", true);  
  399.     Sleep(2000);
  400. }
  401.  
  402. else if(userinputint == 3){
  403.     if (computerinputint==2)
  404.     typedelayslow("Scissors beats Paper. You have won!", true);
  405.     else if (computerinputint==1)
  406.     typedelayslow("Rock beats Scissors. You have lost.", true);
  407.     Sleep(2000);
  408. }
  409.  
  410.  
  411. }  
  412.     }
  413. //Credits***************************************************************************************************************************************************************************
  414. void credits(){
  415.     system("Color 0E");
  416. std::string userinputstring;
  417. std::cout<<"                         _ _ _       "<<std::endl;
  418. std::cout<<"                        | (_) |      "<<std::endl;
  419. std::cout<<"        ___ _ __ ___  __| |_| |_ ___ "<<std::endl;
  420. std::cout<<"       / __| '__/ _ \\/ _` | | __/ __|"<<std::endl;
  421. std::cout<<"      | (__| | |  __/ (_| | | |_\\__ \\"<<std::endl;
  422. std::cout<<"       \\___|_|  \\___|\\__,_|_|\\__|___/"<<std::endl;
  423.  
  424. std::cout<<std::endl<<std::endl;
  425.  
  426. typedelayxtraslow("Made by:", false);
  427. typedelayxtraslow("Julius Formilles", false);
  428. typedelayxtraslow("Aaron Advincula", false);
  429. typedelayxtraslow("Danielle Lachica", false);
  430. typedelayxtraslow("Mico Larracas", false);
  431. std::cout<<std::endl<<std::endl;
  432. typedelayxtraslow("Special Mentions:", false);
  433. typedelayxtraslow("Linus (Waffle) Pitargue ", false);
  434. typedelayxtraslow("Karl Stephen Delos Santos Mangahas", false);
  435. typedelayxtraslow("Troy Ronquillo", false);
  436. std::cout<<std::endl<<std::endl;
  437. typedelayxtraslow("Enter 'exit' to return to menu or exit the program.", false);
  438.  
  439. while(userinputstring != "exit" && userinputstring != "Exit" && userinputstring != "EXIT"){
  440. std::cin>>userinputstring;
  441. if(userinputstring == "exit" || userinputstring == "Exit" || userinputstring == "EXIT"){
  442. return;
  443. }                              
  444. }
  445. }
  446.  
  447.  
  448.  
  449. //Main Menu Function*************************************************************************************************************************************************************
  450.  
  451. int userinputint;
  452. char userinputchar;
  453.  
  454. void menu(){
  455. if (std::cin.fail()) { // Checks if previous input operation failed. (If the input was not the correct type)
  456. std::cin.clear(); // Clear error state
  457. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // Discard invalid input
  458. }
  459.  
  460. std::cout<<"   _____    _          ___   ___                        __   "<<std::endl;
  461. std::cout<<"  |__  /   (_)___     <  /  /   |  ______________ _____/ /__ "<<std::endl;
  462. std::cout<<"   /_ <   / / __ \\    / /  / /| | / ___/ ___/ __ `/ __  / _ \\"<<std::endl;
  463. std::cout<<" ___/ /  / / / / /   / /  / ___ |/ /  / /__/ /_/ / /_/ /  __/"<<std::endl;
  464. std::cout<<"/____/  /_/_/ /_/   /_/  /_/  |_/_/   \\___/\\__,_/\\__,_/\\___/ "<<std::endl;
  465.                                                              
  466.                                                                                
  467. std::cout<<std::endl;
  468. std::cout<<"Enter the number of the game that you want to play:"<<std::endl;
  469. std::cout<<"(1) Rock Paper Scissors"<<std::endl;
  470. std::cout<<"(2) Wordle"<<std::endl;
  471. std::cout<<"(3) Word Bomb"<<std::endl;
  472. std::cout<<"(4) Credits" << std::endl;
  473. std::cout<<"(5) Exit" << std::endl;
  474. std::cin>>userinputint;
  475.  
  476. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  477.  
  478. switch(userinputint){
  479. case 1:
  480. system("cls");
  481. janken();
  482. break;
  483.  
  484. case 2:
  485. system("cls");
  486. wordle();
  487. break;
  488.  
  489. case 3:
  490. system("cls");
  491. wordbomb();
  492. break;
  493.  
  494. case 4:
  495. system("cls");
  496. credits();
  497. break;
  498.  
  499. case 5:
  500. system("cls");
  501. return;
  502.  
  503. default:
  504. menu();
  505. }
  506. return; //Goes back to main(); on the line after the function was called.
  507. }
  508.  
  509. //Main Function
  510. int main(){
  511.    system("Color 0A");
  512.    while(true){
  513.     std::cout<<"Press enter to continue."<<std::endl;
  514.     std::cin.ignore();
  515.  
  516.     system("cls");
  517.     menu();
  518.  
  519.     std::cout<<"Do you want to close the program? (Y/N)";
  520.     std::cin>>userinputchar;
  521.     if(userinputchar == 'Y' || userinputchar == 'y')
  522.     break;
  523.     else
  524.     continue;
  525.  
  526. }
  527. system("cls");
  528. typedelayslow("Thank you for playing :)", true);
  529. return 0;
  530. }
  531.  
  532.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement