Home php教程 PHP源码 石头剪刀布的php非循环写法

石头剪刀布的php非循环写法

May 25, 2016 pm 05:00 PM

跳至

<?php

/**
 * Rock Paper Scissors
 * by inuxor
 */

function rps() {
	$rps = array("石头", "剪刀", "布");
	$keys = array_keys($rps);
	shuffle($keys);
	$computer = $keys[0];

	echo "请输入: 石头 剪刀 布\n";
	$keyin = trim(fgets(STDIN));
	$person = array_search($keyin, $rps);
	if($person === false){
		echo "输入错误!!\n";
		rps();

	}else{
		echo "电脑出的是:" . $rps[$computer] . "\n";

		$action = $computer - $person;
		if($action == 0){
			echo "平局\n";
		}else if($action == -2 || $action == 1){
			echo "你赢\n";
		}else{
			echo "电脑赢\n";
		}
		echo "再来一次?(y/n)\n";
		$yorn = trim(fgets(STDIN));
		if($yorn == &#39;y&#39;){
			rps();
		}else if($yorn == &#39;n&#39;){
			echo "Bye\n";
		}else{
			echo "全当是再来一次了,再来!\n";
			rps();
		}
	}


}

echo "开始猜拳游戏\n";
rps();
Copy after login

                   

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)