[Tutor] Beginner Game: Rock, Paper, Scissors

Johnny Jelinek johnnyjiv at gmail.com
Tue Jun 26 15:11:35 CEST 2007


Hello, I'm a beginner to python; I wanted to make a fun little game, so I
started with something simple: Rock, Paper, Scissors.

The program I made satisfies me, but I want to add graphics.  I installed
pygame, and have some svg's that I want to render into graphics.  I
installed cairo, but then realized that it is only used to draw svg's and
other graphics into files, not render them on the screen.  Any ideas how to
start turning this into a graphical game?  Feel free to add any other
suggestions as well :D:D:D! Thanks.

Here is the source code:

#! /usr/bin/env python
##########Rock Paper Scissors, By: John Jelinek IV##########
##########GLOBAL VARS#######################################
import random
import os
random = random.Random()
##########FUNCTIONS#########################################
def clear():        # Clear's the screen
    os.system("clear")
def rounds():        # Asks how many rounds
    rnum = input("How many rounds?!?: ")
    while rnum == 1 or rnum%2 == 0 or rnum <= -1:
        print "Must be an odd number of rounds and more than 1, try again!"
        rnum = input("How many rounds?!?: ")
    return rnum
def rps(rounds):    # Begins the real game

    win = 0
    lose = 0
    tie = 0

    for i in range(1,rounds+1):
        decision = ('rock', 'paper', 'scissors')
        player = ''
        ai = random.choice(decision)

        while player != 'r' and player != 'p' and player != 's':
            print "\nROUND ", + i
            player = raw_input('What will YOU choose? (r)ock, (p)aper,
(s)cissors: ')

        if player == 'r':
            player = 'rock'
        elif player == 'p':
            player = 'paper'
        else:
            player = 'scissors'

        print "====================="
        print "you chose " + player.upper(),
        print ":: I choose " + ai.upper()

        if player.upper() == 'ROCK' and ai.upper() == 'SCISSORS':
            win += 1
            print "You WIN by CRUSHING those SCISSORS!"
        elif player.upper() == 'PAPER' and ai.upper() == 'ROCK':
            win += 1
            print "You WIN by WRAPPING that ROCK!"
        elif player.upper() == 'SCISSORS' and ai.upper() == 'PAPER':
            win += 1
            print "You WIN by CUTTING that PAPER!"
        elif player.upper() == ai.upper():
            tie += 1
            print "YOU TIE!"
        else:
            lose += 1
            print "YOU LOSE!"

    print "\nRounds Won: ", + win
    print "\nRounds Lost: ", + lose
    print "\nRounds Tied: ", + tie
##########BEGIN PROGRAM#####################################
clear()
print "Welcome to ROCK PAPER SCISSORS!  PREPARE FOR BATTEL!!\n\n"
rounds = rounds()
rps(rounds)
##########END PROGRAM#######################################
print "\n\nThanks for playing!\n"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070626/a62fc599/attachment.htm 


More information about the Tutor mailing list