Advertisement
Guest User

Untitled

a guest
Dec 12th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. // Answer.hpp - Johnny Pacific
  2. // 12/12/12
  3.  
  4. #pragma once
  5. #include <array>
  6. #include <cstdlib>
  7. #include <ctime>
  8. #include <string>
  9.  
  10. namespace Games {
  11.     namespace MasterMind {
  12.         class Answer {
  13.         private:
  14.            
  15.             std::string answer[4];  // Answer to game.
  16.             int uPos[4];            // Used positions in game.
  17.             std::string colors[6];  // Colors used as answers to game.
  18.  
  19.         public:
  20.             Answer() {
  21.                 srand((unsigned)time(NULL));
  22.  
  23.                 answer[0] = "";
  24.                 answer[1] = "";
  25.                 answer[2] = "";
  26.                 answer[3] = "";
  27.  
  28.                 uPos[0] = -1;
  29.                 uPos[1] = -1;
  30.                 uPos[2] = -1;
  31.                 uPos[3] = -1;
  32.  
  33.                 colors[0] = "white";
  34.                 colors[1] = "red";
  35.                 colors[2] = "orange";
  36.                 colors[3] = "green";
  37.                 colors[4] = "blue";
  38.                 colors[5] = "yellow";
  39.  
  40.                 setAnswer();
  41.             }
  42.  
  43.  
  44.             void setAnswer() {
  45.                 for(int i = 0; i < 4; i++) {
  46.                    
  47.                     int ran = ((rand() % 6) + 1);   // Generate the Random Number.
  48.  
  49.                     while((ran == uPos[0] || ran == uPos[1] || ran == uPos[2] || ran == uPos[3])) {
  50.                         ran = ((rand() % 6) + 1);
  51.  
  52.                         std::cout << ran << std::endl;
  53.                     }
  54.  
  55.                     std::cout << ran << std::endl;
  56.                     uPos[i] = ran;
  57.  
  58.                     // Set one of the answers to one of the randomly selected colors.
  59.                     answer[i] =  colors[ran];
  60.                 }
  61.             }
  62.             void resetGame() {
  63.                 answer[0, 1, 2, 3] = "";
  64.                 uPos[0, 1, 2, 3] = -1;
  65.                 colors[0, 1, 2, 3] = "white", "red", "orange",
  66.                                      "green", "blue", "yellow";
  67.                 setAnswer();
  68.             }
  69.  
  70.             std::string getAnswer(int k)    { return answer[k]; }
  71.         };
  72.     }
  73. }
  74.  
  75. /* EXTRA CRAP THAT WAS THOUGHT OVER:
  76.  
  77. std::random_device rd;
  78. // Define how to use raw numbers using uniform distribution with 6 possible events.
  79. std::uniform_int_distribution<> dis(0, 5);
  80. std::mt19937 gen(rd()); // Random Device is seeding the generator.
  81.  
  82. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement