0

さて、これは私の頭を台無しにしています。主に私が深いところに身を投げているからです。

要するに; プレーヤーは、「フラワー ポーカー」をプレイする家に対して賭けます (お楽しみのお金で) フルハウス、ツー オブ ア カインドなどの結果を表示するために必要なものはすべて揃っています。しかし、スコアを制御する変数を割り当てることはできません。ユーザーが得るもの、家が得るもの。したがって、それらを比較して、mySQL を介して楽しいお金を更新することができません。

私がこれまでに持っているもの。これにより、次の部分のランダムが比較され、結果が得られます。

function counting(array $array) {
// Input figures
//print_r($array);

// Run the figures twice through the bucket-counter
$firstBuckets = bucketCounter($array);
$secondBuckets = bucketCounter($firstBuckets);

// Ignore counts of 1
array_shift($secondBuckets);

// Output, just need to do the lookup now
//echo ' converts to ';
//print_r($secondBuckets);
//echo "<br />";
//Lookup Table
if ($secondBuckets[0] == 1 && $secondBuckets[1] == 0) {
    echo ' One Pair';
} else if ($secondBuckets[0] == 2) {
    echo ' Two Pair';
} else if ($secondBuckets[1] == 1 && $secondBuckets[0] == 0) {
    echo ' Three of a kind';
} else if ($secondBuckets[0] == 1 && $secondBuckets[1] == 1) {
    echo ' Full House';
} else if ($secondBuckets[2] == 1) {
    echo ' Four of a kind';
} else if ($secondBuckets[3] == 1) {
    echo ' Five of a kind';
}

}
function counting1(array $array) {
// Input figures
//print_r($array);

// Run the figures twice through the bucket-counter
$firstBuckets = bucketCounter($array);
$secondBuckets = bucketCounter($firstBuckets);

// Ignore counts of 1
array_shift($secondBuckets);

// Output, just need to do the lookup now
//echo ' converts to ';
//print_r($secondBuckets);
//echo "<br />";
//Lookup Table

if ($secondBuckets[0] == 1 && $secondBuckets[1] == 0) {
    echo ' One Pair';
} else if ($secondBuckets[0] == 2) {
    echo ' Two Pair';
} else if ($secondBuckets[1] == 1 && $secondBuckets[0] == 0) {
    echo ' Three of a kind';
} else if ($secondBuckets[0] == 1 && $secondBuckets[1] == 1) {
    echo ' Full House';
} else if ($secondBuckets[2] == 1) {
    echo ' Four of a kind';
} else if ($secondBuckets[3] == 1) {
    echo ' Five of a kind';
}

}
/**
 * Bucket counter
*/
function bucketCounter(array $array) {
$result = array(0, 0, 0, 0, 0, );
foreach($array as $value) {
    if ($value > 0) {
        $result[$value - 1]++;
    }
}

return $result;
}

これは、ベットボタンを押した後に起こることです。

    if (isset($_POST['play'])) {
    $rand1 = rand(1, 5);$rand2 = rand(1, 5);$rand3 = rand(1, 5);$rand4 = rand(1, 5);$rand5 = rand(1, 5);$rand6 = rand(1, 5);$rand7 = rand(1, 5);$rand8 = rand(1, 5);$rand9 = rand(1, 5);$rand10 = rand(1, 5);
    if ($_POST['bet'] <= $user_data['coins']) {
        if ($_POST['bet'] < 999999999) {
            if ($_POST['bet'] > 0.99) {
                if ($user_data['coins'] > 1) {
                    //$userscore = 0;
                    //$hostscore = 0;
                    //echo $rand1.', '.$rand2.', '.$rand3.', '.$rand4.', '.$rand5;
                    echo '<font size="2">You\'ve planted : <br></font>';
                    if ($rand1 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand1 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand1 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand1 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand1 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand2 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand2 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand2 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand2 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand2 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand3 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand3 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand3 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand3 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand3 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand4 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand4 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand4 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand4 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand4 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand5 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand5 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand5 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand5 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand5 === 5) {echo '<img src="images/Flowers_(pastel).png">';}                     
                    //echo '<br>';
                    counting(array($rand1, $rand2, $rand3, $rand4, $rand5));
                    echo ' '.$userscore;
                    echo '<br>';
                    echo '<font size="2">Host planted : <br></font>';
                    if ($rand6 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand6 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand6 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand6 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand6 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand7 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand7 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand7 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand7 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand7 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand8 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand8 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand8 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand8 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand8 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand9 === 1) {     echo '<img src="images/Red_flowers.png">';} else if ($rand9 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand9 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand9 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand9 === 5) {echo '<img src="images/Flowers_(pastel).png">';}
                    if ($rand10 === 1){     echo '<img src="images/Red_flowers.png">';} else if ($rand10 === 2) {echo '<img src="images/Blue_flowers.png">';} else if ($rand10 === 3) {echo '<img src="images/Yellow_flowers.png">';} else if ($rand10 === 4) {echo '<img src="images/Orange_flowers.png">';} else if ($rand10 === 5) {echo '<img src="images/Flowers_(pastel).png">';}                     
                    //echo '<br>';
                    counting1(array($rand6, $rand7, $rand8, $rand9, $rand10));
                    echo '<br>';
                }
            }
        }
    }   
}

カウントで $userscore を設定し、counting1 関数で $hostscore を設定しようとすると、2 番目のコード ボックスでアクセスできないため、スコアを比較して勝者を決定することはできません。

4

1 に答える 1

1

「変数スコープ」と呼ばれるもののため、これらの変数にアクセスすることはできません。

しかし、あなたの場合、その障害を克服するのは非常に簡単です。関数は値を返すだけです。

したがって、 $score 変数を割り当てると仮定すると、追加するだけです

return $score;

関数の最後の行として。

次に、2番目のコードボックスで-変更します

counting(array($rand1, $rand2, $rand3, $rand4, $rand5));

$userscore = counting(array($rand1, $rand2, $rand3, $rand4, $rand5));

そして、$hostscore に対して同じことを行います。

実際には、ユーザーとホストのスコアを別々にカウントする 2 つの関数は必要ありません。1 つだけ残して、次のように 2 回呼び出します。

$userscore = counting(array($rand1, $rand2, $rand3, $rand4, $rand5));
$hostscore = counting(array($rand6, $rand7, $rand8, $rand9, $rand10));
于 2013-04-27T23:57:53.760 に答える