诺比在这里.我正在尝试跨多个类对Player对象进行更改mainCharacter.我目前有一个Player声明如下所示的对象.在Player能够瞬移到各种世界和怪物进行战斗.
所有这些代码都有效.一旦一个世界的敌人被击败,他们就会被击败.我的问题是当他传送到另一个世界时,他们Player的统计数据都被重置为默认值; 即使在前世界遭受敌人的伤害之后,他仍然拥有完整的生命值.
如何Player跨多个类或世界对同一对象进行更改?我认为我的声明中存在问题,但我不确定.我很感激任何意见.谢谢!
当mainCharacter对象被声明:
class SpaceList
{
protected:
class SpaceNode
{
friend class SpaceList;
Player mainCharacter;
Space* thisSpace;
SpaceNode* next;
SpaceNode(int m, SpaceNode* next1 = NULL)
{
if(m == 0)
{
thisSpace = new EntranceHall(&mainCharacter);
}
else if(m == 1)
{
thisSpace = new WaterSpace(&mainCharacter);
}
Run Code Online (Sandbox Code Playgroud)
部分Player.hpp:
class Player: public Interactable
{
protected:
Backpack myBackpack;
public:
Player();
virtual interactableType getInteractableType();
virtual int interact(); …Run Code Online (Sandbox Code Playgroud) 我正在试图弄清楚如何计算部分程序的执行时间,但是当我使用下面的代码时,我得到的所有代码都是0.我知道这不可能是正确的.代码我正在递归地实现大量int的mergesort.如何在几毫秒内获得执行程序所需的时间?
//opening input file and storing contents into array
index = inputFileFunction(inputArray);
clock_t time = clock();//start the clock
//this is what needs to be timed
newRecursive.mergeSort(inputArray, 0, index - 1);
//getting the difference
time = clock() - time;
double ms = double(time) / CLOCKS_PER_SEC * 1000;
std::cout << "\nTime took to execute: " << std::setprecision(9) << ms << std::endl;
Run Code Online (Sandbox Code Playgroud)