我想找到一种方法来将stat数据导入到正在进行的游戏中通过传播板?这就是我正在使用的:如何从外部源获取信息到游戏中
现在,例如..法术,为了命名它们,设置统计数字,并且能够通过数字来调用它们我有这样的事情在实际的代码中进行:
void spell(int & eMoney, int eSpell[10])
{
using namespace std;
char spellname[10][25] = {"Minor Heal", "Fire Shard", "Lightening Shard", "Ice Shard", "Magic Barrier", "Essence Of Life",
"Earth Shard", "Wind Shard", "Insigma", "Weaken"};
int spellcost[10] = {50, 80, 80, 80, 100, 100, 80, 80, 120, 80};
这是所有罚款和花花公子,它的作品...但它现在是一个问题,后来..我希望能够用一个电子表格,就像一个CSV文件,这样我就可以有一个流传表格就像刚才的法术,只是剑,只是俱乐部...我打算有一个非常大的选择,它是更加理想的能够编辑一个单一的文件成列和行,并让实际的游戏从外部文件中获取信息何时需要......但我无法弄清楚如何去做这件事?我愿意接受任何想法..
这里是我现在该怎么呼吁咒语的信息的例子:
case 2:
do
{
cout << "Which spell would you like to cast?\n\n";
for(x=0;x<10;x++)
cout << x+1 << ". " << spellname[x] << ": " << eSpell[x] << " left" << endl;
cout << "11. Leave\n\n>> ";
cin >> decision;
system("cls");
}
while((decision<1)&&(decision>11)||(eSpell[decision-1]==0));
switch(decision)
,这里是试算表我心里有基本的例子吗?起始于A1:
又如:
目前代码:
char monsters[16][25] = {"Wolf", "Bear", "Bandit", "Traveler", "Gargoyle", "Knight", "Warlock", "Mammoth", "Cyclops", "Unicorn", "Dragon", "Your Mother", "Demon", "Jesus", "Satan", "God"};
//monster strengths
int monsterdamagemax[16] = {32, 42, 53, 53, 65, 65, 75, 75, 85, 85, 90, 90, 95, 95, 110, 110};
int monsterdamagemin[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int monsterdefensemax[16] = {2, 7, 13, 13, 20, 20, 25, 25, 35, 35, 40, 40, 45, 45, 55, 55};
int monsterdefensemin[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int monsterhealth[16] = {32, 52, 73, 73, 95, 95, 118, 118, 142, 142, 167, 167, 193, 193, 220, 220};
int monsterspeed[16] = {7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15};
int monstergold[16] = {20, 30, 41, 41, 53, 53, 66, 66, 80, 80, 95, 95, 110, 110, 125, 125};
理想情况下,我希望能够得到所有从一个CSV文件,如:
mID mName mDmgMax mDmgMin mDefMax mDefMin mHp mSpeed mGold
1 Wolf 32 0 2 0 32 7 20
2 Bear 42 0 7 0 52 8 30
3 Bandit 53 0 13 0 73 9 41
4 Traveler 53 0 13 0 73 9 41
5 Gargoyle 65 0 20 0 95 10 53
6 Knight 65 0 20 0 95 10 53
7 Warlock 75 0 25 0 118 11 66
8 Mammoth 75 0 25 0 118 11 66
9 Cyclops 85 0 35 0 142 12 80
10 Unicorn 85 0 35 0 142 12 80
11 Dragon 90 0 40 0 167 13 95
12 Your Mother 90 0 40 0 167 13 95
13 Demon 95 0 45 0 193 14 110
14 Jesus 95 0 45 0 193 14 110
15 Statan 110 0 55 0 220 15 125
16 God 110 0 55 0 220 15 125
如何使用需要的信息制作文件并从中读取信息? – lapk 2011-12-23 04:40:01
@AzzA这就是想法,但我无法从实际的游戏中正确读取文件中的信息= \ – Leaum 2011-12-23 04:41:34
请查看http://www.cplusplus.com/reference/iostream/fstream上的C++文件流/, 例如。他们有大部分功能的小例子可以帮助您入门。基本上,如果您从未尝试从文件读取/写入,则需要练习如何读取格式化数据以及如何从中提取信息。这并不难,你只需要尝试一下,看看它是如何工作的,哪些功能是有用的。 – lapk 2011-12-23 04:47:41