由于某种原因,这个Ncurses代码(见下文)有时不会停止获取输入(使用getnstr()),停止打印(使用printw())或执行任何操作。 (Ncurses代码从int main()开始。为了完整起见,我已经包含了整个程序。这是我的第一个'大'项目)
#include <iostream>
#include <string>
#include <ncurses.h>
//name that will be avaliable to everything
std::string pubName;
//const which is the number of items
static const int numberOfItems = 5;
//Array with the 'human' names for items to help when displaying the items
static const std::string humanNames[numberOfItems] = {"Empty", "A Wooden Sword", "A Bronze Sword", "An Iron Sword", "A Steel Sword"};
//stores enums will values 0-6 with 0 meaning that the inventory has nothing in that slot and 1-6 being items;
enum item{NOITEM = 0, SWORDWD = 1, SWORDBRZ = 2, SWORDIRN = 3, SWORDSTL = 4, SWORDSCIMITAR = 5, DAGGER = 6};
class Player{
private:
//stores name of user
std::string name;
//stores 6 enums which are the current items which the user has. Default state is no items.
int inventory[6];
//variable to prevent the use of an empty slot. When item is added or removed it increments or decrements respectivly
int numOfItems;
//stores health data for each slot so that potions can't be used more than once and other such things
int invUseData[6];
//stores health data for player
int pHealth;
//prevents the incrementing of health above acceptable levels and allows for health ups (Give you more hearts).
int curMaxHealth;
public:
//sets default values
Player(std::string newName){
for (int n=0; n<6; n++) {
inventory[n] = NOITEM;
}
//sets name
name = newName;
//sets health to default 100
pHealth = 100;
//sets item count to 0
numOfItems = 0;
//set maxhealth to default 100.
curMaxHealth = 100;
}
//adds attempts to add item to inventory. If inventory is full it returns false if when inventory is full
bool addItToInv(item ){
//TODO
return false;
}
//negates one health point of an item. Returns false if health of slot is 0
bool useItem( int slot){
//TODO
return false;
}
//returns health of player
int returnHealth(){
return pHealth;
}
//returns name of player
std::string returnName(){
return name;
}
//returns name of item in slot
std::string returnNameOfSlot(int slotNum){
return humanNames[inventory[slotNum]];
}
};
//class for monster
class Monster{
private:
int health;
};
//Does all the things needed at the end of turn (I.E.: Checks health)
void onEndTurn(){
//TODO
}
int main(){
//sets up memory for a temporary name
char* nameTemp = new char[20];
initscr();
getnstr(nameTemp, 19);
clear();
move(1,0);
Player pOne(nameTemp);
std::string pubName = pOne.returnName();
delete nameTemp;
refresh();
printw(pubName.c_str());
refresh();
getch();
endwin();
return 0;
}
请询问您是否需要有关我的问题的更多详细信息。
提前致谢。