Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DxLib.h"
- #include <string>
- int konnnitiwasound = 0;
- int situreisimasitasound = 0;
- char String[256];
- char StringA[256];
- int InputHandle;
- int InputHandleA;
- int modoru = 0;
- std::string input;
- std::string message;
- std::string messageA;
- int i;
- int a[1] = { 3};
- int suuti = 256;
- int duration = 0;
- int konnnitiwa = 0;
- int sitaidou = 0;
- int sitaidouA = 0;
- int mozicount = 0;
- int mozicount2 = 0;
- int mozicount3 = 0;
- int gimonnlock = 0;
- // 自作文字列比較関数
- int my_strcmp(const char* s1, const char* s2) {
- // 先頭から走査して差があればループ終了
- for (; *s1 == *s2; s1++, s2++) {
- // 終了前に終端文字が見つかったら差分なし
- if (*s1 == '\0'&& *s2 == '\0') { return 0; }
- } return *s1 > * s2 ? 1 : -1;
- }
- int my_str2(const char* s1, const char* s2)//ここで入力した文字列と用意された文字列を引数として扱う。
- {
- //s1, s2を比較する関数を使うためだけにs2の文字列のサイズが必要なので、変数aに用意した文字列の情報s2を文字列の長さを測るための関数strlenに引数として渡す。
- const size_t a = strlen(s2);
- //無限ループする。
- for (;;) {
- //関数memcmpの返り値が0の時は一致した時なので、==0とする。
- if (memcmp(s1, s2, a) == 0)
- return 1;//入力した文字列にい指定された文字列が入っていた場合は1を返すように設定した。
- //入力した文字列が最後の文字まで到達した場合は一致する文字列がないということなので0を返すようにした。
- else if (*s1 == '\0')
- return 0;//入っていなかった
- //文字列が一致した場合でも一致する文字列がない場合でも入力した文字列の一文字分の文字コードのバイト数?が繰り上がるようにした。
- else
- ++s1;
- }
- }
- int rireki = 0;
- int rireki2 = 0;
- int LEFTmark = 0;
- const char* str[100] = {
- "どんな映画が好きなんですか?","はい!大好きです!!あなたはどんな映画が好きですか? " ,"私は恋愛映画が好きです!",
- "人間観察が好きだからかもしれません。","申し訳ありません。わかりません。" ,"おはようございます。今日は何をなさるんですか?"};//ここで文字を直接書いてるので、この文字のバイト数が各posmozi[]に入るだけ
- int frame[100] = { 10,10 ,10,10,10,10};//次の一文字が出るまでのカウンタとして働いている、ここの数値を変えることで文字が一文字ずつ出るまでの間隔を設定できる。
- int posmozi[100];//文字のバイト数が入る箱を表している。
- int countS[100];//次の文字が出るまでのカウントするためのもの
- int z;//関数drawString外でも使えるように外にも定義を書いた。zの数値は関係なく、文字列が入った数列がif文により同じ変数zの時にframe[z]と同じになるまで+1されていったり、+2バイトor+1バイトされていくため、
- //文字が一文字ずつ入っていく、なんでzの変数に値を入れて動かす必要がないのだ。ちなみにfor (z = 0; z < 3; ++z)で書いてしまうとキーAを押した際のif文に関係なく関数drawStringの最初のzどこかに値が入っただけで繰り返しを開始してしまうため、今回のように同じ変数zの時にフレームを利用して描画するようにした。
- char c = str[z][posmozi[z]];//関数drawString外でも使えるように外にも定義を書いた。
- void drawString(int z, int x, int y, int color)
- {
- c = str[z][posmozi[z]];//posmozi[z]
- if (countS[z] == 0 && c != '\0')
- posmozi[z] += IsDBCSLeadByte(c) ? 2 : 1;
- if (++countS[z] == frame[z]) countS[z] = 0;
- DrawFormatString(x, y, color, "%.*s", posmozi[z], str[z]);
- DrawFormatString(300, 300, (0, 0, 255), "countS[0]は%d", countS[0]);
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- SetGraphMode(1500, 780, 32); // ウィンドウの大きさを指定
- ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
- // DXライブラリの初期化
- if (DxLib_Init() == -1) return -1;
- SetFontSize(42); //サイズを42に変更
- // 描画先を裏にする
- SetDrawScreen(DX_SCREEN_BACK);
- // キー入力ハンドルを作る(キャンセルなし全角文字有り数値入力じゃなし)
- //MakeKeyInputは開発者の方が一回呼び出せば使えるように作ったのでループ内には書かない。
- InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
- // 作成したキー入力ハンドルをアクティブにする
- SetActiveKeyInput(InputHandle);
- // キー入力終了待ちループ
- // (ProcessMessageをループごとに行う)
- while (ProcessMessage() == 0)
- {
- // 画面の初期化
- ClearDrawScreen();
- //まずは描画する部分から作る。
- // 入力モードを描画
- DrawKeyInputModeString(640, 480);
- // 入力途中の文字列を描画
- DrawKeyInputString(0, 0, InputHandle);//InputHandleはint型とリファレンスに書いてあったんで
- //その後にif文での分岐を考える。
- // 入力が終了している場合は終了
- //ループ内とは言えエンターキー一回でCheckKeyInputが呼べればいい。
- //エンターキーが押されていないとき?の部分。
- if (CheckKeyInput(InputHandle) != 0) {
- // 入力された文字列を取得
- char buffer[256];//★InputHandleに入ったのは文字のデータなので、文字のデータが受け取れる変数の型にする。
- // 入力された文字列を取得、その文字列を数値に変換
- GetKeyInputString(buffer, InputHandle);//ここでInputHandleに入力された文字列の数値をGetKeyInputStringにより文字コードに変換したものを上でchar型で定義したbufferに入れる。
- input = buffer;//bufferに入った文字コードに変換したものを
- DrawString(0, 0, input.c_str(), GetColor(255, 255, 255));
- /* 配列の要素を出力 */
- //inputに入った文字のデータを数値化するために input.c_str()を定義して、下のif文に使った。
- //変数inputに入る前はchar型のbufferに文字列が入るので、my_str2はchar*型を引数にとるため、char*型は文字列を定義するので、
- //関数my_str2にはそのまま文字列が使えるので、その文字列が入っているbufferを直接書いた。
- if (my_str2(buffer, "映画") && my_str2(buffer, "好き")) {
- // message = "どんな映画が好きなんですか?";
- konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
- PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
- z = 0;
- ++mozicount;
- if (my_str2(buffer, "どんな") && my_str2(buffer, "?") ||
- my_str2(buffer, "?")) {
- // message = "どんな映画が好きなんですか?";
- konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
- PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
- z = 1;
- ++mozicount;
- gimonnlock = 1;
- }
- else if (my_str2(buffer, "なぜ") && my_str2(buffer, "?") ||
- my_str2(buffer, "なんで") && my_str2(buffer, "?")) {
- // message = "どんな映画が好きなんですか?";
- konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
- PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
- z = 3;
- ++mozicount;
- }
- }
- if (my_str2(buffer, "映画") && my_str2(buffer, "事実") || my_str2(buffer, "映画") && my_str2(buffer, "アクション")) {
- // message = "どんな映画が好きなんですか?";
- // konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
- //PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
- z = 2;
- ++mozicount;
- }
- if (my_str2(buffer, "おはよう") ) {
- // message = "どんな映画が好きなんですか?";
- konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
- PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
- z = 5;
- ++mozicount;
- }
- else {
- z = 4;
- ++mozicount;
- }
- //duration = 1;
- // 再度インプットハンドルをアクティブにする
- SetActiveKeyInput(InputHandle);
- // 入力文字列を初期化する
- SetKeyInputString("", InputHandle);
- }
- // DrawFormatString(100, 150, GetColor(255, 255, 0), "ProcessMessage()は%d,modoruは%d", ProcessMessage(), modoru);
- DrawFormatString(0, 150, GetColor(255, 255, 0), "zは%d,konnnitiwaは%d,sitaidouは%d,mozicountは%d", z, konnnitiwa, sitaidou, mozicount);
- DrawFormatString(0, 250, GetColor(255, 255, 0), "mozicount2は%d,input.c_str()は%d, LEFTmarkは%d", mozicount2, input.c_str(), LEFTmark);
- //新しい言葉の処理
- //文字カウントが1の時
- if (mozicount > 0 ) {
- drawString(z, 10, 100, GetColor(5, 255, 255));
- }
- // 裏画面の内容を表画面に反映させる
- ScreenFlip();
- }
- // 用済みのインプットハンドルを削除する
- DeleteKeyInput(InputHandle);
- // 画面の初期化
- ClearDrawScreen();
- // 裏画面の内容を表画面に反映させる
- ScreenFlip();
- // キー入力待ち
- // WaitKey();
- //ループないやループから出た後で何かしらの問題が発生したら終了する。
- // DXライブラリの使用終了
- DxLib_End();
- // 終了
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement