Created
May 17, 2010 08:03
-
-
Save yono/403518 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define("ROCK",0); | |
define("SCISSORS",1); | |
define("PAPER",2); | |
define("WIN","あなたの勝ちです\n"); | |
define("LOSE","あなたの負けです\n"); | |
define("DRAW","ひきわけです\n"); | |
$janken = array(ROCK => "グー", SCISSORS => "チョキ", PAPER => "パー"); | |
echo "じゃんけんしましょう\n"; | |
echo "グーは ", ROCK, " , チョキは ", SCISSORS, " , パーは ", PAPER, " を入力してね\n"; | |
$input = intval(fgets(STDIN,4096)); | |
$randval = rand(0,2); | |
echo "あなたの手は{$janken[$input]}です\n"; | |
echo "わたしの手は{$janken[$randval]}です\n"; | |
switch($input) { | |
case ROCK: | |
switch($randval) { | |
case ROCK: | |
echo DRAW; | |
break; | |
case SCISSORS: | |
echo WIN; | |
break; | |
case PAPER: | |
echo LOSE; | |
break; | |
} | |
break; | |
case SCISSORS: | |
switch($randval) { | |
case ROCK: | |
echo LOSE; | |
break; | |
case SCISSORS: | |
echo DRAW; | |
break; | |
case PAPER: | |
echo WIN; | |
break; | |
} | |
break; | |
case PAPER: | |
switch($randval) { | |
case ROCK: | |
echo WIN; | |
break; | |
case SCISSORS: | |
echo LOSE; | |
break; | |
case PAPER: | |
echo DRAW; | |
break; | |
} | |
break; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
import random | |
ROCK = 0 | |
SCISSORS = 1 | |
PAPER = 2 | |
WIN = "あなたの勝ちです" | |
LOSE = "あなたの負けです" | |
DRAW = "引き分けです" | |
janken = {ROCK:"グー", SCISSORS:"チョキ", PAPER:"パー"} | |
print "じゃんけんしましょう" | |
print "グーは %s, チョキは %s, パーは %s を入力してね" % (ROCK, SCISSORS, PAPER) | |
inval = input() | |
randval = random.randint(0, 2) | |
print "あなたの手: %s" % (janken[inval]) | |
print "わたしの手: %s" % (janken[randval]) | |
if inval == ROCK: | |
if randval == ROCK: | |
print DRAW | |
elif randval == SCISSORS: | |
print WIN | |
else: | |
print LOSE | |
elif inval == SCISSORS: | |
if randval == ROCK: | |
print LOSE | |
elif randval == SCISSORS: | |
print DRAW | |
else: | |
print WIN | |
else: | |
if randval == ROCK: | |
print WIN | |
elif randval == SCISSORS: | |
print LOSE | |
else: | |
print DRAW |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROCK = 0 | |
SCISSORS = 1 | |
PAPER = 2 | |
DRAW = "あいこですね" | |
WIN = "あなたの勝ちです" | |
LOSE = "残念、私の勝ちです" | |
janken = { | |
ROCK => "グー", | |
SCISSORS => "チョキ", | |
PAPER => "パー" | |
} | |
puts "じゃんけんしましょう" | |
puts "グーのときは #{ROCK}, チョキのときは #{SCISSORS}, パーのときは #{PAPER} を入力してね" | |
input = gets | |
input = input.to_i | |
randnum = rand(3) | |
puts "あなたが出した手: #{janken[input]}" | |
puts "わたしが出した手: #{janken[randnum]}" | |
case input | |
when ROCK | |
case randnum | |
when ROCK | |
puts DRAW | |
when SCISSORS | |
puts WIN | |
else | |
puts LOSE | |
end | |
when SCISSORS | |
case randnum | |
when ROCK | |
puts LOSE | |
when SCISSORS | |
puts DRAW | |
else | |
puts WIN | |
end | |
when PAPER | |
case randnum | |
when ROCK | |
puts WIN | |
when SCISSORS | |
puts LOSE | |
else | |
puts DRAW | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment