Jag håller på med ett litet RPG spel som projektarbete till min klass i programering.
Tyvärr vägrar den att göra de jag vill att den ska göra, nämligen regristrera när någon har fått en skada i en fajt.
Här är ett litet uttdrag ur spelet som innehåller de som inte fungerar (jag har gjort så att den går att komplimera):
[code:c++]#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
class Player {
private:
int health;
int strength;
int temp;
public:
void ability(int s, int h);
void damage(int a);
int attack();
int deffens();
void tempShield(int d);
int healthStats();
};
void Player::ability(int s, int h) {
strength = s;
health = h;
}
void Player::tempShield(int d){
temp = temp + d;
}
void Player::damage(int a) {
if (temp == 0){
health = health - a;
}
if (temp >1)
{
a = a - temp;
if (a > 0){
health = health - a; }
}
}
int Player::deffens(){
srand(time(NULL));
int r = rand() % strength + 1;
return r;
}
int Player::attack() {
srand(time(NULL));
int r = rand() % strength + 1;
return r;
}
int Player::healthStats(){
return health;
}
int randm();
void header();
int main(){
Player enemy, player;
int choice = 3;
while (choice >= 3 || choice <= 0){
system("cls");
header();
cout<<"Pick youre side, fool!\n";
cout<<"1. Maffia\n";
cout<<"2. Gangsters\n";
cin>>choice;
if (choice >= 3 || choice <= 0){
cout<<"What!? Press enter and then just pick one of the 2 alternatives!\n";
getchar();
cin.get();
}}
if (choice == 1){
player.ability(7,50);
enemy.ability(10,40);
}
else if (choice == 2) {
player.ability(10,40);
enemy.ability(7,50);
}
system("cls");
header();
cout<<"\nYou have chosen well. In order to train you for the future,\nwe will send in an oponent for you!";
cin.get();
getchar();
int ahealth = player.healthStats();
int bhealth = enemy.healthStats();
while ( ahealth > 0 && bhealth > 0){
system("cls");
header();
cout<< "An unknown villian has attacked!";
cout<<"\n\n\n";
cout<<"You:"<<ahealth<<" Youre enemy:"<<bhealth;
cout<<"\n\nWhat do you wish to do?\n";
cout<<"\n1.Punch 2.Block\n";
cin>>choice;
while (choice >= 3 || choice <= 0){
cout<<"\n Please enter a valid choice!\n\n";
cin>>choice;
}
if (choice == 1){
int attack = player.attack();
enemy.damage(attack);
system("cls");
header();
cout<<"Youre punch caused "<<attack<<" in damage!";
getchar();
cin.get();
if (bhealth < 0){
break;
}
else{}
}
if (choice == 2) {
int deffense = player.deffens();
player.tempShield(deffense);
system("cls");
header();
cout<<"Your deffence rose!";
getchar();
cin.get();
}
int enemychoice = randm();
if (enemychoice == 1){
int attack = enemy.attack();
player.damage(attack);
system("cls");
header();
cout<<"You where punched by your enemy! It cost "<<attack<<" of your life!";
getchar();
cin.get();
if (ahealth < 0){
break;
}
else{}
}
if (enemychoice == 2){
int deffense = enemy.deffens();
enemy.tempShield(deffense);
system("cls");
header();
cout<<"Your enemy's deffence rose!";
getchar();
cin.get();
}
}
int a = 1;
return a;
}
int randm()
{srand((unsigned)time(0));
srand(time(NULL));
int r = rand() % 2 + 1;
return r;
}
//Ögongodis, strunta i det här :D
void header()
{
cout<< " _\n";
cout<< " | |\n";
cout<< " __| | ____ _____ _____ ____ ___ ____ _____ ____ _____\n";
cout<< " / _ | / ___)| ___ |(____ || \\ /___) / ___)(____ || _ \\ | ___ |\n";
cout<< "( (_| || | | ____|/ ___ || | | ||___ |( (___ / ___ || |_| || ____|\n";
cout<< " \\____||_| |_____)\\_____||_|_|_|(___/ \\____)\\_____|| __/ |_____)\n";
cout<<" |_|\n";
}
[/code]
Uppskattar all hjälp jag kan få!