トップページ > 記事閲覧
4枚だけ残ります 
名前:aaa 日時: 2017/03/04 13:52

#include "DxLib.h" // 場のカードデータ struct { int mark; int number; bool reverse; } cards[3][4]; int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { int turns = 0; int ox, oy, nx, ny; int remains = 12; int start_time, elapsed_time; bool mouse_flag = false; int graph_cards[2], graph_marks[4], graph_numbers[13]; ChangeWindowMode(TRUE); DxLib_Init(); SetDrawScreen(DX_SCREEN_BACK); LoadDivGraph("card.png", 2, 2, 1, 40, 64, graph_cards); LoadDivGraph("mark.png", 4, 4, 1, 28, 28, graph_marks); LoadDivGraph("number.png", 6, 6, 1, 28, 28, graph_numbers); // シャッフル bool deal[3][4] = {}; for (int y = 0; y < 3; y++) for (int x = 0; x < 4; x++) { int mk, no; do { mk = GetRand(2); no = GetRand(6); } while (deal[mk][no]); cards[y][x].mark = mk; cards[y][x].number = no; cards[y][x].reverse = true; deal[mk][no] = true; } start_time = GetNowCount(); while (!ProcessMessage()) { ClearDrawScreen(); // カードめくり処理 if (GetMouseInput() & MOUSE_INPUT_LEFT) { if (!mouse_flag) { mouse_flag = true; if (turns == 2) { cards[oy][ox].reverse = true; cards[ny][nx].reverse = true; turns = 0; } else { GetMousePoint(&nx, &ny); nx = (nx - 60) / 40; ny = (ny - 96) / 64; if (nx >= 0 && nx <= 3 && ny >= 0 && ny <= 2 && cards[ny][nx].reverse) { cards[ny][nx].reverse = false; if (turns == 0) { ox = nx; oy = ny; turns = 1; } else { if (cards[ny][nx].number == cards[oy][ox].number) { remains -= 2; turns = 0; } else turns = 2; } } } } } else mouse_flag = false; // 場のカード表示 for (int y = 0; y < 3; y++) for (int x = 0; x < 4; x++) { int x2 = x * 40 + 60; int y2 = y * 64 + 96; DrawGraph(x2, y2, graph_cards[cards[y][x].reverse], FALSE); if (!cards[y][x].reverse) { DrawGraph(x2 + 6, y2 + 5, graph_marks[cards[y][x].mark], FALSE); DrawGraph(x2 + 6, y2 + 32, graph_numbers[cards[y][x].number], FALSE); } } // メッセージ表示 int color = GetColor(255, 255, 255); if (remains <= 0) DrawString(8, 8, "クリア!", color); else elapsed_time = (GetNowCount() - start_time) / 1000; DrawFormatString(8, 450, color, "残り %d枚 経過時間 %d秒", remains, elapsed_time); ScreenFlip(); } DxLib_End(); } なぜ四枚だけ残るのか教えて下さい!!
メンテ

Page: 1 |

Re: 4枚だけ残ります  ( No.1 )
名前:aaa 日時:2017/03/05 10:10

追記 3×4の6までの神経衰弱を作りたいのですが、何故かできないです。
メンテ
Re: 4枚だけ残ります  ( No.2 )
名前:管理人 日時:2017/03/05 21:03

「//シャッフル」の処理が正しくないのが原因です 「//シャッフル」の処理を↓このようにしたところ正常に動作しましたので、よろしければ試してみてください bool deal[3][4] = {}; for (int mk = 0; mk < 2; mk++) { for (int no = 0; no < 3; no++) { for( int i = 0; i < 2; i++ ) { int x, y; do { x = GetRand(3); y = GetRand(2); } while (deal[y][x]); cards[y][x].mark = mk; cards[y][x].number = no; cards[y][x].reverse = true; deal[y][x] = true; } } }
メンテ
Re: 4枚だけ残ります  ( No.3 )
名前:aaa(解決) 日時:2017/03/06 13:34

ありがとうございました!!
メンテ

Page: 1 |

題名
名前
コメント
パスワード (記事メンテ時に使用)

   クッキー保存