Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.30 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. // 自作文字列比較関数
  32. int my_strcmp(const char* s1, const char* s2) {
  33.     // 先頭から走査して差があればループ終了
  34.     for (; *s1 == *s2; s1++, s2++) {
  35.         // 終了前に終端文字が見つかったら差分なし
  36.         if (*s1 == '\0'&& *s2 == '\0') { return 0; }
  37.     } return *s1 > * s2 ? 1 : -1;
  38. }
  39.  
  40. int my_str2(const char* s1, const char* s2)//ここで入力した文字列と用意された文字列を引数として扱う。
  41.  
  42. {
  43.     //s1, s2を比較する関数を使うためだけにs2の文字列のサイズが必要なので、変数aに用意した文字列の情報s2を文字列の長さを測るための関数strlenに引数として渡す。
  44.     const size_t a = strlen(s2);
  45.     //無限ループする。
  46.     for (;;) {
  47.         //関数memcmpの返り値が0の時は一致した時なので、==0とする。
  48.         if (memcmp(s1, s2, a) == 0)
  49.  
  50.             return 1;//入力した文字列にい指定された文字列が入っていた場合は1を返すように設定した。
  51. //入力した文字列が最後の文字まで到達した場合は一致する文字列がないということなので0を返すようにした。
  52.         else if (*s1 == '\0')
  53.  
  54.             return 0;//入っていなかった
  55. //文字列が一致した場合でも一致する文字列がない場合でも入力した文字列の一文字分の文字コードのバイト数?が繰り上がるようにした。
  56.         else
  57.  
  58.             ++s1;
  59.  
  60.     }
  61.  
  62. }
  63.  
  64. int rireki = 0;
  65. int rireki2 = 0;
  66. int   LEFTmark = 0;
  67. const char* str[100] = {
  68.     "どんな映画が好きなんですか?","はい!大好きです!!あなたはどんな映画が好きですか? " ,"私は恋愛映画が好きです!",
  69. "人間観察が好きだからかもしれません。","申し訳ありません。わかりません。" ,"おはようございます。今日は何をなさるんですか?"};//ここで文字を直接書いてるので、この文字のバイト数が各posmozi[]に入るだけ
  70. int frame[100] = { 10,10 ,10,10,10,10};//次の一文字が出るまでのカウンタとして働いている、ここの数値を変えることで文字が一文字ずつ出るまでの間隔を設定できる。
  71. int posmozi[100];//文字のバイト数が入る箱を表している。
  72. int countS[100];//次の文字が出るまでのカウントするためのもの
  73. int z;//関数drawString外でも使えるように外にも定義を書いた。zの数値は関係なく、文字列が入った数列がif文により同じ変数zの時にframe[z]と同じになるまで+1されていったり、+2バイトor+1バイトされていくため、
  74. //文字が一文字ずつ入っていく、なんでzの変数に値を入れて動かす必要がないのだ。ちなみにfor (z = 0; z < 3; ++z)で書いてしまうとキーAを押した際のif文に関係なく関数drawStringの最初のzどこかに値が入っただけで繰り返しを開始してしまうため、今回のように同じ変数zの時にフレームを利用して描画するようにした。
  75. char c = str[z][posmozi[z]];//関数drawString外でも使えるように外にも定義を書いた。
  76.  
  77.  
  78. void drawString(int z, int x, int y, int color)
  79. {
  80.     c = str[z][posmozi[z]];//posmozi[z]
  81.     if (countS[z] == 0 && c != '\0')
  82.         posmozi[z] += IsDBCSLeadByte(c) ? 2 : 1;
  83.     if (++countS[z] == frame[z]) countS[z] = 0;
  84.     DrawFormatString(x, y, color, "%.*s", posmozi[z], str[z]);
  85.     DrawFormatString(300, 300, (0, 0, 255), "countS[0]は%d", countS[0]);
  86. }
  87.  
  88.  
  89. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  90. {
  91.  
  92.  
  93.     SetGraphMode(1500, 780, 32);         // ウィンドウの大きさを指定
  94.     ChangeWindowMode(TRUE);             // 全画面ではなくウインドウを使用
  95.     // DXライブラリの初期化
  96.     if (DxLib_Init() == -1) return -1;
  97.     SetFontSize(42);                             //サイズを42に変更
  98.     // 描画先を裏にする
  99.     SetDrawScreen(DX_SCREEN_BACK);
  100.  
  101.     // キー入力ハンドルを作る(キャンセルなし全角文字有り数値入力じゃなし)
  102.     //MakeKeyInputは開発者の方が一回呼び出せば使えるように作ったのでループ内には書かない。
  103.     InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
  104.  
  105.     // 作成したキー入力ハンドルをアクティブにする
  106.     SetActiveKeyInput(InputHandle);
  107.  
  108.     // キー入力終了待ちループ
  109.     // (ProcessMessageをループごとに行う)
  110.  
  111.     while (ProcessMessage() == 0)
  112.     {
  113.  
  114.         // 画面の初期化
  115.         ClearDrawScreen();
  116.  
  117.  
  118.         //まずは描画する部分から作る。
  119.         // 入力モードを描画
  120.         DrawKeyInputModeString(640, 480);
  121.         // 入力途中の文字列を描画
  122.         DrawKeyInputString(0, 0, InputHandle);//InputHandleはint型とリファレンスに書いてあったんで
  123.  
  124.  
  125.         //その後にif文での分岐を考える。
  126.           // 入力が終了している場合は終了
  127.           //ループ内とは言えエンターキー一回でCheckKeyInputが呼べればいい。
  128.          //エンターキーが押されていないとき?の部分。
  129.         if (CheckKeyInput(InputHandle) != 0) {
  130.  
  131.             // 入力された文字列を取得
  132.            
  133.             char buffer[256];//★InputHandleに入ったのは文字のデータなので、文字のデータが受け取れる変数の型にする。
  134.  
  135.             // 入力された文字列を取得、その文字列を数値に変換
  136.             GetKeyInputString(buffer, InputHandle);//ここでInputHandleに入力された文字列の数値をGetKeyInputStringにより文字コードに変換したものを上でchar型で定義したbufferに入れる。
  137.             input = buffer;//bufferに入った文字コードに変換したものを
  138.  
  139.  
  140.             DrawString(0, 0, input.c_str(), GetColor(255, 255, 255));
  141.  
  142.  
  143.  
  144.  
  145.             /* 配列の要素を出力 */
  146.            
  147.                 //inputに入った文字のデータを数値化するために input.c_str()を定義して、下のif文に使った。
  148.                
  149.             //変数inputに入る前はchar型のbufferに文字列が入るので、my_str2はchar*型を引数にとるため、char*型は文字列を定義するので、
  150.             //関数my_str2にはそのまま文字列が使えるので、その文字列が入っているbufferを直接書いた。
  151.             if (my_str2(buffer, "映画") && my_str2(buffer, "好き")) {
  152.                     //  message = "どんな映画が好きなんですか?";
  153.                     konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  154.                     PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  155.                     z = 0;
  156.                     ++mozicount;
  157.                  
  158.                 }
  159.             if (my_str2(buffer, "映画") && my_str2(buffer, "好き")&& my_str2(buffer, "?")) {
  160.                 //  message = "どんな映画が好きなんですか?";
  161.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  162.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  163.                 z = 1;
  164.                 ++mozicount;
  165.              
  166.             }
  167.             if (my_str2(buffer, "映画") && my_str2(buffer, "事実") or my_str2(buffer, "映画") && my_str2(buffer, "アクション")) {
  168.                     //  message = "どんな映画が好きなんですか?";
  169.                    // konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  170.                     //PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  171.                     z = 2;
  172.                     ++mozicount;
  173.             }
  174.             if (my_str2(buffer, "なぜ") && my_str2(buffer, "映画") && my_str2(buffer, "好き") && my_str2(buffer, "?") or
  175.                 my_str2(buffer, "なんで") && my_str2(buffer, "映画")&& my_str2(buffer, "好き") && my_str2(buffer, "?")) {
  176.                 //  message = "どんな映画が好きなんですか?";
  177.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  178.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  179.                 z = 3;
  180.                 ++mozicount;
  181.             }
  182.             if (my_str2(buffer, "おはよう") ) {
  183.                 //  message = "どんな映画が好きなんですか?";
  184.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  185.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  186.                 z = 5;
  187.                 ++mozicount;
  188.             }
  189.             else {
  190.                 z = 4;
  191.                 ++mozicount;
  192.             }
  193.  
  194.  
  195.             //duration = 1;
  196.             // 再度インプットハンドルをアクティブにする
  197.             SetActiveKeyInput(InputHandle);
  198.             // 入力文字列を初期化する
  199.             SetKeyInputString("", InputHandle);
  200.  
  201.         }
  202.  
  203.         //  DrawFormatString(100, 150, GetColor(255, 255, 0), "ProcessMessage()は%d,modoruは%d", ProcessMessage(), modoru);
  204.         DrawFormatString(0, 150, GetColor(255, 255, 0), "zは%d,konnnitiwaは%d,sitaidouは%d,mozicountは%d", z, konnnitiwa, sitaidou, mozicount);
  205.         DrawFormatString(0, 250, GetColor(255, 255, 0), "mozicount2は%d,input.c_str()は%d,  LEFTmarkは%d", mozicount2, input.c_str(), LEFTmark);
  206.  
  207.         //新しい言葉の処理
  208.        
  209.             //文字カウントが1の時
  210.             if (mozicount > 0 ) {
  211.                 drawString(z, 10, 100, GetColor(5, 255, 255));
  212.  
  213.             }
  214.        
  215.      
  216.         // 裏画面の内容を表画面に反映させる
  217.         ScreenFlip();
  218.  
  219.  
  220.  
  221.  
  222.  
  223.     }
  224.  
  225.     // 用済みのインプットハンドルを削除する
  226.     DeleteKeyInput(InputHandle);
  227.  
  228.     // 画面の初期化
  229.     ClearDrawScreen();
  230.  
  231.     // 裏画面の内容を表画面に反映させる
  232.     ScreenFlip();
  233.  
  234.     // キー入力待ち
  235.    // WaitKey();
  236.  
  237.     //ループないやループから出た後で何かしらの問題が発生したら終了する。
  238.     // DXライブラリの使用終了
  239.     DxLib_End();
  240.  
  241.     // 終了
  242.     return 0;
  243. }
  244. ```
  245.  
  246. orの部分を || にしました。ですが問題は解決していません。
  247. ```
  248. #include "DxLib.h"
  249. #include <string>
  250.  
  251. int konnnitiwasound = 0;
  252. int situreisimasitasound = 0;
  253. char String[256];
  254. char StringA[256];
  255. int InputHandle;
  256. int InputHandleA;
  257. int modoru = 0;
  258. std::string input;
  259. std::string message;
  260. std::string messageA;
  261.  
  262.  
  263.  
  264. int i;
  265.  
  266. int a[1] = { 3};
  267.  
  268. int suuti = 256;
  269.  
  270. int duration = 0;
  271. int konnnitiwa = 0;
  272. int sitaidou = 0;
  273. int sitaidouA = 0;
  274. int mozicount = 0;
  275. int mozicount2 = 0;
  276. int mozicount3 = 0;
  277.  
  278. // 自作文字列比較関数
  279. int my_strcmp(const char* s1, const char* s2) {
  280.     // 先頭から走査して差があればループ終了
  281.     for (; *s1 == *s2; s1++, s2++) {
  282.         // 終了前に終端文字が見つかったら差分なし
  283.         if (*s1 == '\0'&& *s2 == '\0') { return 0; }
  284.     } return *s1 > * s2 ? 1 : -1;
  285. }
  286.  
  287. int my_str2(const char* s1, const char* s2)//ここで入力した文字列と用意された文字列を引数として扱う。
  288.  
  289. {
  290.     //s1, s2を比較する関数を使うためだけにs2の文字列のサイズが必要なので、変数aに用意した文字列の情報s2を文字列の長さを測るための関数strlenに引数として渡す。
  291.     const size_t a = strlen(s2);
  292.     //無限ループする。
  293.     for (;;) {
  294.         //関数memcmpの返り値が0の時は一致した時なので、==0とする。
  295.         if (memcmp(s1, s2, a) == 0)
  296.  
  297.             return 1;//入力した文字列にい指定された文字列が入っていた場合は1を返すように設定した。
  298. //入力した文字列が最後の文字まで到達した場合は一致する文字列がないということなので0を返すようにした。
  299.         else if (*s1 == '\0')
  300.  
  301.             return 0;//入っていなかった
  302. //文字列が一致した場合でも一致する文字列がない場合でも入力した文字列の一文字分の文字コードのバイト数?が繰り上がるようにした。
  303.         else
  304.  
  305.             ++s1;
  306.  
  307.     }
  308.  
  309. }
  310.  
  311. int rireki = 0;
  312. int rireki2 = 0;
  313. int   LEFTmark = 0;
  314. const char* str[100] = {
  315.     "どんな映画が好きなんですか?","はい!大好きです!!あなたはどんな映画が好きですか? " ,"私は恋愛映画が好きです!",
  316. "人間観察が好きだからかもしれません。","申し訳ありません。わかりません。" ,"おはようございます。今日は何をなさるんですか?"};//ここで文字を直接書いてるので、この文字のバイト数が各posmozi[]に入るだけ
  317. int frame[100] = { 10,10 ,10,10,10,10};//次の一文字が出るまでのカウンタとして働いている、ここの数値を変えることで文字が一文字ずつ出るまでの間隔を設定できる。
  318. int posmozi[100];//文字のバイト数が入る箱を表している。
  319. int countS[100];//次の文字が出るまでのカウントするためのもの
  320. int z;//関数drawString外でも使えるように外にも定義を書いた。zの数値は関係なく、文字列が入った数列がif文により同じ変数zの時にframe[z]と同じになるまで+1されていったり、+2バイトor+1バイトされていくため、
  321. //文字が一文字ずつ入っていく、なんでzの変数に値を入れて動かす必要がないのだ。ちなみにfor (z = 0; z < 3; ++z)で書いてしまうとキーAを押した際のif文に関係なく関数drawStringの最初のzどこかに値が入っただけで繰り返しを開始してしまうため、今回のように同じ変数zの時にフレームを利用して描画するようにした。
  322. char c = str[z][posmozi[z]];//関数drawString外でも使えるように外にも定義を書いた。
  323.  
  324.  
  325. void drawString(int z, int x, int y, int color)
  326. {
  327.     c = str[z][posmozi[z]];//posmozi[z]
  328.     if (countS[z] == 0 && c != '\0')
  329.         posmozi[z] += IsDBCSLeadByte(c) ? 2 : 1;
  330.     if (++countS[z] == frame[z]) countS[z] = 0;
  331.     DrawFormatString(x, y, color, "%.*s", posmozi[z], str[z]);
  332.     DrawFormatString(300, 300, (0, 0, 255), "countS[0]は%d", countS[0]);
  333. }
  334.  
  335.  
  336. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  337. {
  338.  
  339.  
  340.     SetGraphMode(1500, 780, 32);         // ウィンドウの大きさを指定
  341.     ChangeWindowMode(TRUE);             // 全画面ではなくウインドウを使用
  342.     // DXライブラリの初期化
  343.     if (DxLib_Init() == -1) return -1;
  344.     SetFontSize(42);                             //サイズを42に変更
  345.     // 描画先を裏にする
  346.     SetDrawScreen(DX_SCREEN_BACK);
  347.  
  348.     // キー入力ハンドルを作る(キャンセルなし全角文字有り数値入力じゃなし)
  349.     //MakeKeyInputは開発者の方が一回呼び出せば使えるように作ったのでループ内には書かない。
  350.     InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
  351.  
  352.     // 作成したキー入力ハンドルをアクティブにする
  353.     SetActiveKeyInput(InputHandle);
  354.  
  355.     // キー入力終了待ちループ
  356.     // (ProcessMessageをループごとに行う)
  357.  
  358.     while (ProcessMessage() == 0)
  359.     {
  360.  
  361.         // 画面の初期化
  362.         ClearDrawScreen();
  363.  
  364.  
  365.         //まずは描画する部分から作る。
  366.         // 入力モードを描画
  367.         DrawKeyInputModeString(640, 480);
  368.         // 入力途中の文字列を描画
  369.         DrawKeyInputString(0, 0, InputHandle);//InputHandleはint型とリファレンスに書いてあったんで
  370.  
  371.  
  372.         //その後にif文での分岐を考える。
  373.           // 入力が終了している場合は終了
  374.           //ループ内とは言えエンターキー一回でCheckKeyInputが呼べればいい。
  375.          //エンターキーが押されていないとき?の部分。
  376.         if (CheckKeyInput(InputHandle) != 0) {
  377.  
  378.             // 入力された文字列を取得
  379.            
  380.             char buffer[256];//★InputHandleに入ったのは文字のデータなので、文字のデータが受け取れる変数の型にする。
  381.  
  382.             // 入力された文字列を取得、その文字列を数値に変換
  383.             GetKeyInputString(buffer, InputHandle);//ここでInputHandleに入力された文字列の数値をGetKeyInputStringにより文字コードに変換したものを上でchar型で定義したbufferに入れる。
  384.             input = buffer;//bufferに入った文字コードに変換したものを
  385.  
  386.  
  387.             DrawString(0, 0, input.c_str(), GetColor(255, 255, 255));
  388.  
  389.  
  390.  
  391.  
  392.             /* 配列の要素を出力 */
  393.            
  394.                 //inputに入った文字のデータを数値化するために input.c_str()を定義して、下のif文に使った。
  395.                
  396.             //変数inputに入る前はchar型のbufferに文字列が入るので、my_str2はchar*型を引数にとるため、char*型は文字列を定義するので、
  397.             //関数my_str2にはそのまま文字列が使えるので、その文字列が入っているbufferを直接書いた。
  398.             if (my_str2(buffer, "映画") && my_str2(buffer, "好き")) {
  399.                     //  message = "どんな映画が好きなんですか?";
  400.                     konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  401.                     PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  402.                     z = 0;
  403.                     ++mozicount;
  404.                  
  405.                 }
  406.             if (my_str2(buffer, "映画") && my_str2(buffer, "好き")&& my_str2(buffer, "?")) {
  407.                 //  message = "どんな映画が好きなんですか?";
  408.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  409.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  410.                 z = 1;
  411.                 ++mozicount;
  412.              
  413.             }
  414.             if (my_str2(buffer, "映画") && my_str2(buffer, "事実") || my_str2(buffer, "映画") && my_str2(buffer, "アクション")) {
  415.                     //  message = "どんな映画が好きなんですか?";
  416.                    // konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  417.                     //PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  418.                     z = 2;
  419.                     ++mozicount;
  420.             }
  421.             if (my_str2(buffer, "なぜ") && my_str2(buffer, "映画") && my_str2(buffer, "好き") && my_str2(buffer, "?") ||
  422.                 my_str2(buffer, "なんで") && my_str2(buffer, "映画")&& my_str2(buffer, "好き") && my_str2(buffer, "?")) {
  423.                 //  message = "どんな映画が好きなんですか?";
  424.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  425.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  426.                 z = 3;
  427.                 ++mozicount;
  428.             }
  429.             if (my_str2(buffer, "おはよう") ) {
  430.                 //  message = "どんな映画が好きなんですか?";
  431.                 konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  432.                 PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  433.                 z = 5;
  434.                 ++mozicount;
  435.             }
  436.             else {
  437.                 z = 4;
  438.                 ++mozicount;
  439.             }
  440.  
  441.  
  442.             //duration = 1;
  443.             // 再度インプットハンドルをアクティブにする
  444.             SetActiveKeyInput(InputHandle);
  445.             // 入力文字列を初期化する
  446.             SetKeyInputString("", InputHandle);
  447.  
  448.         }
  449.  
  450.         //  DrawFormatString(100, 150, GetColor(255, 255, 0), "ProcessMessage()は%d,modoruは%d", ProcessMessage(), modoru);
  451.         DrawFormatString(0, 150, GetColor(255, 255, 0), "zは%d,konnnitiwaは%d,sitaidouは%d,mozicountは%d", z, konnnitiwa, sitaidou, mozicount);
  452.         DrawFormatString(0, 250, GetColor(255, 255, 0), "mozicount2は%d,input.c_str()は%d,  LEFTmarkは%d", mozicount2, input.c_str(), LEFTmark);
  453.  
  454.         //新しい言葉の処理
  455.        
  456.             //文字カウントが1の時
  457.             if (mozicount > 0 ) {
  458.                 drawString(z, 10, 100, GetColor(5, 255, 255));
  459.  
  460.             }
  461.        
  462.      
  463.         // 裏画面の内容を表画面に反映させる
  464.         ScreenFlip();
  465.  
  466.  
  467.  
  468.  
  469.  
  470.     }
  471.  
  472.     // 用済みのインプットハンドルを削除する
  473.     DeleteKeyInput(InputHandle);
  474.  
  475.     // 画面の初期化
  476.     ClearDrawScreen();
  477.  
  478.     // 裏画面の内容を表画面に反映させる
  479.     ScreenFlip();
  480.  
  481.     // キー入力待ち
  482.    // WaitKey();
  483.  
  484.     //ループないやループから出た後で何かしらの問題が発生したら終了する。
  485.     // DXライブラリの使用終了
  486.     DxLib_End();
  487.  
  488.     // 終了
  489.     return 0;
  490. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement