Advertisement
Pyprokid

Rock-Paper-Scissors Game

Aug 16th, 2011
1,747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.69 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # Coded by: Matthew Schaney
  4.  
  5. #  Copyright (C) <2011>  <Matthew Schaney>
  6.  
  7. #    This program is free software: you can redistribute it and/or modify
  8. #    it under the terms of the GNU General Public License as published by
  9. #    the Free Software Foundation, either version 3 of the License, or
  10. #    (at your option) any later version.
  11.  
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16.  
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program.  If not, see <http://www.gnu.org/licenses/>
  19.  
  20. # Version 1.0
  21.  
  22. # A simple Rock Paper Scissors game. You must have Python installed, to run simply go to a terminal and once in the directory that the code is in type: "python NAME" <--- NAME = whatever you named the code.
  23.  
  24. # # # IMPORTS OS, WHICH I USE TO CLEAR THE SCREEN, RANDOM TO GET THE COMPUTER'S SELECTION, AND GETPASS FOR USERNAME AND HIDING USER CHOICES
  25.  
  26. import os, random, getpass
  27. os.system("clear")
  28.  
  29.  
  30.  
  31. # # # GETS THE USERNAME FROM THE SYSTEM AND ASSIGNS IT TO THE VARIABLE 'username'
  32. username = getpass.getuser()
  33.  
  34.  
  35. # # # THE INPUT THAT IS USED TO DETERMINE WETHER IT IS SINGLE PLAYER OR NOT
  36.  
  37. print "Hello,", username, "\b, would you like to play against a computer or another person?"
  38. singleOrNot = int(raw_input("(1) Computer\n(2) Multiplayer\n\n---> "))
  39.  
  40.  
  41.  
  42. # # # IF IT IS 1, WHICH MEANS SINGLE PLAYER, THEN IT RANDOMIZES A NUMBER AND CALCULATES THE CHANGES
  43.  
  44. if singleOrNot == 1:
  45.     os.system("clear")
  46.  
  47.  
  48.  
  49.     # # # THE COLORS DEFINITIONS
  50.  
  51.     normal = '\033[0m'
  52.     bold = '\033[1m'
  53.     lose = '\033[91m'
  54.     win = '\033[92m'
  55.     tie = '\033[93m'
  56.  
  57.  
  58.  
  59.     # # # GENERATES A RANDOM NUMBER BETWEEN 0-2
  60.  
  61.     computerSelc = random.randrange(3)
  62.     # 0 = ROCK
  63.     # 1 = PAPER
  64.     # 2 = SCISSORS
  65.  
  66.  
  67.  
  68.     # # # GETS YOUR SELECTION
  69.  
  70.     playerSelc = int(raw_input("WHICH ONE WOULD YOU LIKE?\n(1) Rock\n(2) Paper\n(3) Scissors\n\n---> "))
  71.  
  72.  
  73.  
  74.     # # # THIS BASICALLY IS ALOT OF IF'S THAT MATCH UP THE DIFFERENT POINTS
  75.  
  76.     if playerSelc == 1:
  77.         if computerSelc == 0:
  78.             print "\n\n", bold, tie, "\b\bTie Game.", normal
  79.         if computerSelc == 1:
  80.             print "\n\n", bold, lose, "\b\bPaper covers Rock, you lose.", normal
  81.         if computerSelc == 2:
  82.             print "\n\n", bold, win, "\b\bRock smashes Scissors, you win!", normal
  83.     if playerSelc == 2:
  84.         if computerSelc == 0:
  85.             print "\n\n", bold, win, "\b\bPaper covers Rock, you win!", normal
  86.         if computerSelc == 1:
  87.             print "\n\n", bold, tie, "\b\bTie Game.", normal
  88.         if computerSelc == 2:
  89.             print "\n\n", bold, lose, "\b\bScissors cut paper, you lose.", normal
  90.     if playerSelc == 3:
  91.         if computerSelc == 0:
  92.             print "\n\n", bold, lose, "\b\bRock smashes Scissors, you lose.", normal
  93.         if computerSelc == 1:
  94.             print "\n\n", bold, win, "\b\bScissors cut paper, you win!", normal
  95.         if computerSelc == 2:
  96.             print "\n\n", bold, tie, "\b\bTie Game.", normal
  97.  
  98.  
  99.  
  100. # # # BASICALLY THE EXACT SAME STUFF AS ABOVE NO RANDOM NUMBER INSTEAD IT IS AN INPUTED NUMBER FROM BOTH PLAYERS
  101.  
  102. if singleOrNot == 2:
  103.     os.system("clear")
  104.  
  105.  
  106.  
  107.     # # # THERE ARE DIFFERENT COLORS COMPARED TO ABOVE
  108.  
  109.     normal = '\033[0m'
  110.     bold = '\033[1m'
  111.     two = '\033[91m'
  112.     one = '\033[34m'
  113.     tie = '\033[93m'
  114.  
  115.     print "PLAYER", bold, one, "\b\bONE", normal, "\b\b: WHICH ONE WOULD YOU LIKE?\n(1) Rock\n(2) Paper\n(3) Scissors\n\n"
  116.     player1Selc = int(getpass.getpass("---> "))
  117.     os.system("clear")
  118.     print "PLAYER", bold, two, "\b\bTWO", normal, "\b\b: WHICH ONE WOULD YOU LIKE?\n(1) Rock\n(2) Paper\n(3) Scissors\n\n"
  119.     player2Selc = int(getpass.getpass("---> "))
  120.  
  121.  
  122.  
  123.     # # # SAME CALCULATION SYSTEM; USES DIFFERENT VARIABLE SENSE IT IS A PLAYER, NOT A COMPUTER
  124.  
  125.     if player1Selc == 1:
  126.         if player2Selc == 1:
  127.             print "\n\n", bold, tie, "\b\bTie Game.", normal
  128.         if player2Selc == 2:
  129.             print "\n\n", bold, two, "\b\bPaper covers Rock, Player Two wins.", normal
  130.         if player2Selc == 3:
  131.             print "\n\n", bold, one, "\b\bRock smashes Scissors, Player One wins.", normal
  132.     if player1Selc == 2:
  133.         if player2Selc == 1:
  134.             print "\n\n", bold, one, "\b\bPaper covers Rock, Player One wins.", normal
  135.         if player2Selc == 2:
  136.             print "\n\n", bold, tie, "\b\bTie Game.", normal
  137.         if player2Selc == 3:
  138.             print "\n\n", bold, two, "\b\bScissors cut paper, Player Two wins.", normal
  139.     if player1Selc == 3:
  140.         if player2Selc == 1:
  141.             print "\n\n", bold, two, "\b\bRock smashes Scissors, Player Two wins.", normal
  142.         if player2Selc == 2:
  143.             print "\n\n", bold, one, "\b\bScissors cut paper, Player One wins.", normal
  144.         if player2Selc == 3:
  145.             print "\n\n", bold, tie, "\b\bTie Game.", normal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement