Skip to content

Instantly share code, notes, and snippets.

@jesyspa
Forked from johnhamelink/hand.h
Created June 27, 2012 19:19
Show Gist options
  • Save jesyspa/3006159 to your computer and use it in GitHub Desktop.
Save jesyspa/3006159 to your computer and use it in GitHub Desktop.
#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
// 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