1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
//Games.h
#ifndef GAMES_H
#define GAMES_H
#include <string>
namespace games
{
std::string yourPlay;
//functions
int genRandNum();
std::string reverseString(const std::string& oldString);
int testHiLo(int guess, int answer);
bool testPalindrome(std::string palindrome);
int testYourPlayRPS(std::string theirPlay);
int testCpuPlayRPS(int cpuPlay);
int testSlotMachine(int slotNum1, int slotNum2, int slotNum3);
}
#endif
//Games.cpp
#include "Games.h"
#include <algorithm>
#include <boost\algorithm\string\predicate.hpp>
using namespace std;
namespace games
{
int genRandNum(int maxRand)
{
int result = (rand() % maxRand);
return result;
}
string reverseString(const string& oldString)
{
string newString(oldString);
reverse(newString.begin(), newString.end());
return newString;
}
int testHiLo(int guess, int answer)
{
if (guess==answer)
{
return 0;
}
else if (guess>answer)
{
return 1;
}
else if (guess < answer)
{
return 2;
}
}
bool testPalindrome(string palindrome)
{
if (boost::iequals(palindrome, reverseString(palindrome)))
{
return true;
}
else
{
return false;
}
}
int testYourPlayRPS(string theirPlay)
{
if ((boost::iequals(theirPlay, "rock")) || (boost::iequals(theirPlay, "1")))
{
return 1;
}
else if ((boost::iequals(theirPlay, "paper")) || (boost::iequals(theirPlay, "2")))
{
return 2;
}
else if ((boost::iequals(theirPlay, "scissors")) || (boost::iequals(theirPlay, "3")))
{
return 3;
}
else
{
return 0;
}
}
int testCpuPlayRPS(int cpuPlay)
{
if (testYourPlayRPS(yourPlay)==1)
{
if (cpuPlay==1)
{
return 11;
}
else if (cpuPlay==2)
{
return 12;
}
else if (cpuPlay==3)
{
return 13;
}
else
{
return 0;
}
}
else if (testYourPlayRPS(yourPlay) == 2)
{
if (cpuPlay == 1)
{
return 21;
}
else if (cpuPlay == 2)
{
return 22;
}
else if (cpuPlay == 3)
{
return 23;
}
else
{
return 0;
}
}
else if (testYourPlayRPS(yourPlay) == 3)
{
if (cpuPlay == 1)
{
return 31;
}
else if (cpuPlay == 2)
{
return 32;
}
else if (cpuPlay == 3)
{
return 33;
}
else
{
return 0;
}
}
else if (testYourPlayRPS(yourPlay) == 0)
{
return 0;
}
}
int testSlotMachine(int slotNum1, int slotNum2, int slotNum3)
{
if ((slotNum1 == slotNum2) && (slotNum1 == slotNum3))
{
return 3;
}
else if ((slotNum1 == slotNum2) || (slotNum2 == slotNum3) || (slotNum1 == slotNum3))
{
return 2;
}
else
{
return 1;
}
}
}
|