問題:爲我的互聯網編程課程創建視頻撲克遊戲。如何檢查我的撲克遊戲中的Full House?
我有一切工作,除了我在我的邏輯下面丟失了一些東西。 當我擁有的是3種類型時,它會爲滿屋返回true。
我知道我的3種作品的邏輯。但是當比較兩種卡片中沒有涉及的3種情況時,哪裏出了問題。
下面的代碼:
//Calculate if Full House exist
function checkHouse()
{
$kindFlag = false;
$pairFlag = false;
$tempCardValue = 0;
$temp = array();
$counter = 0;
//check for 3 of a kind, save card positions so they aren't tested for a pair
for($i=0; $i<3; $i++)
{
for($j=($i+1); $j<4; $j++)
{
for($k=($j+1); $k<5; $k++)
{
if($this->Hand[$i]->GetSortValue() == $this->Hand[$j]->GetSortValue() && $this->Hand[$i]->GetSortValue() == $this->Hand[$k]->GetSortValue())
{
$kindFlag = true;
$tempCardValue = $this->Hand[$i]->GetSortValue();
break 3;
}
}
}
}
//Checks 2 remaining cards to see if they match
for($i=0; $i<5; $i++)
{
if($this->Hand[$i]->GetSortValue() != $tempCardValue)
{
$temp[$counter] = $this->Hand[$i]->GetSortValue();
$counter++;
}
}
if($temp[0] == $temp[1])
{
$pairFlag = true;
}
//Computes Full House or not
if($pairFlag && $kindFlag)
return true;
else
return false;
}
不是一個答案,但哇,你已經結束了複雜化你的卡片。 – ajacian81