Created
February 15, 2020 12:12
-
-
Save LoadDragon0000000000/c9f6cb7516fefcad145b7989aa6a5e60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <ios> | |
#include <iomanip> | |
#pragma warning(disable:4996) | |
using namespace std; | |
const int DECK_NUM = 40; // デッキの総枚数 | |
int main() { | |
short NotDeckBuildSwitch = 9; // デッキ登録をするかどうか | |
// デッキの入力(初回のみ) | |
cout << "シナプス・キューブ(ver a)へようこそ" << endl; | |
cout << "このアプリケーションは、あなたが次にドローするカードの確率を計算します。" << endl; | |
cout << "※a版なので1デッキしか登録できません" << endl; | |
cout << endl; | |
cout << "新たにデッキを登録する場合は半角で0を、" << endl; | |
cout << "以前に作成したデッキを読み込む場合は半角で9を入力して下さい" << endl; | |
cin >> NotDeckBuildSwitch; | |
char CardList[DECK_NUM][80]; // カードリスト | |
short CardListNum[DECK_NUM]; // カードリストと対応した積んだカードの枚数 | |
for (int i = 0; i < DECK_NUM; ++i) { | |
CardListNum[i] = 0; | |
} | |
// デッキの登録 | |
if (NotDeckBuildSwitch == 0) { | |
for (int i = 0; i < DECK_NUM; i += CardListNum[i]) { | |
cout << i + 1 << "枚目のカードを入力して下さい(略称可):"; | |
cin >> CardList[i]; | |
cout << CardList[i] << " ですね" << " 何枚入れていますか?(半角で入力して下さい)(取り消す場合は0を入力して下さい)" << endl; | |
cin >> CardListNum[i]; | |
if (1 <= CardListNum[i] && CardListNum[i] <= 4) { | |
cout << CardList[i] << "を" << CardListNum[i] << " 枚でよろしいですね" << endl; | |
} | |
if (CardListNum[i] <= 0 || 5 <= CardListNum[i]) { | |
cout << "入力を取り消します" << endl; | |
CardList[i][0] = 'N'; | |
CardListNum[i] = 0; | |
} | |
} | |
// 登録したデッキの保存 | |
ofstream SaveDeck("./DeckA.txt"); | |
for (int i = 0; i < DECK_NUM; i += CardListNum[i]) { | |
SaveDeck << CardList[i] << ',' << CardListNum[i] << endl; | |
} | |
cout << endl; | |
cout << "あなたのデッキリストを登録しました" << endl; | |
cout << "(デッキリストはこのアプリと同じ場所に保存されます。メモ帳で編集も可能です)" << endl; | |
cout << endl; | |
for (int i = 0; i < DECK_NUM; i += CardListNum[i]) { | |
cout << CardList[i] << ' ' << CardListNum[i] << "枚" << endl; | |
} | |
} | |
// 保存したデッキの読み込み | |
char NumBuffer[20]; // CardListNumへ代入するためのバッファ | |
ifstream LoadDeck("./DeckA.txt"); | |
if (!LoadDeck) { | |
cout << "デッキを読み込めませんでした" << endl; | |
} | |
cout << endl; | |
cout << "デッキを読み込みます" << endl; | |
cout << endl; | |
for (int i = 0; i < DECK_NUM; i += CardListNum[i]) { | |
LoadDeck.getline(CardList[i], 79, ','); | |
LoadDeck.getline(NumBuffer, 19); | |
CardListNum[i] = atoi(NumBuffer); | |
} | |
// デッキリストの表示 | |
cout << "あなたのデッキリストを表示します" << endl; | |
cout << endl; | |
for (int i = 0; i < DECK_NUM; i += CardListNum[i]) { | |
cout << "ID:" << i << ' ' << CardList[i] << ' ' << CardListNum[i] << "枚" << endl; // \nは保存してあるのでendlは不要 | |
} | |
cout << endl; | |
// 確率計算 | |
float DeckNum = DECK_NUM; // 残りデッキ枚数 | |
short DrawID; | |
short CardListNum_tmp[DECK_NUM]; // 元データは参照用に残す必要があるので、コピーデータを表示 | |
for (int i = 0; i < DECK_NUM; ++i) { | |
CardListNum_tmp[i] = CardListNum[i]; | |
} | |
while (DeckNum >= 1) { | |
cout << endl; | |
cout << "ドローしたカードをIDで入力して下さい:"; | |
cin >> DrawID; | |
if (CardListNum[DrawID] != NULL) { | |
cout << endl; | |
cout << CardList[DrawID] << " をドローしました" << endl; | |
DeckNum -= 1.0f; | |
--CardListNum_tmp[DrawID]; // ドローしたカードの枚数を減らす | |
cout << endl; | |
} | |
cout << "あなたの残りのデッキ" << '(' << DeckNum << "枚)と次にドローするカードの確率を表示します" << endl; | |
cout << endl; | |
for (int i = 0; i < DECK_NUM; i += CardListNum[i]) { | |
cout << "ID:" << i << ' '; | |
cout.width(10); | |
cout << right << setw(30) << CardList[i] << " "; | |
cout << CardListNum_tmp[i] << "枚 "; | |
cout.width((CardListNum_tmp[i] / DeckNum) * 100.0f); | |
cout.fill('*'); | |
cout << ' ' << (CardListNum_tmp[i] / DeckNum) * 100.0f << '%' << endl; | |
cout.fill(' '); | |
} | |
} | |
cout << "デュエル終了 お疲れ様でした" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment