Well I have my program running and the Variables are not passing correctly and the return statements are not returning correctly.
Here is the parts that are not working.
#include <iostream>
#include "fight.h"
#include <time.h>
#include "player.h"
#include "stdlib.h"
#include <cstdlib>
usingnamespace std;
combat A;
combat::combat(void)
{
hit = 10;
zombiehitmod = 1;
zombiehitchance = 1;
zombiechop = 2;
playerhealth = 10;
zombiehealth = 3;
}
combat::~combat()
{
}
int combat::fight_combat()
{
cout << " Choose your attack. " << endl;
cout << " Enter 1 to shoot or 2 of Hand to Hand" << endl;
cout << " " << endl;
//cout << " prime is" << this -> prime << endl;
//cout << "ammo is "<< this -> ammo << endl;
//cout << "second is " << this -> second << endl;
//cout << "hitchance is " << this -> hitchance << endl;
//cout << " player health is " << A.playerhealth << endl;
//cout << " zombie health is " << A.zombiehealth << endl;
//cout << "randhit mod is" << randhitmod << endl;
cin >> A.attack;
cout << "Player health is " << A.playerhealth << endl;
cout << "zombie health is " << A.zombiehealth << endl;
cout << "random hit mod is " << A.randhitmod << endl;
A.playerAttack(); // call playerAttack function
if (A.zombiehealth <= 0) //move on
{
cout << "That was close hopefully there will not be too many of those." << endl;
}
A.deadAttack(); // call zombieAttack function
while (A.playerhealth > 0, A.zombiehealth > 0); //Loop until one or the other is dead
if (A.playerhealth <= 0) //game over
{
cout << "The zombie pulls you to the ground and starts to devour your flesh. Hopefully you will not feel this too long. " << endl;
cout << "Game over" << endl;
cin.get();
cin.get();
return 0;
}
cin.get();
cin.get();
return zombiehealth;
}
int combat::playerAttack() //player Attack function
{
//cout << "Player health is " << A.playerhealth << endl;
//cout << "zombie health is " << A.zombiehealth << endl;
//cout << "random hit mod is " << A.randhitmod << endl;
switch (A.attack)//if (A.attack == 1)
{
case 1: //pirmary attack
if (A.randhitmod + A.hitchance >= A.hit)
{
A.ammo --;
cout << "You hit the zombie" << endl; //Player hit zombie
A.zombiehealth = A.zombiehealth - A.prime;
}
else //if (randhitmod + this -> hitchance < A.hit, this -> ammo --)
{
A.ammo--;
cout << "You missed the zombie" << endl; // player misses zombie
}
if (A.ammo == 0) //ammo check
{
cout << "Click, click you are out of ammo." << endl;
A.hitchance = -9999;
}
break;
//if ( A.attack == 2)
case 2: //secondary attack
if (A.randhitmod + A.hitchance >= A.hit)
{
cout << "You hit the zombie" << endl;
A.zombiehealth = A.zombiehealth - A.second;
}
else //if (A.randhitmod + A.hitchance < A.hit)
{
cout << "You missed the zombie" << endl;
}
break;
default:
cout << "Please enter either 1 or 2." << endl;
break;
}
return A.zombiehealth;
}
int combat::deadAttack()//zombie attacks
{
//cout << "Player health is " << A.playerhealth << endl;
//cout << "zombie health is " << A.zombiehealth << endl;
//cout << "random hit mod is " << A.randhitmod << endl;
if (A.zombiehitmod + A.randhitmod >= A.hit) //zombie hits player
{
cout << "The zombie hits you" << endl;
A.playerhealth = A.playerhealth - A.zombiechop;
cout << "playerhealth is " << playerhealth <<endl;
}
else //if (A.zombiehitmod + A.randhitmod <= A.hit) //zombie deals damage
{
cout << "The zombie missed you" << endl;
}
return A.playerhealth;
}
#include <iostream>
usingnamespace std;
int a = 1;
int func(int a)
{
a = a + 1;
return a;
}
int main()
{
cout << a << endl;
a = func(a)
cout << a << endl;
system("PAUSE");
return 0;
}
but this needs to return a variable and the variable A.randhitmod ant the health variables are not passing correctly they end up being 0 somewhere nin the running of the program.
yes 0 is supposed to be dead, which is why each attack function is supposed to return the others health but if it is 0 in the function and doesn't return properly
A.randhit mod is supposed to be a random number set up earlier in this function.
#include <ctime>
#include <cstdio>
#include <cstdlib>
int func(int stuff)
{
srand((unsigned)time(0)); // seed the timer
int r = 1 + rand() % (5); /* make random number, put a "1 +" if you want from 1 - 5, remove if you want 0 - 5, "% (5)" is max number */
stuff = stuff + r;
return stuff;
}
You return zombiehealth in the battle functions. They're supposed to be implemented once as 10 and they will stay at 10 unless you wanted to change it. If you return it, the new value will turn into A.zombiehealth
exactly one returns player and the other returns zombie but it doesn't loop back like it supposed to should neither one be at zero and the end of the first run through the battle.
But I though that you should only return player, not zombie, and the fight sequence should have a loop withing itself and only return after the battle is done. Which it returns player health