コード例 #1
0
ファイル: GameTest.cpp プロジェクト: fgamador/WumpusStart
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include "Game.h"
#include "Msg.h"

TEST_CASE("Game")
{
    Game game;
    game.SetPlayerRoom(2);
    strvec output = game.Input("");
    REQUIRE(output == strvec({
        Msg::HuntTheWumpus,
        "",
        Msg::YouAreInRoom + "2",
        Msg::TunnelsLeadTo + "1 3 10"
    }));
}
コード例 #2
0
ファイル: satori_sentence.cpp プロジェクト: yagi/satori
string Satori::SentenceToSakuraScriptExec(const Talk& vec)
{
    string jump_to;
    string result;
    ptrdiff_t ip = 0;
    const Talk* pVec = &vec;
    bool comAndMode = mRequestID!="OnCommunicate";

    //実行環境初期化
    string allresult = "\\1";

    question_num = 0;	// 選択肢番号
    chars_spoken = 0;	// 喋った字数
    next_wait_value = 0; // ウェイト処理

    int jumpcount = 0;

    speaker = 1;	// 本体は 0 うにゅうは 1
    bool jump_inited = true;

    //return禁止
    kakko_replace_history.push(strvec()); // カッコの前方参照用

    while ( TRUE ) {
        if ( speaker != 1 && ! jump_inited ) {
            allresult += "\\1";
            speaker = 1;	// 本体は 0 うにゅうは 1
            jump_inited = true;
        }

        result = "";
        jump_to = "";

        kakko_replace_history.top().clear();
        int resp = SentenceToSakuraScriptInternal(*pVec,result,jump_to,ip);

        allresult += result;

        //resp == 0で全実行終了
        if ( ! resp ) {
            break;
        }

        //それ以外はどこかにジャンプを示す
        if ( resp == 1 ) {
            string jump = jump_to;
            m_escaper.unescape(jump);

            const Talk* pTR = GetSentenceInternal(jump);
            if ( ! pTR ) {
                sender << ">" << jump_to << " not found." << endl;
            }
            else {
                pVec = pTR;
                ip = 0;
                jump_inited = false;
            }
        }
        else if ( resp == 2 ) {
            string jump = jump_to;
            m_escaper.unescape(jump);

            const Talk* pTR = talks.communicate_search(jump, comAndMode);
            if ( ! pTR ) {
                sender << "≫" << jump_to << " not found." << endl;
            }
            else {
                pVec = pTR;
                ip = 0;
                jump_inited = false;
            }
        }
        ++jumpcount;

        if ( m_jump_limit > 0 && jumpcount >= m_jump_limit ) {
            sender << "ジャンプ回数超過" << endl;
            break;
        }
    }

    kakko_replace_history.pop(1);
    //return禁止終了

    return allresult;
}