Advertisement
Guest User

Untitled

a guest
Jun 21st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.84 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. char deta1[] = { "私" };
  16. char deta2[] = { "は" };
  17. char deta3[] = { "映画" };
  18. char deta4[] = { "が" };
  19. char deta5[] = { "好き" };
  20.  
  21.  
  22. int i;
  23.  
  24. int a[1] = { 3};
  25.  
  26. int suuti = 256;
  27.  
  28. int duration = 0;
  29. int konnnitiwa = 0;
  30. int sitaidou = 0;
  31. int sitaidouA = 0;
  32. int mozicount = 0;
  33. int mozicount2 = 0;
  34. int mozicount3 = 0;
  35.  
  36. // 自作文字列比較関数
  37. int my_strcmp(const char* s1, const char* s2) {
  38.     // 先頭から走査して差があればループ終了
  39.     for (; *s1 == *s2; s1++, s2++) {
  40.         // 終了前に終端文字が見つかったら差分なし
  41.         if (*s1 == '\0'&& *s2 == '\0') { return 0; }
  42.     } return *s1 > * s2 ? 1 : -1;
  43. }
  44.  
  45. int my_str2(const char* s1, const char* s2)
  46.  
  47. {
  48.  
  49.     const size_t a = strlen(s2);
  50.  
  51.     for (;;) {
  52.  
  53.         if (memcmp(s1, s2, a) == 0)
  54.  
  55.             return 1;//入力した文字列にい指定された文字列が入っていた
  56.  
  57.         else if (*s1 == '\0')
  58.  
  59.             return 0;//入っていなかった
  60.  
  61.         else
  62.  
  63.             ++s1;
  64.  
  65.     }
  66.  
  67. }
  68. int rireki = 0;
  69. int rireki2 = 0;
  70. int   LEFTmark = 0;
  71. const char* str[3] = { "どんな映画が好きなんですか?","申し訳ございません! " ,"私は恋愛映画が好きです!"};//ここで文字を直接書いてるので、この文字のバイト数が各posmozi[]に入るだけ
  72. int frame[3] = { 10,10 ,10};//次の一文字が出るまでのカウンタとして働いている、ここの数値を変えることで文字が一文字ずつ出るまでの間隔を設定できる。
  73. int posmozi[20];//文字のバイト数が入る箱を表している。
  74. int countS[3];//次の文字が出るまでのカウントするためのもの
  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);
  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);
  139.             input = 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.                 //★関数strcmpには文字を数値化したものしか使えない。なので、nput.c_str()の関数でinput内の文字列のデータを数値化したのだ。
  151.             if (my_str2(input.c_str(), "映画") && my_str2(input.c_str(), "好きです")) {
  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(input.c_str(), "映画") && my_str2(input.c_str(), "事実")) {
  160.                     //  message = "どんな映画が好きなんですか?";
  161.                    // konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
  162.                     //PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
  163.                     z = 2;
  164.                     ++mozicount;
  165.                 }
  166.  
  167.  
  168.  
  169.  
  170.             //duration = 1;
  171.             // 再度インプットハンドルをアクティブにする
  172.             SetActiveKeyInput(InputHandle);
  173.             // 入力文字列を初期化する
  174.             SetKeyInputString("", InputHandle);
  175.  
  176.         }
  177.  
  178.         //  DrawFormatString(100, 150, GetColor(255, 255, 0), "ProcessMessage()は%d,modoruは%d", ProcessMessage(), modoru);
  179.         DrawFormatString(0, 150, GetColor(255, 255, 0), "zは%d,konnnitiwaは%d,sitaidouは%d,mozicountは%d", z, konnnitiwa, sitaidou, mozicount);
  180.         DrawFormatString(0, 250, GetColor(255, 255, 0), "mozicount2は%d,input.c_str()は%d,  LEFTmarkは%d", mozicount2, input.c_str(), LEFTmark);
  181.  
  182.         //新しい言葉の処理
  183.        
  184.             //文字カウントが1の時
  185.             if (mozicount > 0 ) {
  186.                 drawString(z, 10, 100, GetColor(5, 255, 255));
  187.  
  188.             }
  189.        
  190.      
  191.         // 裏画面の内容を表画面に反映させる
  192.         ScreenFlip();
  193.  
  194.  
  195.  
  196.  
  197.  
  198.     }
  199.  
  200.     // 用済みのインプットハンドルを削除する
  201.     DeleteKeyInput(InputHandle);
  202.  
  203.     // 画面の初期化
  204.     ClearDrawScreen();
  205.  
  206.     // 裏画面の内容を表画面に反映させる
  207.     ScreenFlip();
  208.  
  209.     // キー入力待ち
  210.    // WaitKey();
  211.  
  212.     //ループないやループから出た後で何かしらの問題が発生したら終了する。
  213.     // DXライブラリの使用終了
  214.     DxLib_End();
  215.  
  216.     // 終了
  217.     return 0;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement