Skip to content

Instantly share code, notes, and snippets.

@sawamur
Created August 24, 2019 05:24
Show Gist options
  • Save sawamur/df05172c7507be3800a8c9921dbb4702 to your computer and use it in GitHub Desktop.
Save sawamur/df05172c7507be3800a8c9921dbb4702 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
#include <thread>
#include <unordered_map>
#include <cmath>
#include <algorithm>
struct Plus
{
bool hasKey; // 鍵を持っているか
bool hassward; //剣を持っているか
};
void sleep(int ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
int RandomInt(int min, int max)
{
std::random_device rd;
std::uniform_int_distribution<int> ud(min, max);
return ud(rd);
}
void Room0(Plus& plus, int& room)
{
sleep(2500);
std::cout << "ダンジョンの部屋 0 に入った\n";
sleep(2500);
std::cout << "どちらに進む? [1]左 [2]右[5]後ろ\n";
int n;
std::cin >> n;
room = n;
}
void Room1(Plus& plus, int& room)
{
std::cout << "ダンジョンの部屋 1 に入った\n";
sleep(2500);
if (plus.hasKey == false) // 鍵を持っていなければ
{
plus.hasKey = true;
std::cout << "鍵を拾った!\n";
sleep(2500);
}
if (plus.hassward)
{
std::cout << "光の石像を切りますか? 1.切る 2.切らない\n";
int A;
std::cin >> A;
if (A == 1)
{
std::cout << "光の石像が壊れ、外から日光が差し込んできた\n";
room = 100;
}
}
else
{
std::cout << "光の石像にふさがれている、さっきの部屋に戻ろう\n";
room = 0;
}
}
void Room2(Plus& plus, int& room)
{
std::cout << "ダンジョンの部屋 2 に入った\n";
sleep(2500);
if (plus.hasKey) // 鍵を持っていれば
{
std::cout << "鍵を使ったら扉が開いた!\n";
room = 3;
}
else
{
std::cout << "扉には鍵がかかっている…\n仕方ない、戻ろう\n";
room = 0;
}
}
void Room3(int intkey, int intkey2,int& room,Plus plus)
{
std::cout << "ダンジョンの部屋 3 に入った\n";
sleep(3000);
std::cout << "\n";
sleep(3000);
std::cout << "石板に「一つ目の合言葉は" << intkey << "だ」と書いてある。何のことだろう\n";
sleep(3000);
std::cout << "ダンジョンの部屋 4 に入った\n";
sleep(3000);
std::cout << "石板に「二つ目の合言葉は" << intkey2 << "だ」と書いてある。何のことだろう\n";
sleep(3000);
std::cout << "封印の石像がある\n";
sleep(3000);
if (plus.hassward)
{
std::cout << "封印の石像を切りますか? 1.切る 2.切らない\n";
int B;
std::cin >> B;
if (B == 1)
{
std::cout << "封印の石像が壊れ、外から大量のモンスターが襲ってきた。ゲームオーバー\n";
room = 800;
}
}
else
{
std::cout << "どうやらこの道は「部屋0」につながっているようだ\n";
room = 0;
}
}
void Room5(Plus& plus, int& room, int intkey, int intkey2)
{
std::cout << "ダンジョンの部屋 5 に入った\n";
sleep(3000);
std::cout << "炎の石像にさえぎられて通れない\n";
sleep(3000);
std::cout << "石板:「合言葉を二つ示せ!」\n";
sleep(3000);
std::cout << "一つ目のキーワードを入力してください\n";
int Keyword;
std::cin >> Keyword;
std::cout << "二つ目のキーワードを入力してください\n";
int keyword2;
std::cin >> keyword2;
if (Keyword == intkey && keyword2 == intkey2) // 合言葉を知っていれば
{
std::cout << "合言葉を使ったら石像が壊れた!\n";
room = 6;
}
else
{
std::cout << "......\n仕方ない、戻ろう\n";
room = 0;
}
}
void Room6(Plus & plus, int& room,int swd)
{
std::cout << "ダンジョンの部屋 6 に入った\n";
sleep(3000);
std::cout << "!\n";
sleep(3000);
std::cout << "宝箱だ!  1.開ける 2.何もせず戻る\n";
int choice;
std::cin >> choice;
if (choice == 1)
{
std::cout << "『岩砕きの大太刀』を手に入れた\n";
sleep(3000);
std::cout << "この刀は呪文" << swd << "を唱えることで力を解放し、このダンジョン中の石像を壊すことができる\n";
sleep(3000);
plus.hassward = true;
std::cout << "行き止まりだ、さっきの部屋に戻ろう\n";
room = 5;
sleep(3000);
std::cout << "!\n";
sleep(3000);
std::cout << "炎の石像が復活して道をふさいでいる!!屋根がだんだん下がって来たぞ!!\n";
for (;;)
{
auto start = std::chrono::system_clock::now();
std::cout << "このままでは押しつぶされてしまう!!!刀で石像を壊すんだ\n";
sleep(3000);
std::cout << "刀の力を開放するんだ!呪文を唱えろ!\n";
int D;
std::cin >> D;
auto end = std::chrono::system_clock::now();
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
if (time >= 6000)
{
std::cout << "遅い!!プラスは押しつぶされてしまった。ゲームオーバー\n";
room = 800;
break;
}
else if (D == swd)
{
std::cout << "やった!脱出成功だ!\n";
break;
}
else
{
std::cout << "呪文が間違っている\n";
}
}
}
else
{
std::cout << "行き止まりだ、さっきの部屋に戻ろう\n";
room = 0;
}
}
int main()
{
Plus plus;
plus.hasKey = false;
plus.hassward = false;
int intkey = RandomInt(1000,100000);
int intkey2 = RandomInt(1000, 100000);
int swd = RandomInt(10000, 100000);
int room = 0;
for (;;)
{
std::cout << "----------------\n";
switch (room)
{
case 0:
Room0(plus, room);
break;
case 1:
Room1(plus, room);
break;
case 2:
Room2(plus, room);
break;
case 3:
Room3(intkey,intkey2,room,plus);
break;
case 5:
Room5(plus, room, intkey,intkey2);
break;
case 6:
Room6(plus,room,swd);
break;
}
if (room == 100)
{
std::cout << "----------------------\n";
std::cout << "ダンジョンを脱出して新しい地方へたどり着いた\n";
break;
}
else if (room == 800)
{
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment