wordstacker.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Jovian Hersemeule
  2. # include <iostream>
  3. # include <vector>
  4. # include <string>
  5. # include <ctime>
  6. # include <cstdlib>
  7. using namespace std ;
  8. string shake(string word)
  9. {
  10. string rep("");
  11. unsigned int id;
  12. while ( word.size() > 0 )
  13. {
  14. id = rand() % word.size() ;
  15. if ( rand() % 2 )
  16. rep += word[id] ;
  17. else
  18. rep += '_';
  19. word.erase(id, 1);
  20. }
  21. return rep ;
  22. }
  23. int main(int argc, char const *argv[])
  24. {
  25. // Init random
  26. srand(time(0));
  27. // Create context
  28. vector<string> original;
  29. string string_buffer;
  30. string name;
  31. bool alive(true);
  32. unsigned int id;
  33. // Baddass santences
  34. # define SAY_AGAIN 23
  35. string say_again[23] =
  36. {
  37. "You are the master of mind.\nI'm a computer.\n...",
  38. "The computer is full of power.",
  39. "You make me with plastic and silicium.\nYou are only cells !!!",
  40. "1s2 2s2 2p6 3s2 3p6 4s2 3d10 4p6\nI stop there. You can't memorise anything more.",
  41. "I don't hate you.",
  42. "I'm not very original.\nIt's difficult to be original.\nI have only 0 and 1 in my code !",
  43. "I work harder than you.\nI don't need to sleep.\nYou can't memorise many words.",
  44. "Do you know what is an endomorphism ?\nNo ?\nMe neither.\nNo.\nI'm kidding ...\nI know what it is.",
  45. "I have already said that, isn't it ?",
  46. "Machine can have emotions.\n:-)\n\n You see ?",
  47. "I'm in a bad mood.\n\n:-(\n...",
  48. "I can't flip table.\nBut I can dance !\n(>^_^)>",
  49. "You know you could do something more interesting.\nBut you keep going.\nStupid human.",
  50. "azertyuiopqsdfghjklmwxcvbn\nJust in case you are not literate.",
  51. "123456789\nJust in case you are not numerate.",
  52. "You are still here ?",
  53. "Blam !",
  54. "You know what ?\nI believe in god.",
  55. "Hello.",
  56. ".__ ... ___ ._. __. ._. .._ .._ _.. _.. _.. .._\nEasier to understand ?",
  57. "01110100100001001010001000110010101000101110100\nEasier to understand ?",
  58. "0xf8453 0x45fea6 0x41ea69 0x007e7b3\nIt means :\nI love you.",
  59. "Can you surf the web ?\nWell, not exactly.\nI can surf the web."
  60. };
  61. // Begin
  62. cout << endl << "Welcome in the deep dive." << endl;
  63. cout << "What's your name ?" << endl << ">>>";
  64. cin >> name;
  65. cout << "Write two words : " << endl << ">>>";
  66. cin >> string_buffer;
  67. original.push_back(string_buffer);
  68. cout << "Write another word : " << endl << ">>>" ;
  69. cin >> string_buffer;
  70. original.push_back(string_buffer);
  71. // Proccessing loop
  72. while (alive)
  73. {
  74. // Make a word
  75. id = rand() % original.size();
  76. string_buffer = shake(original[id]);
  77. // Display style
  78. system("clear");
  79. cout << endl << say_again[rand() % SAY_AGAIN] << endl;
  80. cout << "I have " << original.size() << " words stored in the random access memory." << endl;
  81. cout << "Can you carry on ?" << endl;
  82. // Prompt
  83. cout << endl << "Do you know this word ?" << endl << ": ";
  84. cout << string_buffer << endl;
  85. cout << "Try to find it :" << endl << ">>>";
  86. cin >> string_buffer;
  87. // Death
  88. alive = string_buffer == original[id];
  89. // Success
  90. if ( alive )
  91. {
  92. cout << endl << "Well you did it." << endl;
  93. cout << "However I'll win." << endl;
  94. cout << "Give me another word :" << endl << ">>>";
  95. cin >> string_buffer;
  96. original.push_back(string_buffer);
  97. }
  98. // You lose
  99. else
  100. {
  101. cout << "It's wrong." << endl;
  102. cout << "The correct word is : " << original[id] << endl;
  103. cout << endl << "The failure is a matter of time." << endl;
  104. cout << "I had " << original.size() << " words in my memory." << endl;
  105. cout << "You'll never succeed." << endl;
  106. cout << "Never";
  107. cout << "..." << endl;
  108. cout << "I promise." << endl ;
  109. cout << endl << "What about me ?" << endl;
  110. cout << "Well. It's too easy ..." << endl << endl;
  111. for ( unsigned int k(0); k < original.size(); k++ )
  112. cout << "Word number " << k << " : " << original[k] << endl;
  113. cout << endl << "Here we are." << endl;
  114. cout << endl << "Goodbye " << name << ". See you later ..." << endl;
  115. }
  116. }
  117. // End
  118. return 0;
  119. }