访问唯一指针变量并显示它们

时间:2013-12-25 13:10:40

标签: c++

我对这个网站和c ++编程都很新。我一直试图让某些事情发挥作用,我想我已经碰壁了。

对于我的项目,我尝试制作基于文本的RPG。我试图让它成为一名玩家可以在战斗中看到他们班级的统计数据,但我不知道如何展示它。帮助将不胜感激。

include <iostream>
#include "mage.h"
#include "Warrior.h"
#include "Rogue.h"
#include "CharacterType.h"
#include <memory>
#include <string>
#include "MainGame.h"
#include "Inventory.h"

using namespace std;


int GameStart()
{
    std::unique_ptr<blankCharacter> myCharacter;

    std::unique_ptr<Inventory> myInventory;


    string name;
    int choice;

    cout << " Please enter player name." << endl << endl;
    cin >> name;        
    system("cls");

    cout << "Please select fighting class." << endl << endl;
    cout <<" 1 - Mage" << endl;
    cout <<" 2 - Warrior" << endl;
    cout <<" 3 - Rogue" << endl;
    cin >> choice;

    switch(choice)
    {
        case 1: //Mage
            myCharacter = std::unique_ptr<blankCharacter>(new Mage(70,100,150,60));
            myInventory = std::unique_ptr<Inventory>(new Inventory(10, 30));
        break;

        case 2: //Warrior
            myCharacter = std::unique_ptr<blankCharacter>(new Warrior(100,160,50,60));
            myInventory = std::unique_ptr<Inventory>(new Inventory(10, 30));
        break;

        case 3: //Rogue
            myCharacter = std::unique_ptr<blankCharacter>(new Rogue(90,160,70,100));
            myInventory = std::unique_ptr<Inventory>(new Inventory(10, 30));
        break;

        default: 
        cout << "Please select a relivant value 1 to 3" << endl << endl;
        break;
    }



    system("cls");


    return 0;

}

2 个答案:

答案 0 :(得分:0)

由于您使用的是system("cls"),我将假设您使用的是Windows。我建议您阅读gotoxy函数的工作原理。

或者,如果我错了并且您使用的是Linux,那么请使用the NCURSES library

这两个都是控制台文本操作选项。如果你想为你的游戏提供更高级的东西,我担心答案不会很简短,但你可以先阅读更多关于unity等游戏引擎的内容,或者通过以下方式了解游戏图形的核心内容。学习OpenGLDirect X

我为没有更具体的问题而道歉,但这个问题非常普遍。

答案 1 :(得分:0)

    class blankCharacter
    {
     protected:
 int health;
 int stamina;
 int magic;
 int Attack1;
 int Attack2;
 int Attack3;
 int FirstAttack;
 int SecondAttack;
 int ThirdAttack;
 int healthTodeduct;




   public: 
blankCharacter(int Attack1,  int Attack2, int Attack3, int startingHealth, int        startingStamina, int startingMagic); // Constructor
~blankCharacter(); // Destructor
    }

解决问题的方法是指出价值。

     cout << "Magic: " << myCharacter->getMagic() << endl;
 cout << "Stamina: " << myCharacter->getStamina() <<     endl;
 cout << "Health: " << myCharacter->getHealth() << endl;