1. 首页
  2. 移动开发
  3. Android
  4. 石头剪子布

石头剪子布

上传者: 2019-01-17 09:53:05上传 JS文件 855B 热度 43次

# 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了';

用户评论