石头剪子布
# 0 石头,1 剪刀, 2 布
# 0 输,1 赢, 2 平
$a = rand(0,2);
$b = rand(0,2);
$win = 0;
if( $a == $b ) $win = 2;
if( $a == 0 ){
switch ( $b ){
case 1:$win = 1; break;
case 2:$win = 0; break;
}
}
else if( $a == 1 ){
switch ( $b ){
case 0:$win = 0; break;
case 2:$win = 1; break;
}
}
else if ( $a == 2 ) {
switch ( $b ){
case 0:$win = 1; break;
case 1:$win = 0; break;
}
}
$sta = array("石头","剪刀","布");
$str = array("输","赢","平");
echo "A 出的是".$sta[$a]."\n";
echo "B 出的是".$sta[$b]."\n";
echo 'A '.$str[$win].' B了';
用户评论