⽃地主⼩游戏随机发牌PHP代码
<?php
header("Content-Type:text/html;charset=UTF-8");
$num=['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
$icon=['♠'=>'red','♥'=>'red','♦'=>'black','♣'=>'black'];
$poker=array();
foreach ($icon as $key => $v1) {
foreach ($num as $v2) {
$poker[]="<font color='".$v1."'>$v2 $key</font>";
#
}php游戏源码
}
// 通过数组赋值的⽅式添加两个元素⼤⼩王两张牌⼤王红⾊⼩王⿊;
$poker[]="<font color='red'>⼤王</font>";
$poker[]="<font color='black'>⼩王</font>";
print_r($poker);
echo '<hr>';
shuffle($poker);
print_r($poker);
// 使⽤随机函数rand()⽣成⼀个数
echo $m=rand(0,2);
switch ($m) {
case 0:
echo "恭喜玩家A抢得地主!发牌20张";
break;
case 1:
echo "恭喜玩家B抢得地主!发牌20张";
break;
case 2:
echo "恭喜玩家c抢得地主!发牌20张";
break;
}
$max=17;
echo '<hr>';
>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>随机发牌</title>
</head>
<style type="text/css">
div{
margin: 15px 0;
}
tr{height:60px;
}
td{
border: 1px solid #ccc;
width: 40px;
padding: 6px 3px;
}
</style>
<body>
<body>
<div>玩家A的牌组</div>
<?php
echo '<table><tr>';
if ($m==0) {
$max=20;
}else
{$max=17;}
for ($i=1; $i<=$max; $i++) {
echo "<td>".current($poker).'</td>'; next($poker) ;
}
echo "</tr></table>";
>
<div>玩家B的牌组</div>
<?php
echo '<table><tr>';
if ($m==1) {
$max=20;
}else
{$max=17;}
for ($i=1; $i<=$max; $i++) {
echo "<td>".current($poker).'</td>'; next($poker) ;
}
echo "</tr></table>";
>
<div>玩家c的牌组</div>
<?php
echo '<table><tr>';
if ($m==2) {
$max=20;
}
else
{$max=17;}
for ($i=1; $i<=$max; $i++) {
echo "<td>".current($poker).'</td>'; next($poker) ;
}
echo "</tr></table>";
>
</body>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论