Skip to content

Instantly share code, notes, and snippets.

@yakimelon
Created March 23, 2017 04:15
Show Gist options
  • Save yakimelon/8f1f46baf298e74003a71e520b505e73 to your computer and use it in GitHub Desktop.
Save yakimelon/8f1f46baf298e74003a71e520b505e73 to your computer and use it in GitHub Desktop.
php janken
<?php
function janken($player, $enemy){
$table = [['あいこ', '勝ち', '負け'],
['勝ち', 'あいこ', '負け'],
['負け', '勝ち', 'あいこ']];
return $table[$player][$enemy];
}
if( isset($_POST['gu']) ) $hand = 0;
if( isset($_POST['tyoki']) ) $hand = 1;
if( isset($_POST['pa']) ) $hand = 2;
if( !empty($_POST['flag']) ){
$enemy = rand(0, 2);
$result = janken($hand, $enemy);
}else{
$result = '';
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>じゃんけんゲーム</title>
</head>
<body>
<h1>じゃんけんゲーム</h1>
<form action='' method='post'>
<input type='hidden' name='flag' value='true'>
<input type='submit' name='gu' value='グー'>
<input type='submit' name='tyoki' value='チョキ'>
<input type='submit' name='pa' value='パー'>
</form>
<p><?php echo $result; ?></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment