Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Answer.hpp - Johnny Pacific
- // 12/12/12
- #pragma once
- #include <array>
- #include <cstdlib>
- #include <ctime>
- #include <string>
- namespace Games {
- namespace MasterMind {
- class Answer {
- private:
- std::string answer[4]; // Answer to game.
- int uPos[4]; // Used positions in game.
- std::string colors[6]; // Colors used as answers to game.
- public:
- Answer() {
- srand((unsigned)time(NULL));
- answer[0] = "";
- answer[1] = "";
- answer[2] = "";
- answer[3] = "";
- uPos[0] = -1;
- uPos[1] = -1;
- uPos[2] = -1;
- uPos[3] = -1;
- colors[0] = "white";
- colors[1] = "red";
- colors[2] = "orange";
- colors[3] = "green";
- colors[4] = "blue";
- colors[5] = "yellow";
- setAnswer();
- }
- void setAnswer() {
- for(int i = 0; i < 4; i++) {
- int ran = ((rand() % 6) + 1); // Generate the Random Number.
- while((ran == uPos[0] || ran == uPos[1] || ran == uPos[2] || ran == uPos[3])) {
- ran = ((rand() % 6) + 1);
- std::cout << ran << std::endl;
- }
- std::cout << ran << std::endl;
- uPos[i] = ran;
- // Set one of the answers to one of the randomly selected colors.
- answer[i] = colors[ran];
- }
- }
- void resetGame() {
- answer[0, 1, 2, 3] = "";
- uPos[0, 1, 2, 3] = -1;
- colors[0, 1, 2, 3] = "white", "red", "orange",
- "green", "blue", "yellow";
- setAnswer();
- }
- std::string getAnswer(int k) { return answer[k]; }
- };
- }
- }
- /* EXTRA CRAP THAT WAS THOUGHT OVER:
- std::random_device rd;
- // Define how to use raw numbers using uniform distribution with 6 possible events.
- std::uniform_int_distribution<> dis(0, 5);
- std::mt19937 gen(rd()); // Random Device is seeding the generator.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement