Advertisement
hackloper775

p-p-t-python-re

Apr 20th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # Eres libre de modificar,compartir y jugar :P
  4. # Por Tiempo de Tux
  5.  
  6. import random
  7. import os
  8. import re
  9.  
  10. def clear():
  11.     os.system('clear')
  12.  
  13. # variables globales
  14.  
  15. clear()
  16. nombre = input("Nombre del jugador : ")
  17. cpu = ["piedra","papel","tijeras"]
  18. jugados = 0
  19. score = 0
  20. score_cpu = 0
  21.  
  22. while True:
  23.    n_juegos = input("Numero de juegos : ")
  24.    if not re.search("\D",n_juegos):
  25.       break
  26.    else:
  27.       print("(numeros); ")
  28.       continue
  29.  
  30. class juegos:
  31.      
  32.       def __init__(self,jugados):
  33.          self.jugados = jugados
  34.          self.score = score
  35.          self.score_cpu = score_cpu
  36.          while self.jugados < int(n_juegos):
  37.               self.juego()
  38.          self.game_over()
  39.       def juego(self):
  40.           while True:
  41.                 self.eleccion = input("Piedra papel o tijeras : ")
  42.                 self.eleccion = self.eleccion.lower()
  43.                 if self.eleccion == "piedra" or self.eleccion == "papel" or self.eleccion == "tijeras":
  44.                    break
  45.                 else:
  46.                    continue
  47.           self.n = random.randint(0,2)
  48.           self.eleccion_cpu = cpu[self.n]
  49.           self.resultado()
  50.  
  51.       def resultado(self):
  52.           clear()
  53.           print ("Resultado:\n")
  54.           print (nombre, self.eleccion, "CPU :", self.eleccion_cpu)
  55.           if self.eleccion == self.eleccion_cpu:
  56.                 print ("Es un empate")
  57.           elif self.eleccion == "piedra":
  58.                 if self.eleccion_cpu == "tijeras":
  59.                      print ("Gana", nombre)
  60.                      self.score = self.score + 1
  61.                 else:
  62.                      print ("Gana el CPU")
  63.                      self.score_cpu = self.score_cpu + 1
  64.           elif self.eleccion == "papel":
  65.                 if self.eleccion_cpu == "tijeras":
  66.                      print ("Gana CPU")
  67.                      self.score_cpu = self.score_cpu + 1
  68.                 else:
  69.                      print ("Gana : ", nombre)
  70.                      self.score = self.score + 1
  71.           else:
  72.                 if self.eleccion_cpu == "piedra":
  73.                      print ("Gana CPU")
  74.                      self.score_cpu = self.score_cpu + 1
  75.                 else:
  76.                      print ("Gana : ", nombre)
  77.                      self.score = self.score + 1
  78.           print (nombre, self.score, "CPU", self.score_cpu)
  79.           self.jugados = self.jugados + 1
  80.       def game_over(self):
  81.           print ("Resultado final :")
  82.           if self.score == self.score_cpu:
  83.              print ("Es un empate")
  84.           elif self.score > self.score_cpu:
  85.              print (nombre, "gana")
  86.           else:
  87.              print ("CPU gana")
  88.  
  89. juego = juegos(jugados)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement