-
-
Save jesyspa/3006159 to your computer and use it in GitHub Desktop.
This file contains 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
#ifndef HAND_H | |
#define HAND_H | |
// string is not IO. | |
#include <string> | |
// For random | |
#include <cstdlib> | |
class hand | |
{ | |
public: | |
hand(); | |
std::string getType() { return type; }; | |
private: | |
std::string type; | |
static std::vector<std::string> types; | |
}; | |
#endif | |
This file contains 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
// put this somewhere else | |
// and no ; after an include! | |
#include "hand.h" | |
#include "player.h" | |
#include <string> | |
#include <iostream> | |
#include <cstdlib> | |
#include <ctime> | |
std::vector<std::string> hand::types{"rock", "paper", "scissors"}; | |
hand::hand() | |
{ | |
// Initialise with a random seed somewhere earlier, not every time you make a hand. | |
// Random number from 0 to 2 | |
random = std::rand() % 3; | |
type = types[random]; | |
} | |
int main(int argc, const char *argv[]) | |
{ | |
std::srand(static_cast<unsigned int>(std::time(0)); | |
hand h; | |
std::cout << h.getType() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment