Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable: 4996)
- #include "DxLib.h"
- // drawString -- 文字を一字ずつ表示する
- void drawString(int x, int y, int color, int* pos, const char* str)
- {
- char c = str[*pos]; // *pos は pos[0] で表示文字位置
- if (pos[1] == 0 && c != '\0') *pos += IsDBCSLeadByte(c) ? 2 : 1;
- if (++pos[1] == 10) pos[1] = 0; // pos[1] はフレームカウンタ
- DrawFormatString(x, y, color, "%.*s", *pos, str);
- }
- int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
- {
- char buffer[256]; // ユーザ入力文字列
- char buffer2[256]; // ファイルから読み込む 1行の文字列
- int hyouzi = 0; // ???
- int mozicount = 0; // ???
- int gimonnlock = 0; // ???
- int gimon = 0; // ???
- int memorycount = 0; // ???
- int memory = 0; // ???
- const char* z = ""; // z は drawString で表示する文字列
- int pos[2] = { 0 }; // z の表示文字位置(初期値をゼロにする)
- unsigned buf_color = GetColor(64, 255, 192);
- unsigned z_color = GetColor(5, 255, 255);
- unsigned debug_color = GetColor(255, 255, 0);
- SetGraphMode(1500, 780, 32); // ウィンドウの大きさを指定
- ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
- if (DxLib_Init() == -1) return -1; // DXライブラリの初期化
- SetFontSize(33); // サイズの変更
- SetDrawScreen(DX_SCREEN_BACK); // 描画先を裏にする
- int InputHandle = MakeKeyInput(150, FALSE, FALSE, FALSE);
- SetActiveKeyInput(InputHandle); // 作成したキー入力ハンドルをアクティブにする
- while (ProcessMessage() == 0) {
- ClearDrawScreen(); // 画面の初期化
- DrawKeyInputModeString(1500, 0); // 入力モードを描画
- DrawKeyInputString(0, 0, InputHandle); // 入力途中の文字列を描画
- if (CheckKeyInput(InputHandle) != 0) {
- hyouzi = 0;
- gimon = 0;
- memorycount = 0;
- ++mozicount;
- GetKeyInputString(buffer, InputHandle); // 入力された文字列を取得
- if (strstr(buffer, "覚えて")) {
- z = "何を覚えますか?", pos[0] = pos[1] = 0;
- ++mozicount;
- memory = 1;
- gimon = 0;
- }
- else if (memory == 0) {
- FILE* fp = fopen("memo.txt", "r");
- if (fp == NULL) goto dxlib_end;
- z = "どうしましたか?", pos[0] = pos[1] = 0;
- while (fgets(buffer2, 256, fp)) { // ファイルから読み込む
- if (strstr(buffer, "映画") && strstr(buffer, "好き") && strstr(buffer, "?")) {
- if (strstr(buffer, "どんな")) {
- ++mozicount;
- gimonnlock = 1;
- if (strstr(buffer2, "映画") && strstr(buffer2, "どんな")) {
- hyouzi = 1;
- break;
- }
- }
- if (strstr(buffer, "なんで") || strstr(buffer, "なぜ")) {
- ++mozicount;
- gimonnlock = 1;
- if (strstr(buffer2, "映画") && strstr(buffer2, "なぜ")) {
- hyouzi = 1;
- break;
- }
- }
- }
- if (strstr(buffer2, buffer)) {
- hyouzi = 1;
- break;
- }
- if (hyouzi == 0) {
- if (strcmp(buffer2, buffer) == 0) {
- gimon = 1;
- }
- }
- //!!入力した文字の入るbufferが空だった場合、hyouziを0として、buffer2の中身を表示しないようにする。
- if (buffer=="\0") {
- hyouzi = 0;
- }
- }
- fclose(fp);
- }
- if (memory == 1 && strstr(buffer, "→")) {
- ++mozicount;
- memory = 2;
- z = "記憶しました。", pos[0] = pos[1] = 0;
- }
- SetActiveKeyInput(InputHandle); // 再度インプットハンドルをアクティブにする
- SetKeyInputString("", InputHandle); // 入力文字列を初期化する
- }
- if (memory == 2) {
- FILE* fp = fopen("memo.txt", "a");
- if (fp == NULL) goto dxlib_end;
- fprintf(fp, "%s\n", buffer); // ファイルに書く
- fclose(fp);
- memory = 0;
- memorycount = 1;
- }
- DrawFormatString(100, 320, debug_color, "mozicount = %d, z = %s",
- mozicount, z);
- DrawFormatString(100, 360, debug_color, "gimonnlock = %d, memory = %d",
- gimonnlock, memory);
- DrawFormatString(100, 400, debug_color, "gimon = %d, hyouzi = %d, memorycount = %d",
- gimon, hyouzi, memorycount);
- if (mozicount > 0) {
- drawString(10, 100, z_color, pos, z);
- }
- if (gimon == 0 && hyouzi == 1) {
- DrawFormatString(100, 180, buf_color, "buffer2 = %s", buffer2);
- }
- if (hyouzi == 0 && mozicount > 0 && memory == 0 && memorycount == 0) {
- z = "", pos[0] = pos[1] = 0;
- DrawFormatString(10, 110, buf_color, "申し訳ありません %s とは何ですか?", buffer);
- }
- ScreenFlip(); // 裏画面の内容を表画面に反映させる
- }
- dxlib_end:
- DeleteKeyInput(InputHandle); // 用済みのインプットハンドルを削除する
- DxLib_End(); // DXライブラリの使用終了
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment