캠프 중 하나가 결과를 표시하는 데 문제가있는 텍스트 기반 비디오 게임 코드를 만든 기술 캠프를 감독합니다. 프로그램이 올바르게 컴파일되고 실행되는 동안 "치료"가 선택되면 플레이어의 건강 상태에 추가되지 않으며 사용자가 "공격"을 선택하면 0이됩니다. 나는 프로그래밍에 대한 지식이 제한되어 있으며, 내가 할 수있는 최선을 다해 도움을 주려고 노력하고 있으므로 여기에서 그의 경험이 즐겁고 만족 스러울 것입니다. 도움이나 조언을 제공 할 수 있다면 우리는 그렇게 감사 할 것입니다. 일반적으로텍스트 기반 어드벤처 게임
// Test for hard stuff.cpp : Defines the entry point for the console application.
//
// Bigger proj
// Constructors will make characters with rolling statistics
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
// declaring function for hit power
//int power(int str, int def);
int command;
class character
{
public:
character();
//~character();
string name;
float str;
float def;
float health; // hit points
float regen; // health regen amount
float roll; // for random value
float ouch; // amount of attack damage
float getAttack(void);
float getHeal(void);
void setRegen(float reg);
//void setHeal(float healAmt);
private:
};
character::character()
{
srand(time_t(NULL));
str = rand() % 30 + 5;
def = rand() % 30 + 5;
health = 100;
//Output to check the constructor is running properly
cout<< "Character has been created.\n";
}
void character::setRegen(float reg)
{
regen = reg;
}
float character::getAttack()
{
//defines the magnitude/power of attack
//function shows how much damage is inflicted
// ouch is how much damage is done
roll = rand() % 20 + 1; // range between 1 &20
if (roll <= 11)
{
ouch = str - (def /2);
}
else if ((roll <= 17) && (roll >= 12))
{
ouch = (str * 2) - (def/2);
}
else if ((roll <= 20) && (roll >= 18))
{
ouch = (str * 3) - (def/2);
//cout << "CRITICAL HIT!!";
}
return ouch;
}
float character::getHeal()
{
//this is what happens when you chose to heal
regen = rand() % 20 + 3;
cout << "regen value= " << regen<< ".\n";
return regen;
}
/*character::~character()
{
str = 0;
def = 0;
health = 0;
// Output to check the destructor is running properly
cout << "Character has been destroyed\n";
} */
int _tmain(int argc, _TCHAR* argv[])
{
//Class objects
character user, computer;
//Hard code in a name for the computer's player
computer.name = "ZOID\n";
float attackDamage;
float healthAdded;
user.setRegen(void);
//Recieve data for the user's player
cout<< "Please enter a name for your character:\n";
cin>> user.name;
//Output name and stats to the user
cout<< "\nYour name is: " << user.name << endl;
cout << "here are your statistics: \n"
<< "strength: " << user.str << endl
<< "Defense: " << user.def << endl
<< "Health: " << user.health << endl;
cout<< "oh no an oppenent appeared!!!\n";
cout<< "you will have to fight him!" << endl<< endl;
cout << "opponent's health: 100" << endl
<< "what would you like to do: heal (1), attack(2), or run(3).\n";
cin>> command;
switch(command)
{
case 1 :
healthAdded = user.getHeal();
cout<< ""<<user.name <<" has regenerated " << healthAdded << " health.\n";
break;
case 2 :
attackDamage = user.getAttack();
cout << "" <<user.name <<" did " << attackDamage << " damage to the opponent!\n";
break;
case 3:
cout<< ""<<user.name<<" got away!\n";
break;
default:
cout<< "Please enter a valid choice!";
} //end switch
return 0;
}
'srand'는 프로그램 시작시 한 번만 사용하도록 알려줍니다. – chris
는'user.getHeal'는 건강에 아무것도하지 않고 그렇지 않으면 사용하지 마십시오. 건강이 어떻게 바뀔지는 모르겠다. – chris
만 재생성를 제공하고 재생성 아직 건강에 연결되지 않았습니다. turn-based iteration은 어디에 있습니까? Regen이 거기에서 일하기로되어 있습니다. 아이들을 도와 주려고 및 재미있는 방법으로 프로그램 학습을 장려 –