ここにコード全体を貼り付けることができませんでした。本体には大きすぎます。フルペーストはこちら(リンクは申し訳ありませんが、少し信用できないに見えます。)C++は特定の変数を表示しません
しかし、私はエラーがどこかにこれらのブロックであることをかなり確信しています。
これはすべての項目、変数、値のリストです。このコードで
void item1()
{
if(!isItem1Randomized)
{
shopItem1 = rand()%4+1;
isItem1Randomized = true;
}
if(shopItem1 == 1)
{
shopItem1Name = purchasableItem1Name;
shopItem1Description = itemHealthUpDescription;
shopItem1Price = purchasableItem1Price;
}
else if(shopItem1 == 2)
{
shopItem1Name = purchasableItem2Name;
shopItem1Description = itemWoodenSwordDescription;
shopItem1Price = purchasableItem2Price;
}
else if(shopItem1 == 3)
{
shopItem1Name = purchasableItem3Name;
shopItem1Description = itemLeatherBootsDescription;
shopItem1Price = purchasableItem3Price;
}
else if(shopItem1 == 4)
{
shopItem1Name = purchasableItem4Name;
shopItem1Description = itemGarnetNecklaceDescription;
shopItem1Price = purchasableItem4Price;
}
}
void item2()
{
if(!isItem2Randomized)
{
shopItem2 = rand()%4+1;
isItem2Randomized = true;
cout << shopItem2;
}
if(shopItem2 == 1)
{
shopItem2Name = purchasableItem5Name;
shopItem2Description = itemSpookyMemeStaffDescription;
shopItem2Price = purchasableItem5Price;
}
else if(shopItem2 == 2)
{
shopItem2Name = purchasableItem6Name;
shopItem2Description = itemLeatherHelmetDescription;
shopItem2Price = purchasableItem6Price;
}
else if(shopItem2 == 3)
{
shopItem2Name = purchasableItem7Name;
shopItem2Description = itemHealthPotionDescription;
shopItem2Price = purchasableItem7Price;
}
else if(shopItem2 == 4)
{
shopItem2Name = purchasableItem8Name;
shopItem2Description = itemManaPotionDescripton;
shopItem2Price = purchasableItem8Price;
}
}
void item3()
{
if(!isItem3Randomized)
{
shopItem3 = rand()%4+1;
isItem3Randomized = true;
}
if(shopItem3 == 1)
{
shopItem3Name = purchasableItem9Name;
shopItem3Description = itemHealthUpDescription;
shopItem3Price = purchasableItem9Price;
}
else if(shopItem3 == 2)
{
shopItem3Name = purchasableItem10Name;
shopItem3Description = itemWoodenSwordDescription;
shopItem3Price = purchasableItem10Price;
}
else if(shopItem3 == 3)
{
shopItem3Name = purchasableItem11Name;
shopItem3Description = itemLeatherBootsDescription;
shopItem3Price = purchasableItem11Price;
}
else if(shopItem3 == 4)
{
shopItem3Name = purchasableItem12Name;
shopItem3Description = itemGarnetNecklaceDescription;
shopItem3Price = purchasableItem12Price;
}
}
void item4()
{
if(!isItem4Randomized)
{
shopItem4 = rand()%4+1;
isItem4Randomized = true;
}
if(shopItem4 == 1)
{
shopItem4Name = purchasableItem13Name;
shopItem4Description = itemHealthUpDescription;
shopItem4Price = purchasableItem13Price;
}
else if(shopItem4 == 2)
{
shopItem4Name = purchasableItem14Name;
shopItem4Description = itemWoodenSwordDescription;
shopItem4Price = purchasableItem14Price;
}
else if(shopItem4 == 3)
{
shopItem4Name = purchasableItem15Name;
shopItem4Description = itemLeatherBootsDescription;
shopItem4Price = purchasableItem15Price;
}
else if(shopItem4 == 4)
{
shopItem4Name = purchasableItem16Name;
shopItem4Description = itemGarnetNecklaceDescription;
shopItem4Price = purchasableItem16Price;
}
}
void itemSelector()
{
item1();
item2();
item3();
item4();
}
void buyMenu()
{
if(mazeActive == 2)
{
if((shop1[17][17] == shop1[playerY][playerX]))
{
isEnteredShop = true;
}
else
{
isEnteredShop = false;
}
}
if(isEnteredShop)
{
itemSelector();
cout << "You have entered the shop. Items to buy: \n";
if(!isItem1Bought)
{
cout << "1. " << shopItem1Name << ":\n"
<< shopItem1Description << "\n" << "$" << shopItem1Price << "\n \n";
}
if(!isItem2Bought)
{
cout << "2. " << shopItem3Name << ":\n"
<< shopItem3Description << "\n" << "$" << shopItem3Price << "\n \n";
}
else
{
cout << "Something broke";
}
if(!isItem3Bought)
{
cout << "3. " << shopItem2Name << ":\n"
<< shopItem2Description << "\n" << "$" << shopItem2Price << "\n \n";
}
if(!isItem4Bought)
{
cout << "4. " << shopItem4Name << ":\n"
<< shopItem4Description << "\n" << "$" << shopItem4Price << "\n \n";
}
cout << "5. Exit shop. \n";
cin >> shop1ItemBought;
if((shop1ItemBought == 1) && (shopItem1Name == purchasableItem1Name))
{
playerHealthPoints = playerHealthPoints + itemHeartCanisterPlayerStatisticChanges;
playerCurrency = playerCurrency - purchasableItem1Price;
isItem1Bought = true;
isMoved = true;
}
else if((shop1ItemBought == 1) && (shopItem1Name == purchasableItem2Name))
{
playerDamage++;
playerCurrency = playerCurrency - purchasableItem2Price;
isItem1Bought = true;
isMoved = true;
}
else if((shop1ItemBought == 1) && (shopItem1Name == purchasableItem3Name))
{
speedStatistic++;
playerCurrency = playerCurrency - purchasableItem3Price;
isItem1Bought = true;
isMoved = true;
}
else if((shop1ItemBought == 1) && (shopItem1Name == purchasableItem4Name))
{
playerDamage++;
playerCurrency = playerCurrency - purchasableItem4Price;
isItem1Bought = true;
isMoved = true;
}
else if((shop1ItemBought == 2) && (shopItem1Name == purchasableItem5Name))
{
playerCurrency =- purchasableItem5Price;
hasSpookyMemeStaff = true;
isItem2Bought = true;
}
else if((shop1ItemBought == 2) && (shopItem1Name == purchasableItem6Name))
{
playerCurrency = playerCurrency - shopItem2Price;
playerDefense+=2;
isItem2Bought = true;
}
else if((shop1ItemBought == 2) && (shopItem1Name == purchasableItem7Name))
{
playerCurrency = playerCurrency - shopItem2Price;
playerHealthPoints++;
isItem2Bought = true;
}
else if((shop1ItemBought == 2) && (shopItem1Name == purchasableItem8Name))
{
playerCurrency = playerCurrency - shopItem2Price;
playerMana+=10;
isItem2Bought = true;
}
isEnteredShop = false;
}
}
すべての作品、ショップで1つのセクション以外:
void itemHeartCanister()
{
purchasableItem1Name = "Heart Canister";
itemHealthUpDescription = "Increases your maximum health by 1.";
purchasableItem1Price = 25;
}
void itemWoodenSword()
{
purchasableItem2Name = "Wooden Sword";
itemWoodenSwordDescription = "Increases your damage by 2.";
purchasableItem2Price = 40;
}
void itemLeatherBoots()
{
purchasableItem3Name = "Leather Boots";
itemLeatherBootsDescription = "Increases your speed and defense by 1.";
purchasableItem3Price = 30;
}
void itemGarnetNecklace()
{
purchasableItem4Name = "Garnet Necklace";
itemGarnetNecklaceDescription = "Increases your luck by 1.";
purchasableItem4Price = 50;
}
void itemSpookyMemeStaff()
{
purchasableItem5Name = "Spooky Meme Staff";
itemSpookyMemeStaffDescription = "Fires spooky memes that do 4.20 damage each";
purchasableItem5Price = 69;
}
void itemLeatherHelmet()
{
purchasableItem6Name = "Leather Helmet";
itemLeatherHelmetDescription = "A leather helmet that increases your defense by 2";
purchasableItem6Price = 35;
}
void itemHealthPotion()
{
purchasableItem7Name = "Health Potion";
itemHealthPotionDescription = "A health potion that restores one health point";
purchasableItem7Price = 20;
}
void itemManaPotion()
{
purchasableItem8Name = "Mana Potion";
itemManaPotionDescripton = "A potion that heals 10 mana points.";
purchasableItem8Price = 20;
}
void itemEnergyPotion()
{
purchasableItem9Name = "Energy Potion";
itemEnergyPotionDescription = "A potion that heals 10 points of health and mana.";
purchasableItem9Price = 45;
}
void itemStatusPotion()
{
purchasableItem10Name = "Status Potion";
itemStatusPotionDescription = "A potion that removes all bad status effects.";
purchasableItem10Price = 120;
}
void itemIceSword()
{
purchasableItem11Name = "Ice Sword";
itemIceSwordDescription = "A sword made of ice. Has a 40% chance to freeze enemies for 2 seconds.";
purchasableItem11Price = 150;
}
void itemBomb()
{
purchasableItem12Name = "Bomb";
itemBombDescription = "A bomb. Blows stuff up.";
purchasableItem12Price = 30;
}
void itemToyPlane()
{
purchasableItem13Name = "Toy Plane";
itemToyPlaneDescription = "A toy plane. Does absolutely nothing.";
purchasableItem13Price = 50;
}
void shopItemDatabase()
{
itemHeartCanister();
itemWoodenSword();
itemLeatherBoots();
itemGarnetNecklace();
itemSpookyMemeStaff();
itemLeatherHelmet();
itemEnergyPotion();
itemStatusPotion();
itemIceSword();
itemBomb();
itemToyPlane();
}
この
は買いメニューのためのコードの残りの部分です。 3番目の項目以外のすべての項目をショップに印刷します。私は周りの項目を切り替えることができ、それらの特定の項目がどこにあっても、それらは印刷されません。どんな助けもありがとうございます。
デバッガを使用してコードをステップ実行する方法を学ぶ必要があるようです。良いデバッガを使用すると、プログラムを1行ずつ実行し、どこからずれているかを確認することができます。これはプログラミングをする場合に不可欠なツールです。詳しい読書:** [小さなプログラムをデバッグする方法](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)** – NathanOliver
[最小、完全、 – cpplearner
[mcve](最小限の強調)を投稿すると、誰かがあなたのコードをデバッグするのを迷惑に思うかもしれません。 –