Guest User

Untitled

a guest
Jul 5th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.93 KB | None | 0 0
  1. #pragma warning(disable: 4996)
  2. #include "DxLib.h"
  3.  
  4. // drawString -- 文字を一字ずつ表示する
  5. void drawString(int x, int y, int color, int* pos, const char* str)
  6. {
  7.     char c = str[*pos];  // *pos は pos[0] で表示文字位置
  8.     if (pos[1] == 0 && c != '\0') *pos += IsDBCSLeadByte(c) ? 2 : 1;
  9.     if (++pos[1] == 10) pos[1] = 0;  // pos[1] はフレームカウンタ
  10.     DrawFormatString(x, y, color, "%.*s", *pos, str);
  11. }
  12.  
  13. int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  14. {
  15.     char buffer[256];    // ユーザ入力文字列
  16.     char buffer2[256];   // ファイルから読み込む 1行の文字列
  17.     int hyouzi = 0;      // ???
  18.     int mozicount = 0;   // ???
  19.     int gimonnlock = 0;  // ???
  20.     int gimon = 0;       // ???
  21.     int memorycount = 0; // ???
  22.     int memory = 0;      // ???
  23.  
  24.     const char* z = "";  // z は drawString で表示する文字列
  25.     int pos[2] = { 0 };  // z の表示文字位置(初期値をゼロにする)
  26.  
  27.     unsigned buf_color = GetColor(64, 255, 192);
  28.     unsigned z_color = GetColor(5, 255, 255);
  29.     unsigned debug_color = GetColor(255, 255, 0);
  30.  
  31.     SetGraphMode(1500, 780, 32);        // ウィンドウの大きさを指定
  32.     ChangeWindowMode(TRUE);             // 全画面ではなくウインドウを使用
  33.     if (DxLib_Init() == -1) return -1;  // DXライブラリの初期化
  34.     SetFontSize(33);                    // サイズの変更
  35.     SetDrawScreen(DX_SCREEN_BACK);      // 描画先を裏にする
  36.     int InputHandle = MakeKeyInput(150, FALSE, FALSE, FALSE);
  37.     SetActiveKeyInput(InputHandle); // 作成したキー入力ハンドルをアクティブにする
  38.  
  39.     while (ProcessMessage() == 0) {
  40.         ClearDrawScreen(); // 画面の初期化
  41.         DrawKeyInputModeString(1500, 0); // 入力モードを描画
  42.         DrawKeyInputString(0, 0, InputHandle); // 入力途中の文字列を描画
  43.  
  44.         if (CheckKeyInput(InputHandle) != 0) {
  45.             hyouzi = 0;
  46.             gimon = 0;
  47.             memorycount = 0;
  48.             ++mozicount;
  49.             GetKeyInputString(buffer, InputHandle); // 入力された文字列を取得
  50.  
  51.             if (strstr(buffer, "覚えて")) {
  52.                 z = "何を覚えますか?", pos[0] = pos[1] = 0;
  53.                 ++mozicount;
  54.                 memory = 1;
  55.                 gimon = 0;
  56.             }
  57.             else if (memory == 0) {
  58.                 FILE* fp = fopen("memo.txt", "r");
  59.                 if (fp == NULL) goto dxlib_end;
  60.                 z = "どうしましたか?", pos[0] = pos[1] = 0;
  61.                 while (fgets(buffer2, 256, fp)) {  // ファイルから読み込む
  62.                     if (strstr(buffer, "映画") && strstr(buffer, "好き") && strstr(buffer, "?")) {
  63.                         if (strstr(buffer, "どんな")) {
  64.                             ++mozicount;
  65.                             gimonnlock = 1;
  66.                             if (strstr(buffer2, "映画") && strstr(buffer2, "どんな")) {
  67.                                 hyouzi = 1;
  68.                                 break;
  69.                             }
  70.                         }
  71.                         if (strstr(buffer, "なんで") || strstr(buffer, "なぜ")) {
  72.                             ++mozicount;
  73.                             gimonnlock = 1;
  74.                             if (strstr(buffer2, "映画") && strstr(buffer2, "なぜ")) {
  75.                                 hyouzi = 1;
  76.                                 break;
  77.                             }
  78.                         }
  79.                     }
  80.                     if (strstr(buffer2, buffer)) {
  81.                         hyouzi = 1;
  82.                         break;
  83.                     }
  84.                     if (hyouzi == 0) {
  85.                         if (strcmp(buffer2, buffer) == 0) {
  86.                             gimon = 1;
  87.                         }
  88.                     }
  89.                     //!!入力した文字の入るbufferが空だった場合、hyouziを0として、buffer2の中身を表示しないようにする。
  90.                     if (buffer=="\0") {
  91.                         hyouzi = 0;
  92.                        
  93.                     }
  94.                 }
  95.                 fclose(fp);
  96.             }
  97.             if (memory == 1 && strstr(buffer, "→")) {
  98.                 ++mozicount;
  99.                 memory = 2;
  100.                 z = "記憶しました。", pos[0] = pos[1] = 0;
  101.             }
  102.             SetActiveKeyInput(InputHandle); // 再度インプットハンドルをアクティブにする
  103.             SetKeyInputString("", InputHandle); // 入力文字列を初期化する
  104.         }
  105.         if (memory == 2) {
  106.             FILE* fp = fopen("memo.txt", "a");
  107.             if (fp == NULL) goto dxlib_end;
  108.             fprintf(fp, "%s\n", buffer); // ファイルに書く
  109.             fclose(fp);
  110.             memory = 0;
  111.             memorycount = 1;
  112.         }
  113.         DrawFormatString(100, 320, debug_color, "mozicount = %d, z = %s",
  114.             mozicount, z);
  115.         DrawFormatString(100, 360, debug_color, "gimonnlock = %d, memory = %d",
  116.             gimonnlock, memory);
  117.         DrawFormatString(100, 400, debug_color, "gimon = %d, hyouzi = %d, memorycount = %d",
  118.             gimon, hyouzi, memorycount);
  119.  
  120.         if (mozicount > 0) {
  121.             drawString(10, 100, z_color, pos, z);
  122.         }
  123.         if (gimon == 0 && hyouzi == 1) {
  124.             DrawFormatString(100, 180, buf_color, "buffer2 = %s", buffer2);
  125.         }
  126.         if (hyouzi == 0 && mozicount > 0 && memory == 0 && memorycount == 0) {
  127.             z = "", pos[0] = pos[1] = 0;
  128.             DrawFormatString(10, 110, buf_color, "申し訳ありません %s とは何ですか?", buffer);
  129.         }
  130.  
  131.         ScreenFlip(); // 裏画面の内容を表画面に反映させる
  132.     }
  133. dxlib_end:
  134.     DeleteKeyInput(InputHandle); // 用済みのインプットハンドルを削除する
  135.     DxLib_End(); // DXライブラリの使用終了
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment