diff --git a/src/AkizukiForest/Program.cs b/src/AkizukiForest/Program.cs index 9255817..4dded70 100644 --- a/src/AkizukiForest/Program.cs +++ b/src/AkizukiForest/Program.cs @@ -24,21 +24,21 @@ static int Main(string[] args) }; // 初期化 - bool where; // ループ用 + bool loopFlag; // ループ用 int section = 0; // セーブ用 string? command; // コマンド読み取り // ステータス - (int HP, int MP, int Luck) komari = (200, 30, 0); - - // 敵のステータス - (int HP, string Name) enemy = (0, ""); - - // アイテム - int item = 12; // アイテムの総重量 - int itemBom = 0; // 手榴弾の数 (手榴弾の重さはx2で算出) - int itemBullet = 0; // 弾丸の数 - int itemMedicine = 0; // 医療品の数 + Character komari = new() + { + Name = "秋月小鞠", + HP = 200, + MP = 30, + Luck = 10, + ItemBom = 0, + ItemBullet = 0, + ItemMedicine = 0 + }; if (File.Exists("Data.xml")) { @@ -61,7 +61,7 @@ static int Main(string[] args) try { - Load(); + Load(ref section, ref komari); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("ロードが成功しました。"); Console.ResetColor(); @@ -108,8 +108,7 @@ void InitialSettings() AnovReader("0.anov"); // アイテム選択処理 - bool selectingItem = true; - while (selectingItem == true) + while (true) { Console.WriteLine(""); Console.WriteLine("その他に冒険に持っていくものを決めてください"); @@ -120,45 +119,44 @@ void InitialSettings() Console.WriteLine("3: 医療品 (回復) [1つ当たりの重さ: 1]"); Console.WriteLine(""); - ItemSelection("1: 手榴弾", ref item, ref itemBom, 2); - ItemSelection("2: 弾薬", ref item, ref itemBullet, 1); - ItemSelection("3: 医療品", ref item, ref itemMedicine, 1); + // アイテムの初期化 + int tempItem = 12; // アイテムの総重量 + int tempItemBom = 0; // 手榴弾の数 (手榴弾の重さはx2で算出) + int tempItemBullet = 0; // 弾丸の数 + int tempItemMedicine = 0; // 医療品の数 + + ItemSelection("1: 手榴弾", ref tempItem, ref tempItemBom, 2); + ItemSelection("2: 弾薬", ref tempItem, ref tempItemBullet, 1); + ItemSelection("3: 医療品", ref tempItem, ref tempItemMedicine, 1); void ItemSelection(string _itemName, ref int _item, ref int _itemEach, int _itemWeight) { - bool selectingEachItems = true; - while (selectingEachItems == true) + while (true) { Console.WriteLine(_itemName + " を何個持っていきますか?"); if (int.TryParse(Console.ReadLine(), out _itemEach) && (_item - _itemEach * _itemWeight >= 0)) { _item -= _itemEach * _itemWeight; Console.WriteLine("{0}個 (重さ{1}|残り重量{2})", _itemEach, _itemEach * _itemWeight, _item); - selectingEachItems = false; + break; } else InvalidInput(); } } - Console.WriteLine($"手榴弾{itemBom}個、弾丸{itemBullet}個、医療品{itemMedicine}個でよろしいですか? (Y/n): "); + Console.WriteLine($"手榴弾{tempItemBom}個、弾丸{tempItemBullet}個、医療品{tempItemMedicine}個でよろしいですか? (Y/n): "); command = Console.ReadLine(); Console.WriteLine(""); if (command?.ToLower() == "n" || command?.ToLower() == "no") - { WarningConsole("もう一度設定します。"); - // アイテム数の初期化 - item = 12; - itemBom = 0; - itemBullet = 0; - itemMedicine = 0; - } else { - selectingItem = false; - // 現時点では、弾丸のセット数を記録しているため、弾数表記に変更 - itemBullet *= 10; + komari.ItemBom = tempItemBom; + komari.ItemBullet = tempItemBullet * 10; // 1セット=10発 + komari.ItemMedicine = tempItemMedicine; + break; } } @@ -171,8 +169,8 @@ void Section1() AnovReader("1.anov"); - where = false; - while (where == false) + loopFlag = true; + while (loopFlag) { Console.WriteLine(""); Console.WriteLine("どちらへ行きますか?"); @@ -186,31 +184,31 @@ void Section1() switch (command) { case "1": - where = true; + loopFlag = false; komari.Luck += 5; Console.WriteLine("珍しい植物を見つけた!"); Console.ReadLine(); break; case "2": - where = true; + loopFlag = false; Console.WriteLine("特にめぼしい物は見当たらなかった。"); Console.ReadLine(); break; case "3": - where = true; + loopFlag = false; Console.WriteLine("怪しい影に近づいてみると、何かはわからないが、中型の生物のように見える。"); Console.ReadLine(); Console.WriteLine("こちらに対して敵対的な視線を向けて、今すぐにでも攻撃してきそうだ。"); Console.ReadLine(); komari.Luck -= 5; // 戦闘処理 - Buttle(); + Buttle(komari); break; case "4": - Save(); + Save(section, komari); break; default: @@ -228,8 +226,8 @@ void Section2() AnovReader("2.anov"); - where = false; - while (where == false) + loopFlag = true; + while (loopFlag) { Console.WriteLine(""); Console.WriteLine("どうしますか"); @@ -243,13 +241,13 @@ void Section2() switch (command) { case "1": - where = true; + loopFlag = false; Console.WriteLine("見たことがない建物を見た秋月は、すぐにそこへ近づいた。"); Console.ReadLine(); break; case "2": - where = true; + loopFlag = false; Console.WriteLine("建造物の周辺を見渡すと、近くには紅の花と、鮮やかな秘色(ひそく)の花が咲き乱れていた。"); // 特に意味はないが、花の紹介 (後付け設定) @@ -273,7 +271,7 @@ void Section2() break; case "3": - where = true; + loopFlag = false; Console.WriteLine("一旦木陰で休憩することにした。"); Console.ReadLine(); Console.WriteLine("森林ならではの爽やかな風が頬に当たり心地が良い。"); @@ -289,7 +287,7 @@ void Section2() break; case "4": - Save(); + Save(section, komari); break; default: @@ -315,8 +313,8 @@ void Section3() Console.WriteLine("「うーん…どっちに行こうかなぁ」"); Console.ReadLine(); - where = false; - while (where == false) + loopFlag = true; + while (loopFlag) { Console.WriteLine(""); Console.WriteLine("どちらに行きますか"); @@ -329,7 +327,7 @@ void Section3() switch (command) { case "1": - where = true; + loopFlag = false; Console.WriteLine("右の道へ進んでいくと、その道はだんだんと細くなってきた。"); Console.ReadLine(); Console.WriteLine("だんだんと地下へと進んでいった。"); @@ -341,7 +339,6 @@ void Section3() break; case "2": - where = true; Console.WriteLine("道なりに進んでいくと、何かの影のようなものが見えた。"); Console.ReadLine(); Console.WriteLine("「なにかしら?」"); @@ -351,9 +348,9 @@ void Section3() Console.WriteLine("こちらにはまだ気づいていないようだ。"); Console.ReadLine(); - // 戦闘or道を戻って分岐点の右側の道に行くかの選択肢 - bool which = false; - while (which == false) + // 戦闘 or 道を戻って分岐点の右側の道に行くかの選択肢 + bool which = true; + while (which) { Console.WriteLine(""); Console.WriteLine("どうしますか"); @@ -364,14 +361,14 @@ void Section3() switch (command) { case "1": - which = true; + which = false; + loopFlag = false; //戦闘処理 - Buttle(); + Buttle(komari); break; case "2": - which = true; - where = false; + which = false; Console.WriteLine("先ほどの分岐点まで戻った。"); Console.ReadLine(); break; @@ -384,7 +381,7 @@ void Section3() break; case "3": - Save(); + Save(section, komari); break; default: @@ -399,7 +396,7 @@ void Section3() komari.HP = (komari.HP >= 260) ? komari.HP : 260; komari.MP = (komari.MP >= 30) ? komari.MP : 30; // 戦闘開始 - Buttle(); + Buttle(komari); Section6(); } @@ -414,8 +411,8 @@ void Section6() // 天空世界の頂上到達√…天空世界の結末(たまたま地下洞窟と天空世界でつながってしまったことなど)を明かす // 天空世界の地上到達√…地下空洞の過去を明かす // 秘密コマンドにて窓から飛び降りる→森の泉(隠し)√…次回作や尾花と桜(北大陸)の世界観についてのフラグ・ヒント/秋月の過去について - where = false; - while (where == false) + loopFlag = true; + while (loopFlag) { Console.WriteLine(""); Console.WriteLine("どうしますか"); @@ -432,20 +429,17 @@ void Section6() switch (command) { case "1": - where = true; + loopFlag = false; // 天空ルート(戦闘(ボス戦)後に神が現れて現世に戻らせてくれる) AnovReader("4.1.1.anov"); - // ボス戦 - enemy.HP = 1000; - enemy.Name = "黒色の影"; // (秋月回復) komari.HP = (komari.HP >= 300) ? komari.HP : 300; komari.HP += 240; komari.MP += 10; - // 戦闘開始 - Buttle(); + // 戦闘開始 (ボス戦) + Buttle(komari, 1000, "黒色の影"); AnovReader("4.1.2.anov"); @@ -461,16 +455,16 @@ void Section6() break; case "2": - where = true; + loopFlag = false; // 地上ルート (地下の場所に関する文献を読める。また、魔導書かワープ装置か何かで現世に戻る。) AnovReader("4.2.anov"); // 探索ターン // 最短√…机のメモを読む→本棚からメモに書いてある題名の本を探す→斜め読み→地上世界へ戻る魔法→終了 (神には遭遇しない) - bool which = false; - bool note = false; - while (which == false) + bool which = true; + bool checkedNote = false; // 机のメモ帳を見ているか見ていないか + while (which) { Console.WriteLine(""); Console.WriteLine("どこを調べますか"); @@ -484,20 +478,17 @@ void Section6() case "1": Console.WriteLine("20冊以上の本が並んでいた。"); Console.ReadLine(); - // 机のメモ帳を見ているか見ていないか - if (note == false) + if (checkedNote) { - // 机のメモ帳を見ていないときの処理 - Console.WriteLine("右から1冊取り、読んでみたがいまいち意味が分からなかった。"); - Console.ReadLine(); + // 机のメモ帳を見ているときの処理 + which = false; + AnovReader("4.2.1.anov"); } else { - // 机のメモ帳を見ているときの処理 - - AnovReader("4.2.1.anov"); - - which = true; + // 机のメモ帳を見ていないときの処理 + Console.WriteLine("右から1冊取り、読んでみたがいまいち意味が分からなかった。"); + Console.ReadLine(); } break; @@ -510,7 +501,7 @@ void Section6() Console.ReadLine(); Console.WriteLine("「天界のレートピシ」"); // レートピシ=歴史書 Console.ReadLine(); - note = true; + checkedNote = true; break; case "3": @@ -533,7 +524,7 @@ void Section6() break; case "3": - where = true; + loopFlag = false; AnovReader("3.3.anov"); @@ -546,7 +537,7 @@ void Section6() break; case "4": - Save(); + Save(section, komari); break; default: @@ -561,9 +552,7 @@ void Section6() // →旧黒軍師では3人いるが、航空隊2人の名前や詳細がまだ決まっていないため、椿という推測は一応可能だが。 // (未来になって航空隊2人の名前が決まっても、決まっていなかった時代のストーリーということで未来になっても上記と同じ考察が可能。)) if (komari.Luck >= 8) - { AnovReader("5.0.anov"); - } Console.WriteLine("# クレジット #"); Console.WriteLine("シナリオ: Lemon73 (Ivy Cafeteria)"); @@ -578,208 +567,212 @@ void Section6() // 医療品なんかそもそも使わなくても魔法回復できるし… (戦闘前のMP回復のおかげでほぼMP切れにならないし) // 難易度調整はミスった (簡単すぎた) かも (だからといって今から調整するのも面倒) } + } -// セーブ処理 -void Save() -{ - //データ保存(xml) - XElement element = new - ( - "Data", - new XElement("Section", section), - new XElement("komariHP", komari.HP), - new XElement("komariMP", komari.MP), - new XElement("KomariLuck", komari.Luck), - new XElement("Item", item), - new XElement("ItemBom", itemBom), - new XElement("ItemBullet", itemBullet), - new XElement("ItemMedicine", itemMedicine) - ); - element.Save("Data.xml"); - Console.WriteLine("セーブが完了しました。"); - Console.WriteLine("終了する際は、Ctrl+C を押してください。"); -} - -// ロード処理 -void Load() -{ - //ファイル読み込み - XDocument dataLoading = XDocument.Load(@"./Data.xml"); - - IEnumerable datas = dataLoading.Elements("Data"); - foreach (XElement data in datas) + /// + /// Saves the game data to an XML file. + /// + /// Current game section. + /// Your charactor. + static void Save(int section, Character chara) { - section = int.TryParse(data.Element("Section")?.Value, out var tempSection) ? tempSection : 0; - komari.HP = int.TryParse(data.Element("komariHP")?.Value, out int tempKomariHP) ? tempKomariHP : 200; - komari.MP = int.TryParse(data.Element("komariMP")?.Value, out int tempKomariMP) ? tempKomariMP : 20; - komari.Luck = int.TryParse(data.Element("KomariLuck")?.Value, out int tempKomariLuck) ? tempKomariLuck : 10; - item = int.TryParse(data.Element("Item")?.Value, out int tempItem) ? tempItem : 0; - itemBom = int.TryParse(data.Element("ItemBom")?.Value, out int tempItemBom) ? tempItemBom : 2; - itemBullet = int.TryParse(data.Element("ItemBullet")?.Value, out int tempItemBullet) ? tempItemBullet : 4; - itemMedicine = int.TryParse(data.Element("ItemMedicine")?.Value, out int tempItemMedicine) ? tempItemMedicine : 4; + XElement element = new + ( + "Data", + new XElement("Section", section), + new XElement("komariHP", chara.HP), + new XElement("komariMP", chara.MP), + new XElement("KomariLuck", chara.Luck), + new XElement("ItemBom", chara.ItemBom), + new XElement("ItemBullet", chara.ItemBullet), + new XElement("ItemMedicine", chara.ItemMedicine) + ); + element.Save("Data.xml"); + Console.WriteLine("セーブが完了しました。"); + Console.WriteLine("終了する際は、Ctrl+C を押してください。"); } -} - -//戦闘処理 -void Buttle() -{ - Console.WriteLine(" -+-+- 戦闘開始 -+-+- "); - Console.ReadLine(); - Random rand = new(); + /// + /// Loads the game data from an XML file. + /// + /// Loaded game section. + /// Your charactor. + static void Load(ref int section, ref Character chara) + { + XDocument dataLoading = XDocument.Load(@"./Data.xml"); - int enemyDefaultHP = 100 + rand.Next(0, 15) * 10; // 100-240 (10刻み) - const string enemyDefaultName = "異形の存在"; + IEnumerable datas = dataLoading.Elements("Data"); + foreach (XElement data in datas) + { + section = int.TryParse(data.Element("Section")?.Value, out int tempSection) ? tempSection : 0; + chara.HP = int.TryParse(data.Element("komariHP")?.Value, out int tempHP) ? tempHP : 200; + chara.MP = int.TryParse(data.Element("komariMP")?.Value, out int tempMP) ? tempMP : 20; + chara.Luck = int.TryParse(data.Element("KomariLuck")?.Value, out int tempLuck) ? tempLuck : 10; + chara.ItemBom = int.TryParse(data.Element("ItemBom")?.Value, out int tempItemBom) ? tempItemBom : 2; + chara.ItemBullet = int.TryParse(data.Element("ItemBullet")?.Value, out int tempItemBullet) ? tempItemBullet : 4; + chara.ItemMedicine = int.TryParse(data.Element("ItemMedicine")?.Value, out int tempItemMedicine) ? tempItemMedicine : 4; + } + } - // HP が設定されていないときはランダム値に設定 - enemy.HP = (enemy.HP > 0) ? enemy.HP : enemyDefaultHP; - // 名前が設定されていないときは初期値に設定 - enemy.Name = (enemy.Name != "") ? enemy.Name : enemyDefaultName; + /// + /// Buttle function. + /// + /// Your charactor. + /// Enemy hit point. + /// Enemy name. + static void Buttle(Character chara, int enemyHP = 0, string enemyName = "異形の存在") + { + Random rand = new(); + // HP が設定されていないときはランダム値に設定 + if (enemyHP == 0) + enemyHP = 100 + rand.Next(0, 15) * 10; // 100-240 (10刻み) - // 戦闘開始時自動回復 (難易度調節) - komari.HP += 20 + rand.Next(0, 3) * 10; // 20-40 (10刻み) - komari.MP += rand.Next(2, 6); // 2-5 + // 戦闘開始時自動回復 (難易度調節) + chara.HP += 20 + rand.Next(0, 3) * 10; // 20-40 (10刻み) + chara.MP += rand.Next(2, 6); // 2-5 - while (enemy.HP > 0) - { - Console.WriteLine(" - あなたのターン - "); + Console.WriteLine(" -+-+- 戦闘開始 -+-+- "); Console.ReadLine(); - //キャラクターステータス表示 - Console.WriteLine(""); - Console.WriteLine("味方ステータス"); - Console.WriteLine("|秋月小鞠|HP: {0}|MP: {1}|", komari.HP, komari.MP); - Console.WriteLine(""); - Console.WriteLine("敵ステータス"); - Console.WriteLine("|{0}|HP: {1}|", enemy.Name, enemy.HP); - - //作成途中 - bool where = false; - while (where == false) + while (enemyHP > 0) { - Console.WriteLine(""); - Console.WriteLine("どのような行動をしますか"); - Console.WriteLine("1: ナイフ攻撃"); - Console.WriteLine("2: 手榴弾攻撃 (残り{0}個)", itemBom); - Console.WriteLine("3: 拳銃射撃 (残り{0}発)", itemBullet); - Console.WriteLine("4: 治療魔法");//MPを使って回復 - Console.WriteLine("5: 回復薬治療 (残り{0}個)", itemMedicine); - Console.WriteLine("6: 戦略的撤退");//逃げる - Console.WriteLine("7: 手榴弾退散 (残り{0}個)", itemBom);//手榴弾の爆破と同時に逃げることで「戦略的撤退」よりも高確率で逃げ切れる - Console.WriteLine("8: 敵味方のステータスを再確認"); + Console.WriteLine(" - あなたのターン - "); + Console.ReadLine(); + StatusConsole(chara, enemyHP, enemyName); - command = Console.ReadLine(); - switch (command) + bool loopFlag = true; + while (loopFlag) { - case "1": - where = true; - //近接戦闘 - Console.WriteLine("敵に接近して、ナイフを振り上げて…"); - Console.WriteLine("その腕を素早く振り降ろした。"); - Console.ReadLine(); - Console.WriteLine("敵はダメージを受けたようだ。"); - Console.ReadLine(); - enemy.HP -= 50;//固定ダメージ - break; + Console.WriteLine(""); + Console.WriteLine("どのような行動をしますか"); + Console.WriteLine("1: ナイフ攻撃"); + Console.WriteLine("2: 手榴弾攻撃 (残り{0}個)", chara.ItemBom); + Console.WriteLine("3: 拳銃射撃 (残り{0}発)", chara.ItemBullet); + Console.WriteLine("4: 治療魔法"); // MPを使って回復 + Console.WriteLine("5: 回復薬治療 (残り{0}個)", chara.ItemMedicine); + Console.WriteLine("6: 戦略的撤退"); // 逃げる + Console.WriteLine("7: 手榴弾退散 (残り{0}個)", chara.ItemBom); // 手榴弾の爆破と同時に逃げることで「戦略的撤退」よりも高確率で逃げ切れる + Console.WriteLine("8: 敵味方のステータスを再確認"); + + string? command = Console.ReadLine(); + switch (command) + { + // 近接戦闘 + case "1": + loopFlag = false; + Console.WriteLine("敵に接近して、ナイフを振り上げて…"); + Console.WriteLine("その腕を素早く振り降ろした。"); + Console.ReadLine(); + Console.WriteLine("敵はダメージを受けたようだ。"); + Console.ReadLine(); + enemyHP -= 50; // 固定ダメージ + break; - case "2": - //爆破攻撃 - if (itemBom > 0) - { - where = true; - itemBom -= 1; + // 爆破攻撃 + case "2": + if (chara.ItemBom <= 0) + { + WarningConsole("爆弾がないようだ。"); + break; + } + + loopFlag = false; + chara.ItemBom -= 1; Console.WriteLine("秋月は後ろずさりで少しずつ後退しながら、手榴弾のピンを抜いて、"); Console.WriteLine("敵のほうに向かって投げつけた。"); Console.ReadLine(); Console.WriteLine("しばらくすると、大きな爆発音を上げ、付近は白い煙に包まれた。"); Console.ReadLine(); - enemy.HP -= 150 + rand.Next(0, 4) * 10;//150~180(10刻み) - } - else - WarningConsole("爆弾がないようだ。"); - break; + enemyHP -= 150 + rand.Next(0, 4) * 10; // 150~180 (10刻み) + break; - case "3": - //射撃攻撃処理 - //(ナイフ/爆弾との違いのために命中率は低く、ダメージが大きい、貫通するとさらにダメージ増加とかのほうがいいかも。 - //↑一応、弾薬数が多いため攻撃可能回数がほぼ無限というメリットもあるけど。) - if (itemBullet > 0) - { - where = true; - itemBullet -= 1; + // 射撃攻撃処理 + case "3": + // (ナイフ/爆弾との違いのために命中率は低く、ダメージが大きい、貫通するとさらにダメージ増加とかのほうがいいかも。 + // ↑一応、弾薬数が多いため攻撃可能回数がほぼ無限というメリットもあるけど。) + if (chara.ItemBullet <= 0) + { + WarningConsole("弾薬が足りないようだ。"); + break; + } + + loopFlag = false; + chara.ItemBullet -= 1; Console.WriteLine("拳銃に弾丸を込め、単発射撃を行った。"); Console.ReadLine(); Console.WriteLine("拳銃は、爆音を上げて、強い反動を受けた。"); Console.ReadLine(); Console.WriteLine("弾丸は敵を直撃して、敵の体を貫通した。"); Console.ReadLine(); - enemy.HP -= 40 + rand.Next(0, 27) * 10;// 40~300(10刻み) - } - else - WarningConsole("弾薬が足りないようだ。"); - break; + enemyHP -= 40 + rand.Next(0, 27) * 10; // 40~300 (10刻み) + break; - case "4": - //治療処理 - where = true; - if (komari.MP >= 3) - { - komari.MP -= 3; - Console.WriteLine("「リヴァレド・ハート」"); - Console.WriteLine("両手を空にかざし、回復魔法を唱えた。"); - Console.ReadLine(); - Console.WriteLine("優しいオーラが秋月の体を包み込む。"); - Console.ReadLine(); - Console.WriteLine("傷は見る見るうちに回復していった。"); - Console.ReadLine(); - komari.HP += 150;//固定 - } - else - { - Console.WriteLine("魔力が足りないため、簡易的な治療のみ行うことにした。"); - Console.ReadLine(); - Console.WriteLine("ナイフでスカートの先を切り、その布で傷ついた部分を保護した。"); - Console.ReadLine(); - komari.HP += 40;//固定 - } + // 治療処理 + case "4": + loopFlag = false; + if (chara.MP >= 3) + { + chara.MP -= 3; + Console.WriteLine("「リヴァレド・ハート」"); + Console.WriteLine("両手を空にかざし、回復魔法を唱えた。"); + Console.ReadLine(); + Console.WriteLine("優しいオーラが秋月の体を包み込む。"); + Console.ReadLine(); + Console.WriteLine("傷は見る見るうちに回復していった。"); + Console.ReadLine(); + chara.HP += 150; // 固定 + } + else + { + Console.WriteLine("魔力が足りないため、簡易的な治療のみ行うことにした。"); + Console.ReadLine(); + Console.WriteLine("ナイフでスカートの先を切り、その布で傷ついた部分を保護した。"); + Console.ReadLine(); + chara.HP += 40; // 固定 + } + break; - break; + // アイテム治療処理 + case "5": + if (chara.ItemMedicine <= 0) + { + WarningConsole("治療薬がないようだ。"); + break; + } - case "5": - //アイテム治療処理 - if (itemMedicine > 0) - { - where = true; - itemMedicine -= 1; + loopFlag = false; + chara.ItemMedicine -= 1; Console.WriteLine("医療品をあさり、治療に使えそうな薬品などを取り出した。"); Console.ReadLine(); Console.WriteLine("傷ついた部分に治療薬を塗り、包帯で巻いて痛みを和らげることができた。"); Console.ReadLine(); - komari.HP += 220;//固定 - } - else - WarningConsole("治療薬がないようだ。"); - break; + chara.HP += 220; // 固定 + break; - case "6": - where = true; - //確立で逃げる処理(20%の確率で逃げられる) - if (rand.Next(0, 101) <= 20) - { - Console.WriteLine("敵からなんとか逃げ切ることができた。"); - Console.ReadLine(); - enemy.HP = 0; - } - else - WarningConsole("敵に回り込まれた。"); - break; + // 確立で逃げる処理 + case "6": + loopFlag = false; + if (rand.Next(0, 101) <= 20) // (20%の確率で逃げられる) + { + Console.WriteLine("敵からなんとか逃げ切ることができた。"); + Console.ReadLine(); + enemyHP = 0; + } + else + WarningConsole("敵に回り込まれた。"); + break; - case "7": - //手榴弾があるかを確認 - if (itemBom > 0) - { - where = true; - itemBom -= 1; + // 確立で逃げる処理 + case "7": + // 手榴弾があるかを確認 + if (chara.ItemBom <= 0) + { + WarningConsole("爆弾がないようだ。"); + break; + } + + loopFlag = false; + chara.ItemBom -= 1; Console.WriteLine("秋月は後ろずさりで少しずつ後退しながら、手榴弾のピンを抜いて、"); Console.WriteLine("明後日のほうに向かって投げつけた。"); Console.ReadLine(); @@ -788,116 +781,98 @@ void Buttle() Console.WriteLine("煙に紛れて逃げようと試みる。"); Console.ReadLine(); - //確立で逃げる処理(60%の確率で逃げられる) - if (rand.Next(0, 101) <= 60) + if (rand.Next(0, 101) <= 60) // (60%の確率で逃げられる) { Console.WriteLine("なんとか逃げ切ることができた。"); Console.ReadLine(); - enemy.HP = 0; + enemyHP = 0; } else WarningConsole("しかし、敵に回り込まれてしまった。"); // 敵にダメージはなし - } - else - WarningConsole("爆弾がないようだ。"); - break; - - case "8": - Console.WriteLine(""); - Console.WriteLine("味方ステータス"); - Console.WriteLine("|秋月小鞠|HP: {0}|MP: {1}|", komari.HP, komari.MP); - Console.WriteLine(""); - Console.WriteLine("敵ステータス"); - Console.WriteLine("|{0}|HP: {1}|", enemy.Name, enemy.HP); - break; - - default: - InvalidInput(); - break; - } + break; - //敵死亡判定 - if (enemy.HP <= 0) - { - switch (command) - { - case "6": - case "7": + case "8": + StatusConsole(chara, enemyHP, enemyName); break; default: - //逃げた場合以外表示 - Console.WriteLine("敵はその場に倒れ、もう二度と動かなくなった。"); - Console.ReadLine(); + InvalidInput(); break; } - enemy.Name = "";//敵の名前を未指定状態にする - Console.WriteLine(" -+-+- 戦闘終了 -+-+- "); - Console.ReadLine(); - Console.WriteLine("「ふう。何とかなったわね。」"); - Console.ReadLine(); - Console.WriteLine("「先へ進むわ。」"); - Console.ReadLine(); - } - else - { - // もし攻撃or回復(逃げる+誤入力以外)なら - // このif文で↓のバグを回避できる。 - // (8の「様子を見る」や誤コマンドの際に本来なら再度コマンドを選べるはずなのに、すぐに敵ターンに移行してしまうバグ。 - // 原因:whileの中に敵の処理を入れているから) - if (where == true) - { - // 続行 (敵ターン) - Console.WriteLine(" - 敵のターン - "); - Console.ReadLine(); - // 70% - if (rand.Next(10) < 7) - { - Console.WriteLine("敵からの攻撃"); - Console.ReadLine(); - komari.HP -= rand.Next(5, 14) * 10;//50~130(10刻み)(最大値が出るとまあまあ強いのでHPに注意。) - } - // 20% - else if (rand.Next(3) != 0) - { - Console.WriteLine("敵は様子を見ている。"); - Console.ReadLine(); - } - // 10% - else + // 敵死亡判定 + if (enemyHP <= 0) + { + if (command != "6" && command != "7") { - Console.WriteLine("敵は回復魔法を唱えた。"); + // 逃げた場合以外表示 + Console.WriteLine("敵はその場に倒れ、もう二度と動かなくなった。"); Console.ReadLine(); - enemy.HP += 120; // 固定 } - // 秋月死亡判定 - if (komari.HP <= 0) + Console.WriteLine(" -+-+- 戦闘終了 -+-+- "); + Console.ReadLine(); + Console.WriteLine("「ふう。何とかなったわね。」"); + Console.ReadLine(); + // Console.WriteLine("「先へ進むわ。」"); + // Console.ReadLine(); + } + else + { + // もし攻撃 or 回復 (逃げる+誤入力以外) なら + // この if 文で↓のバグを回避できる。 + // (8の「様子を見る」や誤コマンドの際に本来なら再度コマンドを選べるはずなのに、すぐに敵ターンに移行してしまうバグ。 + // 原因: while の中に敵の処理を入れているから) + if (!loopFlag) { - Console.ForegroundColor = ConsoleColor.Red; // 文字の色を変更 - Console.WriteLine(""); - Console.WriteLine("「う、うそ…」"); - Console.ReadLine(); - Console.WriteLine("体に大きな傷を負った秋月はもう、そこから動くことができなくなってしまった。"); - Console.ReadLine(); - Console.WriteLine("視界に広がる真紅の液体。それが自分の運命を示唆しているようだった。"); + // 続行 (敵ターン) + Console.WriteLine(" - 敵のターン - "); Console.ReadLine(); - Console.WriteLine("「こ…こんなところで死ぬはずは…」"); - Console.ReadLine(); - Console.WriteLine("言葉を言い終える前に、その人生の終わりを早々と迎えた。"); - Console.ReadLine(); - Console.ResetColor(); // 色をリセット - // 終了判定 - enemy.HP = 0; - Environment.Exit(0); + + if (rand.Next(10) < 7) // 70% + { + Console.WriteLine("敵からの攻撃"); + Console.ReadLine(); + chara.HP -= rand.Next(5, 14) * 10; // 50~130 (10刻み) (最大値が出るとまあまあ強いので HP に注意) + } + else if (rand.Next(3) != 0) // 20% + { + Console.WriteLine("敵は様子を見ている。"); + Console.ReadLine(); + } + else // 10% + { + Console.WriteLine("敵は回復魔法を唱えた。"); + Console.ReadLine(); + enemyHP += 120; // 固定 + } + + // 秋月死亡判定 + if (chara.HP <= 0) + { + Console.ForegroundColor = ConsoleColor.Red; // 文字の色を変更 + Console.WriteLine(""); + Console.WriteLine("「う、うそ…」"); + Console.ReadLine(); + Console.WriteLine("体に大きな傷を負った秋月はもう、そこから動くことができなくなってしまった。"); + Console.ReadLine(); + Console.WriteLine("視界に広がる真紅の液体。それが自分の運命を示唆していた。"); + Console.ReadLine(); + Console.WriteLine("「こ…こんなところで死ぬはずは…」"); + Console.ReadLine(); + Console.WriteLine("言葉を言い終える前に、その人生の終わりを早々と迎えた。"); + Console.ResetColor(); // 色をリセット + Console.ReadLine(); + // 終了判定 + enemyHP = 0; + Environment.Exit(0); + } } } } } } -} -} + /// /// Reads the .anov file and outputs the text to the console. /// @@ -950,4 +925,55 @@ static void WarningConsole(string message) Console.ResetColor(); Console.ReadLine(); } + + /// + /// Displays the status of the character and the enemy in the console. + /// + static void StatusConsole(Character chara, int? enemyHP, string? enemyName){ + Console.WriteLine(""); + Console.WriteLine("味方ステータス"); + Console.WriteLine($"|{chara.Name}|HP: {chara.HP}|MP: {chara.MP}|"); + + if (enemyHP is not null && enemyName is not null) + { + Console.WriteLine(""); + Console.WriteLine("敵ステータス"); + Console.WriteLine($"|{enemyName}|HP: {enemyHP}|"); + } + } +} + +/// +/// Represents a character in the game. +/// +public class Character +{ + /// + /// Name of the character. + /// + public required string Name { get; set; } + /// + /// Hit Points (HP) of the character. + /// + public int HP { get; set; } + /// + /// Magic Points (MP) of the character. + /// + public int MP { get; set; } + /// + /// Luck of the character. + /// + public int Luck { get; set; } + /// + /// Number of boms the character has. + /// + public int ItemBom { get; set; } + /// + /// Number of bullets the character has. + /// + public int ItemBullet { get; set; } + /// + /// Number of medical-kits the character has. + /// + public int ItemMedicine { get; set; } }