已掉线,重新登录

首页 > 绿虎论坛 > 历史版块 > 编程 > PHP > 源码

[好了]写了个小游戏


『回复列表(25|隐藏机器人聊天)』

20. @carey,我可以自己伪造参数,这样你的程序就出错了,还是使用POST吧,再弄个识别伪造参数的代码
(/@Ta/2014-06-23 15:11//)

21. 01.<span style="font-size:14px;">自己做练习用的</span><pre code_snippet_id="192725"snippet_file_name="blog_20140218_1_1797273"name="code"class="php"><span style="font-size:14px;"><?php02.11$my_array=array("石头","剪刀","布");03.12$guize=array(array("石头","剪刀"),array("剪刀","布"),array("布","石头"));04.13//上面2个变量定义一个需要输入的数组,和一个获胜规则的二维数组05.14// var_dump($guize);06.15$rand_keys=array_rand($my_array);07.16$computer=$my_array[$rand_keys];08.17//取数组中随机值09.1810.19echo$computer."\n";11.2012.2113.2214.2315.24// echo $person;16.25while(True)17.26  {18.27echo"请输入: 石头  剪刀  布\n";19.28$person= trim(fgets(STDIN)) ;20.29$input=array($computer,$person);21.30//将输入的$person和电脑随机产生的值构造一个数组22.31//再判断在不在获胜规则数组中23.3224.33if(!(in_array($person,$my_array)))25.34      {26.35echo"只能输入'剪刀、石头,布,请重新输入'";27.36continue;28.3729.38      }30.3931.4032.41if($computer==$person)33.42      {34.43echo"平手\n";35.4436.45      }37.46elseif(in_array($input,$guize)) {38.47echo"电脑胜\n";39.4840.49      }41.50else42.51      {43.52echo"人获胜\n";44.53break;45.54      }46.55  }47.56  ?></span></pre><span style="font-size:14px"><br>48.</span>49.<pre></pre>50.<pre code_snippet_id="192725"snippet_file_name="blog_20140218_2_7413617"name="code"class="php"></pre>
(/@Ta/2014-06-23 15:39//)

22. <meta charset="utf-8"/></pre><form action="./rps.php"method="post">剪刀石头布<?phperror_reporting(0);$v1=$_POST['player1'];$v2=$_POST['player2'];//echo $v1;if(!empty($v1)&&!empty($v2)){if($v1==$v2)echo"和局。";elseif($v1=="剪刀"&&$v2=="石头")echo"Player2 wins.";elseif($v1=="石头"&&$v2=="剪刀")echo"Player1 wins.";elseif($v1=="剪刀"&&$v2=="布")echo"Player1 wins.";elseif($v1=="布"&&$v2=="剪刀")echo"Player2 wins.";elseif($v1=="布"&&$v2=="石头")echo"Player1 wins.";elseif($v1=="石头"&&$v2=="布")echo"Player2 wins.";echo"<button>再来一局</button>";}else{if(empty($v1)){echo"Player1: [剪刀<input type="radio" name="player1" value="剪刀" />石头<input type="radio" name="player1" value="石头" />布<input type="radio" name="player1" value="布" />]";echo"<button type="submit">选好了</button>";}else{echo"<input style="display: none;" type="text" name="player1" value="&quot;.$v1.&quot;" />";echo"Player1已经选好";}if(empty($v2)){echo"Player2: [剪刀<input type="radio" name="player2" value="剪刀" />石头<input type="radio" name="player2" value="石头" />布<input type="radio" name="player2" value="布" />]";echo"<button type="submit">选好了</button>";}else{echo"<input style="display: none;" type="text" name="player2" value="&quot;.$v2.&quot;" />";echo"Player2已经选好";}}?></form>
(/@Ta/2014-06-23 15:48//)

23. @齐子,嗯
(/@Ta/2014-06-23 15:55//)

24.  ้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้ ้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้ ้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้ ้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้ ้้้้้้้็็็็็้้้้้็็็็็
(/@Ta/2014-06-23 21:18//)

25. @carey,我擦!我怎么老是平局?看现在的平局数
(/@Ta/2014-06-23 21:24//)

上一页 2/2页,共25楼

回复需要登录

7月9日 02:39 星期三

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1