LoginSignup
0
0

More than 3 years have passed since last update.

楽しい虚空会話

Last updated at Posted at 2019-11-12

今回はとある社畜ちゃん漫画に出てきたラバーダック用のコードです。私はわんこ先生ではありません。ゼッタイニダ。

これは何か。

喋ることで自分の中のプログレスを進められる人がそれなりにいます。
アウトプットすることで一つ進むのです。
その過程をメモなりなんなりを取ることで、蓄積が可視化されます。

何をしているか。

見ての通りランダムに適当に出力しているだけです。
これを実行者に知られてはいけません。手品だからです。

発展

今回は、最大値を表示数を数字で決定していますが、もしかしたら、時間で決定したほうが楽しいかもしれません。
ループをチョロットいじるだけでできる目算です。

言い訳

デバッグはしましたが、完全ではない可能性があります。
それと、conio.hは言語の標準には入っていないヘッダーです。

コード

main.cpp
#include <iostream>
#include <string>
#include <cstdint>
#include <thread>
#include <chrono>
#include <random>

#include <conio.h>//not standard.

//#include "StopWatch_II.h"

//https://twitter.com/vitaone_/status/845954013103239168


//#include <chrono>

class StopWatch {
    std::chrono::high_resolution_clock::time_point S;
    std::chrono::high_resolution_clock::time_point E;
public:

    typedef std::chrono::milliseconds TimeType;

    StopWatch() { Start(); };

    bool Start() {
        S = E = std::chrono::high_resolution_clock::now();
        return true;
    }
    bool ReStart() {
        return Start();
    }
    bool Stop() {
        E = std::chrono::high_resolution_clock::now();
        return true;
    }

    bool Reset() {
        S = E = std::chrono::high_resolution_clock::now();
        return true;
    }
    template<class T = TimeType>
    T Ellipse() {
        return std::chrono::duration_cast<T>(std::chrono::high_resolution_clock::now() - S);
    }
    template<class T = TimeType>
    T Result() {
        return std::chrono::duration_cast<T>(E - S);
    }

};

bool ShowProgress(const std::string& Title, std::uintmax_t L, const std::string& Token) {

    std::uniform_int_distribution<> TL(16, 3500);
    std::uniform_int_distribution<> OL(0, 16*3);
    std::random_device rd;

    std::size_t GC = 0;
    StopWatch SW;
    std::cout << Title << ':';
    for (std::uintmax_t i = 0; i < L; i++) {
        std::chrono::milliseconds ms(TL(rd));
        SW.Start();
        std::cout << ' ';

        while (ms >= SW.Ellipse<>()) {
            std::cout <<(char)8<< Token[GC++];
            GC %= Token.size();
            std::this_thread::sleep_for(std::chrono::milliseconds(OL(rd)));

            if (_kbhit()) { if (_getch() == 27) { std::cout << "--->> Aborted!" << std::endl; goto L;}  }
        }
        std::cout <<(char)8<< '*';
    }

    std::cout << " --->> Task End?" << std::endl;

    L:

    std::cin.clear();

    return true;
}

bool ShowTitle() {
    std::cout << "Think With Duck." << std::endl;
    std::cout << "Hit Key to Start!" << std::endl;
    int Key = _getch();

    if (Key == 27) { return false; }

    std::cout << std::endl;

    return true;
}

int main() {

    if (ShowTitle() == false) { return -1; }

    std::random_device rd;
    std::uniform_int_distribution<> ui(7, 70);
    //std::mt19937 mt(rd());
    std::string T;
    int key = 0;
    do {
        std::cout << "TypeIn to Task Name:";
        std::cin >> T;
        std::cin.clear();

        std::cout << "Let's Think!!" << std::endl;

        std::this_thread::sleep_for(std::chrono::milliseconds(2750));

        std::cout << std::endl;

        ShowProgress(T, ui(rd), " -\|/*");
        std::cout << std::endl;
        std::cout << "You Have next Task?(y/n)";

        key = _getch();
        std::cout << std::endl;

    } while (key == 'y');

    std::cout << std::endl;
    std::cout << "complete this time." << std::endl;


    return true;
}

スクリーンショット

無題.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0