Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.34 KB | None | 0 0
  1. #include "DxLib.h"
  2. #include <string>
  3.  
  4. int konnnitiwasound = 0;
  5. int situreisimasitasound = 0;
  6. char String[256];
  7. char StringA[256];
  8. int InputHandle;
  9. int InputHandleA;
  10. int modoru = 0;
  11. std::string input;
  12. std::string message;
  13. std::string messageA;
  14.  
  15.  
  16.  
  17. int i;
  18.  
  19. int a[1] = { 3};
  20.  
  21. int suuti = 256;
  22.  
  23. int duration = 0;
  24. int konnnitiwa = 0;
  25. int sitaidou = 0;
  26. int sitaidouA = 0;
  27. int mozicount = 0;
  28. int mozicount2 = 0;
  29. int mozicount3 = 0;
  30.  
  31. int gimonnlock = 0;
  32.  
  33. // 自作文字列比較関数
  34. int my_strcmp(const char* s1, const char* s2) {
  35.     // 先頭から走査して差があればループ終了
  36.     for (; *s1 == *s2; s1++, s2++) {
  37.         // 終了前に終端文字が見つかったら差分なし
  38.         if (*s1 == '\0'&& *s2 == '\0') { return 0; }
  39.     } return *s1 > * s2 ? 1 : -1;
  40. }
  41.  
  42. int my_str2(const char* s1, const char* s2)//ここで入力した文字列と用意された文字列を引数として扱う。
  43.  
  44. {
  45.     //s1, s2を比較する関数を使うためだけにs2の文字列のサイズが必要なので、変数aに用意した文字列の情報s2を文字列の長さを測るための関数strlenに引数として渡す。
  46.     const size_t a = strlen(s2);
  47.     //無限ループする。
  48.     for (;;) {
  49.         //関数memcmpの返り値が0の時は一致した時なので、==0とする。
  50.         if (memcmp(s1, s2, a) == 0)
  51.  
  52.             return 1;//入力した文字列にい指定された文字列が入っていた場合は1を返すように設定した。
  53. //入力した文字列が最後の文字まで到達した場合は一致する文字列がないということなので0を返すようにした。
  54.         else if (*s1 == '\0')
  55.  
  56.             return 0;//入っていなかった
  57. //文字列が一致した場合でも一致する文字列がない場合でも入力した文字列の一文字分の文字コードのバイト数?が繰り上がるようにした。
  58.         else
  59.  
  60.             ++s1;
  61.  
  62.     }
  63.  
  64. }
  65.  
  66. int rireki = 0;
  67. int rireki2 = 0;
  68. int   LEFTmark = 0;
  69. const char* str[100] = {
  70.     "どんな映画が好きなんですか?","はい!大好きです!!あなたはどんな映画が好きですか? " ,"私は恋愛映画が好きです!",
  71. "人間観察が好きだからかもしれません。","申し訳ありません。わかりません。" ,"おはようございます。今日は何をなさるんですか?"};//ここで文字を直接書いてるので、この文字のバイト数が各posmozi[]に入るだけ
  72. int frame[100] = { 10,10 ,10,10,10,10};//次の一文字が出るまでのカウンタとして働いている、ここの数値を変えることで文字が一文字ずつ出るまでの間隔を設定できる。
  73. int posmozi[100];//文字のバイト数が入る箱を表している。
  74. int countS[100];//次の文字が出るまでのカウントするためのもの
  75. int z;//関数drawString外でも使えるように外にも定義を書いた。zの数値は関係なく、文字列が入った数列がif文により同じ変数zの時にframe[z]と同じになるまで+1されていったり、+2バイトor+1バイトされていくため、
  76. //文字が一文字ずつ入っていく、なんでzの変数に値を入れて動かす必要がないのだ。ちなみにfor (z = 0; z < 3; ++z)で書いてしまうとキーAを押した際のif文に関係なく関数drawStringの最初のzどこかに値が入っただけで繰り返しを開始してしまうため、今回のように同じ変数zの時にフレームを利用して描画するようにした。
  77. char c = str[z][posmozi[z]];//関数drawString外でも使えるように外にも定義を書いた。
  78.  
  79.  
  80. void drawString(int z, int x, int y, int color)
  81. {
  82.     c = str[z][posmozi[z]];//posmozi[z]
  83.     if (countS[z] == 0 && c != '\0')
  84.         posmozi[z] += IsDBCSLeadByte(c) ? 2 : 1;
  85.     if (++countS[z] == frame[z]) countS[z] = 0;
  86.     DrawFormatString(x, y, color, "%.*s", posmozi[z], str[z]);
  87.     DrawFormatString(300, 300, (0, 0, 255), "countS[0]は%d", countS[0]);
  88. }
  89.  
  90.  
  91. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  92. {
  93.  
  94.  
  95.     SetGraphMode(1500, 780, 32);         // ウィンドウの大きさを指定
  96.     ChangeWindowMode(TRUE);             // 全画面ではなくウインドウを使用
  97.     // DXライブラリの初期化
  98.     if (DxLib_Init() == -1) return -1;
  99.     SetFontSize(42);                             //サイズを42に変更
  100.     // 描画先を裏にする
  101.     SetDrawScreen(DX_SCREEN_BACK);
  102.  
  103.     // キー入力ハンドルを作る(キャンセルなし全角文字有り数値入力じゃなし)
  104.     //MakeKeyInputは開発者の方が一回呼び出せば使えるように作ったのでループ内には書かない。
  105.     InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
  106.  
  107.     // 作成したキー入力ハンドルをアクティブにする
  108.     SetActiveKeyInput(InputHandle);
  109.  
  110.     // キー入力終了待ちループ
  111.     // (ProcessMessageをループごとに行う)
  112.  
  113.     while (ProcessMessage() == 0)
  114.     {
  115.  
  116.         // 画面の初期化
  117.         ClearDrawScreen();
  118.  
  119.  
  120.         //まずは描画する部分から作る。
  121.         // 入力モードを描画
  122.         DrawKeyInputModeString(640, 480);
  123.         // 入力途中の文字列を描画
  124.         DrawKeyInputString(0, 0, InputHandle);//InputHandleはint型とリファレンスに書いてあったんで
  125.  
  126.  
  127.         //その後にif文での分岐を考える。
  128.           // 入力が終了している場合は終了
  129.           //ループ内とは言えエンターキー一回でCheckKeyInputが呼べればいい。
  130.          //エンターキーが押されていないとき?の部分。
  131.         if (CheckKeyInput(InputHandle) != 0) {
  132.  
  133.             // 入力された文字列を取得
  134.            
  135.             char buffer[256];//★InputHandleに入ったのは文字のデータなので、文字のデータが受け取れる変数の型にする。
  136.  
  137.             // 入力された文字列を取得、その文字列を数値に変換
  138.             GetKeyInputString(buffer, InputHandle);//ここでInputHandleに入力された文字列の数値をGetKeyInputStringにより文字コードに変換したものを上でchar型で定義したbufferに入れる。
  139.             input = buffer;//bufferに入った文字コードに変換したものを
  140.  
  141.  
  142.             DrawString(0, 0, input.c_str(), GetColor(255, 255, 255));
  143.  
  144.  
  145.  
  146.  
  147.             /* 配列の要素を出力 */
  148.            
  149.                 //inputに入った文字のデータを数値化するために input.c_str()を定義して、下のif文に使った。
  150.                
  151.             //変数inputに入る前はchar型のbufferに文字列が入るので、my_str2はchar*型を引数にとるため、char*型は文字列を定義するので、
  152.             //関数my_str2にはそのまま文字列が使えるので、その文字列が入っているbufferを直接書いた。
  153.            //---
  154. //※こんなフローになるべきなのかどうか,実際のところは知らんけれども
  155. //---
  156.  
  157. //とりあえず "映画"と"好き" を同時に満たすかどうかを判定
  158.             if (my_str2(buffer, "映画") && my_str2(buffer, "好き"))
  159.             {
  160.                 //"映画"と"好き"を満たしていて,さらに追加の条件も満たすかどうかを判定
  161.                 if (my_str2(buffer, "?")
  162.                     && (my_str2(buffer, "なぜ") || my_str2(buffer, "なんで"))
  163.                     )
  164.                 {
  165.                     //"映画"と"好き"と"?" を全て満たしていて,且つ,{"なぜ","なんで"}のうち少なくとも1つを満たす場合
  166.                     z = 3;
  167.                     ++mozicount;
  168.                 }
  169.  
  170.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  171.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  172.                 z = 0;
  173.                 ++mozicount;
  174.             }
  175.            
  176.             if (my_str2(buffer, "映画") && my_str2(buffer, "事実") || my_str2(buffer, "映画") && my_str2(buffer, "アクション")) {
  177.                     //  message = "どんな映画が好きなんですか?";
  178.                    // konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  179.                     //PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  180.                     z = 2;
  181.                     ++mozicount;
  182.             }
  183.            
  184.             if (my_str2(buffer, "おはよう") ) {
  185.                 //  message = "どんな映画が好きなんですか?";
  186.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  187.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  188.                 z = 5;
  189.                 ++mozicount;
  190.             }
  191.             else {
  192.                 z = 4;
  193.                 ++mozicount;
  194.             }
  195.  
  196.  
  197.             //duration = 1;
  198.             // 再度インプットハンドルをアクティブにする
  199.             SetActiveKeyInput(InputHandle);
  200.             // 入力文字列を初期化する
  201.             SetKeyInputString("", InputHandle);
  202.  
  203.         }
  204.  
  205.         //  DrawFormatString(100, 150, GetColor(255, 255, 0), "ProcessMessage()は%d,modoruは%d", ProcessMessage(), modoru);
  206.         DrawFormatString(0, 150, GetColor(255, 255, 0), "zは%d,konnnitiwaは%d,sitaidouは%d,mozicountは%d", z, konnnitiwa, sitaidou, mozicount);
  207.         DrawFormatString(0, 250, GetColor(255, 255, 0), "mozicount2は%d,input.c_str()は%d,  LEFTmarkは%d", mozicount2, input.c_str(), LEFTmark);
  208.  
  209.         //新しい言葉の処理
  210.        
  211.             //文字カウントが1の時
  212.             if (mozicount > 0 ) {
  213.                 drawString(z, 10, 100, GetColor(5, 255, 255));
  214.  
  215.             }
  216.        
  217.      
  218.         // 裏画面の内容を表画面に反映させる
  219.         ScreenFlip();
  220.  
  221.  
  222.  
  223.  
  224.  
  225.     }
  226.  
  227.     // 用済みのインプットハンドルを削除する
  228.     DeleteKeyInput(InputHandle);
  229.  
  230.     // 画面の初期化
  231.     ClearDrawScreen();
  232.  
  233.     // 裏画面の内容を表画面に反映させる
  234.     ScreenFlip();
  235.  
  236.     // キー入力待ち
  237.    // WaitKey();
  238.  
  239.     //ループないやループから出た後で何かしらの問題が発生したら終了する。
  240.     // DXライブラリの使用終了
  241.     DxLib_End();
  242.  
  243.     // 終了
  244.     return 0;
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement