我想找到一種方法來將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