Welcome, guest | Sign In | My Account | Store | Cart

demonstrate "stone,stainless,paper" game, user could select a sign, and system will generate random sign to compete with user.

Python, 37 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'''
demonstrate Stone, Stainless, Paper game
Created on 2012-11-1

@author: Eric
'''
import random;
                          #elementA-->DRAW  WIN      LOST  
COMPETE_RESULT = {"Stone":["Stone", "Stainless", "Paper"],
                                "Stainless":["Stainless", "Paper", "Stone"],
                                "Paper":["Paper", "Stone", "Stainless"]};
SIGN = {0:"Stone", 1:"Stainless", 2:"Paper"}
RESULTS = {0:"DRAW", 1:"WIN", 2:"LOST"};

def rochambeauGame():
    print('''0:STONE
1:STAINLESS
2:Paper
3:quit
''');
    while True:
        userSign = input("please input your userSign number:");
        if int(userSign) in (0,1, 2, 3):
            if int(userSign) == 3:
                exit();
            else:
                userSignResults = COMPETE_RESULT[SIGN[int(userSign)]];
                pcSign = SIGN[int(genereteRandomPCSign())];
                print("User Sign:" + SIGN[int(userSign)] + " PC Sign:" + pcSign + " \n####result is: user " + RESULTS[userSignResults.index(pcSign)]);
        else:
            print("please input correctly order");
#generate a random number,[0,2]
def genereteRandomPCSign():
    return random.randrange(3);

if __name__ == '__main__':
    rochambeauGame();

simple Rochambeau game