【发布时间】:2012-03-21 12:45:39
【问题描述】:
“玩家必须有能力在游戏过程中随时知道包里有什么。该方法不接受任何参数,一旦调用,将列出包中的所有内容并显示包中的物品总数当前持有。它还会在当前显示的物品名称下列出每个魔法物品的特性。"
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
class MysticalBag
{
private:
int useContent,rangeContent;
string word;
public:
void inventory()
{
useContent;
rangeContent;
word;
}
void addItems()
{
cout << "Enter use count (1-3)" << endl;
cin >> useContent;
if(useContent > 1 && useContent < 4)
{
cout << "Enter content (1.0 - 100.0)" << endl;
cin >> rangeContent;
if(rangeContent > 1.0 && rangeContent < 101)
{
cout << "Enter items name as text" << endl;
cin >> word;
this->inventory();
}
else
{
cout << "Invalid" << endl;
}
}
else
{
cout << "Invalid!" << endl;
exit(1);
}
}
void showItems()
{
cout << "Showing Item content" << endl;
cout << word << endl;
cout << "U - " << useContent << ", C - " << rangeContent;
}
};
int main()
{
char choice;
MysticalBag start;
MysticalBag *Head = new MysticalBag();
MysticalBag *Body = new MysticalBag();
MysticalBag *Tail = new MysticalBag();
cout << "What do you want to do with the bag?" << endl << endl;
cout << "(a)dd item" << endl;
cout << "(r)emove item" << endl;
cout << "(s)how items" << endl;
cout << "e(x)it" << endl;
cin >> choice;
if(choice == 'a')
{
start.addItems();
main();
}
else if(choice == 'r')
{
}
else if(choice == 's')
{
start.showItems();
main();
}
else if(choice == 'x')
{
cout << "Thanks for playing!" << endl;
getch();
exit(1);
}
getch();
}
问题:
1.) 我如何在清单中输入任何值,但它不允许我接受任何参数。
2.) 如果用户想要放入两个项目。我该怎么做
3.) 在showItems()中显示多个项目
【问题讨论】:
-
4.) 为你的“问题”付出一些努力。