現在僕はDXライブラリでポーカーゲームを作っています。
ランダムで画像を表示し、プレイヤーの手札の交換までは何とかなりました。(ランダム関数が重複ありなのは認知していますが今のところスルーでお願いします。)
最後に重要な勝敗判定なのですがこれがどのように書けばいいのかわかりません。
いまの空想では場に出ているカード画像の番号、記号から「ワンペア、ツーペア、スリーカード、フルハウス、フォーカード、ストレート、フラッシュ、ロイヤルストレートフラッシュ」の役を見出したいのです。
どのようにすればいいですか?
以下にコードを添付しておきます。```C++
#include "DxLib.h"
int Key[256];
int gpUpdateKey() {
char tmpKey[256];
GetHitKeyStateAll(tmpKey);
for (int i = 0; i < 256; i++) {
if (tmpKey[i] != 0) {
Key[i]++;
}
else {
Key[i] = 0;
}
}
return 0;
}
int card_Graphic[52];
void load() {
card_Graphic[0] = LoadGraph("Card\A-1.png");
card_Graphic[1] = LoadGraph("Card\A-2.png");
card_Graphic[2] = LoadGraph("Card\A-3.png");
card_Graphic[3] = LoadGraph("Card\A-4.png");
card_Graphic[4] = LoadGraph("Card\A-5.png");
card_Graphic[5] = LoadGraph("Card\A-6.png");
card_Graphic[6] = LoadGraph("Card\A-7.png");
card_Graphic[7] = LoadGraph("Card\A-8.png");
card_Graphic[8] = LoadGraph("Card\A-9.png");
card_Graphic[9] = LoadGraph("Card\A-10.png");
card_Graphic[10] = LoadGraph("Card\A-11.png");
card_Graphic[11] = LoadGraph("Card\A-12.png");
card_Graphic[12] = LoadGraph("Card\A-13.png");
card_Graphic[13] = LoadGraph("Card\B-1.png");
card_Graphic[14] = LoadGraph("Card\B-2.png");
card_Graphic[15] = LoadGraph("Card\B-3.png");
card_Graphic[16] = LoadGraph("Card\B-4.png");
card_Graphic[17] = LoadGraph("Card\B-5.png");
card_Graphic[18] = LoadGraph("Card\B-6.png");
card_Graphic[19] = LoadGraph("Card\B-7.png");
card_Graphic[20] = LoadGraph("Card\B-8.png");
card_Graphic[21] = LoadGraph("Card\B-9.png");
card_Graphic[22] = LoadGraph("Card\B-10.png");
card_Graphic[23] = LoadGraph("Card\B-11.png");
card_Graphic[24] = LoadGraph("Card\B-12.png");
card_Graphic[25] = LoadGraph("Card\B-13.png");
card_Graphic[26] = LoadGraph("Card\C-1.png");
card_Graphic[27] = LoadGraph("Card\C-2.png");
card_Graphic[28] = LoadGraph("Card\C-3.png");
card_Graphic[29] = LoadGraph("Card\C-4.png");
card_Graphic[30] = LoadGraph("Card\C-5.png");
card_Graphic[31] = LoadGraph("Card\C-6.png");
card_Graphic[32] = LoadGraph("Card\C-7.png");
card_Graphic[33] = LoadGraph("Card\C-8.png");
card_Graphic[34] = LoadGraph("Card\C-9.png");
card_Graphic[35] = LoadGraph("Card\C-10.png");
card_Graphic[36] = LoadGraph("Card\C-11.png");
card_Graphic[37] = LoadGraph("Card\C-12.png");
card_Graphic[38] = LoadGraph("Card\C-13.png");
card_Graphic[39] = LoadGraph("Card\D-1.png");
card_Graphic[40] = LoadGraph("Card\D-2.png");
card_Graphic[41] = LoadGraph("Card\D-3.png");
card_Graphic[42] = LoadGraph("Card\D-4.png");
card_Graphic[43] = LoadGraph("Card\D-5.png");
card_Graphic[44] = LoadGraph("Card\D-6.png");
card_Graphic[45] = LoadGraph("Card\D-7.png");
card_Graphic[46] = LoadGraph("Card\D-8.png");
card_Graphic[47] = LoadGraph("Card\D-9.png");
card_Graphic[48] = LoadGraph("Card\D-10.png");
card_Graphic[49] = LoadGraph("Card\D-11.png");
card_Graphic[50] = LoadGraph("Card\D-12.png");
card_Graphic[51] = LoadGraph("Card\D-13.png");
}
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR lpC, int nC)
{
ChangeWindowMode(TRUE), DxLib_Init();
int haikei, mozi1, mozi2, ura; mozi1 = CreateFontToHandle("MS ゴシック", 50, 9, DX_FONTTYPE_NORMAL); mozi2 = CreateFontToHandle("MS ゴシック", 24, 6, DX_FONTTYPE_NORMAL); haikei = LoadGraph("haikei.jpg"); ura = LoadGraph("Card\ura.png"); DrawRotaGraph(320, 240, 0.5, 0.0, haikei, TRUE); DrawFormatString(25, 220, GetColor(255, 255, 255), "1P"); DrawFormatString(25, 370, GetColor(255, 255, 255), "2P"); while (1) { ProcessMessage(); DrawStringToHandle(100, 65, "ポーカーゲーム開始。", GetColor(255, 255, 255), mozi1); DrawStringToHandle(250, 117, "Enterで次へ", GetColor(255, 255, 255), mozi2); if (CheckHitKey(KEY_INPUT_RETURN) == 1) { break; } } ClearDrawScreen(); DrawRotaGraph(320, 240, 0.5, 0.0, haikei, TRUE); DrawFormatString(25, 220, GetColor(255, 255, 255), "1P"); DrawFormatString(25, 370, GetColor(255, 255, 255), "2P"); DrawStringToHandle(250, 117, "Enterで2Pへ", GetColor(255, 255, 255), mozi2); DrawStringToHandle(60, 75, "[1P]交換するカードの番号を選択してください", GetColor(255, 255, 255), mozi2); DrawFormatString(105, 287, GetColor(255, 255, 255), "1"); DrawFormatString(215, 287, GetColor(255, 255, 255), "2"); DrawFormatString(325, 287, GetColor(255, 255, 255), "3"); DrawFormatString(435, 287, GetColor(255, 255, 255), "4"); DrawFormatString(545, 287, GetColor(255, 255, 255), "5"); load(); DrawRotaGraph(110, 220, 0.125, 0.0 , card_Graphic[GetRand(51)] , TRUE); DrawRotaGraph(220, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(330, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(440, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(550, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(110, 370, 0.125, 0.0, ura, TRUE); DrawRotaGraph(220, 370, 0.125, 0.0, ura, TRUE); DrawRotaGraph(330, 370, 0.125, 0.0, ura, TRUE); DrawRotaGraph(440, 370, 0.125, 0.0, ura, TRUE); DrawRotaGraph(550, 370, 0.125, 0.0, ura, TRUE); int flag1 = 0; int flag2 = 0; int flag3 = 0; int flag4 = 0; int flag5 = 0; while (1) { ProcessMessage(); gpUpdateKey(); if ((Key[KEY_INPUT_1] == 1) && !flag1) { DrawRotaGraph(110, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag1 = 1; } if ((Key[KEY_INPUT_2] == 1) && !flag2) { DrawRotaGraph(220, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag2 = 1; } if ((Key[KEY_INPUT_3] == 1) && !flag3) { DrawRotaGraph(330, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag3 = 1; } if ((Key[KEY_INPUT_4] == 1) && !flag4) { DrawRotaGraph(440, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag4 = 1; } if ((Key[KEY_INPUT_5] == 1) && !flag5) { DrawRotaGraph(550, 220, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag5 = 1; } if (Key[KEY_INPUT_RETURN] == 1) { break; } } ClearDrawScreen(); DrawRotaGraph(320, 240, 0.5, 0.0, haikei, TRUE); DrawFormatString(25, 220, GetColor(255, 255, 255), "1P"); DrawFormatString(25, 370, GetColor(255, 255, 255), "2P"); DrawStringToHandle(250, 117, "Enterで次へ", GetColor(255, 255, 255), mozi2); DrawStringToHandle(60, 75, "[2P]交換するカードの番号を選択してください", GetColor(255, 255, 255), mozi2); DrawFormatString(105, 287, GetColor(255, 255, 255), "1"); DrawFormatString(215, 287, GetColor(255, 255, 255), "2"); DrawFormatString(325, 287, GetColor(255, 255, 255), "3"); DrawFormatString(435, 287, GetColor(255, 255, 255), "4"); DrawFormatString(545, 287, GetColor(255, 255, 255), "5"); DrawRotaGraph(110, 220, 0.125, 0.0, ura, TRUE); DrawRotaGraph(220, 220, 0.125, 0.0, ura, TRUE); DrawRotaGraph(330, 220, 0.125, 0.0, ura, TRUE); DrawRotaGraph(440, 220, 0.125, 0.0, ura, TRUE); DrawRotaGraph(550, 220, 0.125, 0.0, ura, TRUE); load(); DrawRotaGraph(110, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(220, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(330, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(440, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); DrawRotaGraph(550, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); int flag6 = 0; int flag7 = 0; int flag8 = 0; int flag9 = 0; int flag0 = 0; while (1) { ProcessMessage(); gpUpdateKey(); if ((Key[KEY_INPUT_1] == 1) && !flag6) { DrawRotaGraph(110, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag6 = 1; } if ((Key[KEY_INPUT_2] == 1) && !flag7) { DrawRotaGraph(220, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag7 = 1; } if ((Key[KEY_INPUT_3] == 1) && !flag8) { DrawRotaGraph(330, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag8 = 1; } if ((Key[KEY_INPUT_4] == 1) && !flag9) { DrawRotaGraph(440, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag9 = 1; } if ((Key[KEY_INPUT_5] == 1) && !flag0) { DrawRotaGraph(550, 370, 0.125, 0.0, card_Graphic[GetRand(51)], TRUE); flag0 = 1; } if (Key[KEY_INPUT_RETURN] == 1) { break; } } WaitKey(); DxLib_End(); return 0;
}