Fix issue, compiles fine but random function is acting fishy
Sep 18, 2012 at 7:21pm UTC
For opponent type, the code works, but for some reason it is coming out with mostly OpponentMonster1 (fire), and OpponentMonster3 (nature), and after compiling about 50 times i only got OpponentMonster2 (water) once, can someone try to fix this issue (if there is one) and explain what you did.
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
///////////////////////////////////////////////////////////////
// Program: un-named-game.cpp
// Description: this program will send out a creature
// and battle your opponents creature. The code currently works
// but more is being added to it.
//
// All code is mine unless otherwise stated
///////////////////////////////////////////////////////////////
//LIBRARYS
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include <cstdlib>
//NAMESPACE
using namespace std;
//MY VARIABLES
string PlayerAge;
string PlayerName;
string PlayerGender;
string CharacterDetails;
string OpponentCharacterDetails;
string Continue;
long Earnings = 10;
long Money = 0;
long AmountExp = 10;
long TotalExp = 0;
long NewLevel = 0;
long LevelUp = 10;
long SkillPoints = 3;
long TotalSkillPoints = 0;
long Attack = 8;
long Defence = 1;
long Health = 40;
long Damage;
long ODamage;
long OAttack = 8;
long ODefence = 1;
long OHealth = 40;
int TypeOfCharacter;
//CALLS MY FUNCTIONS
void Age();//asks for the players age
void Name();//asks the players name
void Gender();//asks for the players gender
void PlayerCard();//shows the user the thier I'D card
void Program();//introduces them to the program
void CharacterDetail();//decides the character they chose
void Rules();//tells the rules
void YourMonster1();//your-fire-type
void YourMonster2();//your-water-type
void YourMonster3();//your-nature-type
void OpponentMonster1();//opponent-fire-type
void OpponentMonster2();//opponent-water-type
void OpponentMonster3();//opponent-nature-type
void OponentType();//chooses the oponents creature
void Battlephase();//begins the battlephase
void Earned();//states what you earned from combat
void Level();//if you leveled up, what level you are, and exp gained
void pause(int dur);//pauses the program for a set number of seconds
//EXECUTES THE PROGRAM
int main()
{
//Name();
//Age();
//Gender();
//PlayerCard();
//Program();
//CharacterDetail();
//Rules();
OponentType();
//Battlephase();
//Earned();
//Level();
system("PAUSE" );
return 0;
}
//FUNCTION DECLARATIONS
void OponentType()
{
/* rand example: guess the number */
#include <stdio.h>
/* initialize random seed: */
srand ( time(NULL) );
/* generate secret number: */
TypeOfCharacter = rand() % 3 + 1;
if (TypeOfCharacter == 1)
{
OpponentMonster1();
}
else if (TypeOfCharacter == 2)
{
OpponentMonster2();
}
else
{
OpponentMonster3();
}
}
void pause(int dur)
{
int temp = time(NULL) + dur;
while (temp > time(NULL));
}
void Name()
{
cout << "Welcome to the game! Since you are starting on your journey," << endl;
cout << "let me know a little bit about you." ;
cout << " What is your full name?" << endl << endl;
getline(cin,PlayerName);
cout << "Nice to meet you " << PlayerName << "." << endl;
pause(5);
system("CLS" );
}
void YourMonster1()
{
cout << "You chose the fire type." << endl << "It does twice as much damage on nature types and half as much damage on water types." << endl << endl;
pause(5);
cout << "Your fire type has the following stats" << endl << endl;
pause(5);
cout << "Attack:" << Attack << endl;
cout << "Defense:" << Defence << endl;
cout << "Health:" << Health << endl;
cout << "Advantage:Nature" << endl;
cout << "Disadvantage:Water" << endl;
pause(5);
//Fire vs Fire
if (OpponentCharacterDetails == "Fire" )
{
Attack = Attack + 0;
}
//Fire vs Water
if (OpponentCharacterDetails == "Water" )
{
Attack = OAttack / 2;
}
//Fire vs Nature
if (OpponentCharacterDetails == "Nature" )
{
Attack = Attack * 2;
}
system("CLS" );
}
void YourMonster2()
{
cout << "You chose the water type." << endl << "It does twice as much damage on fire types and half as much damage on nature types." << endl << endl;
pause(5);
cout << "Your water type has the following stats" << endl << endl;
pause(5);
cout << "Attack:" << Attack << endl;
cout << "Defense:" << Defence << endl;
cout << "Health:" << Health << endl;
cout << "Advantage:Fire" << endl;
cout << "Disadvantage:Nature" << endl;
pause(5);
//Water vs Fire
if (OpponentCharacterDetails == "Fire" )
{
Attack = Attack * 2;
}
//Water vs Water
if (OpponentCharacterDetails == "Water" )
{
Attack = OAttack + 0;
}
//Water vs Nature
if (OpponentCharacterDetails == "Nature" )
{
Attack = Attack / 2;
}
system("CLS" );
}
void YourMonster3()
{
cout << "You chose the nature type." << endl << "It does twice as much damage on water types and half as much damage on fire types." << endl << endl;
pause(5);
cout << "Your nature type has the following stats" << endl << endl;
pause(5);
cout << "Attack:" << Attack << endl;
cout << "Defense:" << Defence << endl;
cout << "Health:" << Health << endl;
cout << "Advantage:Water" << endl;
cout << "Disadvantage:Fire" << endl << endl;
pause(5);
//Nature vs Fire
if (OpponentCharacterDetails == "Fire" )
{
Attack = Attack / 2;
}
//Nature vs Water
if (OpponentCharacterDetails == "Water" )
{
Attack = OAttack * 0;
}
//Nature vs Nature
if (OpponentCharacterDetails == "Nature" )
{
Attack = Attack + 0;
}
system("CLS" );
}
void OpponentMonster1()
{
OpponentCharacterDetails == "Fire" ;
cout << "Your opponent sent out a fire type." <<endl;
cout << "Its stats are" <<endl<<endl;
cout << "Attack:" << OAttack << endl;
cout << "Defense:" << ODefence << endl;
cout << "Health:" << OHealth << endl << endl;
cout << "Advantage:Nature" << endl;
cout << "Disadvantage:Water" << endl;
pause(5);
//fire vs fire
if (CharacterDetails == "Fire" )
{
OAttack = OAttack + 0;
}
//fire vs water
if (CharacterDetails == "Water" )
{
OAttack = OAttack / 2;
}
//fire vs nature
if (CharacterDetails == "Nature" )
{
OAttack = OAttack * 2;
}
system("CLS" );
}
void OpponentMonster2()
{
OpponentCharacterDetails == "Water" ;
cout << "Your opponent sent out a water type." <<endl;
cout << "Its stats are" <<endl<<endl;
cout << "Attack:" << OAttack << endl;
cout << "Defense:" << ODefence << endl;
cout << "Health:" << OHealth << endl << endl;
cout << "Advantage:Fire" << endl;
cout << "Disadvantage:Nature" << endl;
pause(5);
//water vs fire
if (CharacterDetails == "Fire" )
{
OAttack = OAttack * 2;
}
//water vs water
if (CharacterDetails == "Water" )
{
OAttack = OAttack + 0;
}
//water vs nature
if (CharacterDetails == "Nature" )
{
OAttack = OAttack / 2;
}
}
void OpponentMonster3()
{
OpponentCharacterDetails == "Nature" ;
cout << "Your opponent sent out a nature type." <<endl;
cout << "Its stats are" <<endl<<endl;
cout << "Attack:" << OAttack << endl;
cout << "Defense:" << ODefence << endl;
cout << "Health:" << OHealth << endl << endl;
cout << "Advantage:Water" << endl;
cout << "Disadvantage:Fire" << endl;
pause(5);
//Nature vs Fire
if (CharacterDetails == "Fire" )
{
OAttack = OAttack / 2;
}
//Nature vs Water
if (CharacterDetails == "Water" )
{
OAttack = OAttack * 2;
}
//Nature vs Nature
if (CharacterDetails == "Nature" )
{
OAttack = OAttack + 0;
}
}
Sep 18, 2012 at 7:22pm UTC
sorry about cutting off my code it only allowed a certain number of characters
Sep 18, 2012 at 7:25pm UTC
I have not taken a deep look. But is it with rand(); ?
Then you can't do anything about that(can you?) cause it uses an algorithm to generate pseudo integers
Last edited on Sep 18, 2012 at 7:25pm UTC
Sep 19, 2012 at 3:42pm UTC
You need to initialize the seed only once. Do it in main or something, but don't re-seed it everytime you call opponent.
Topic archived. No new replies allowed.