Advertisement
richigarza

subasta.py

Nov 21st, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.80 KB | None | 0 0
  1. #! /usr/bin/python
  2.  
  3. import random
  4. import time
  5. import pygame
  6. from pygame.locals import *
  7.  
  8. pygame.init()
  9.  
  10. SCREEN_WIDTH = 500
  11. SCREEN_HEIGHT = 350
  12.  
  13. def subasta(oferta, sujeto1, sujeto2, saldosujeto1, saldosujeto2, done, ultima):
  14.     while done==False:     
  15.    
  16.     if sujeto1 > sujeto2:
  17.         oferta = sujeto1
  18.     elif sujeto1 == sujeto2:
  19.         sujeto1 = int(sujeto1+random.randint(1, 10))
  20.         sujeto2 = int(sujeto2+random.randint(1, 10))
  21.     else:
  22.         oferta = sujeto2
  23.  
  24.     if ultima == True:
  25.         done = True
  26.     textoferta = str(oferta)
  27.     textsujeto1 = str(sujeto1)
  28.     textsujeto2 = str(sujeto2)         
  29.     pygame.display.update()
  30.     screen.blit(letra2.render("Subasta", True, (34, 139, 34)), (130, 50))
  31.     screen.blit(letra.render("Oferta Mayor: %s " % textoferta, True, (0, 0, 0)), (50, 100))
  32.     screen.blit(letra.render("Sujeto1 ofrece: %s " % textsujeto1, True, (0, 0, 0)), (50, 140))
  33.     screen.blit(letra.render("Sujeto2 ofrece: %s " % textsujeto2, True, (0, 0, 0)), (50, 180))
  34.     pygame.display.update()
  35.     screen.blit(fondo, (0, 0))
  36.         time.sleep(1)
  37.    
  38.     if sujeto1 > sujeto2:
  39.         sujeto2 = sujeto1+random.randint(1,100)
  40.     elif sujeto1 < sujeto2:
  41.         sujeto1 = sujeto2+random.randint(1,100)
  42.    
  43.     if sujeto1 > saldosujeto1:
  44.         sujeto1 = saldosujeto1
  45.         print "Sujeto1 ya ofrecio todo su saldo"
  46.         ultima = True
  47.         screen.blit(letra.render("Gano sujeto2 con: %s " % textsujeto2, True, (255, 0, 0)), (50, 220))
  48.     elif sujeto2 > saldosujeto2:
  49.         sujeto2 = saldosujeto2
  50.         print "Sujeto2 ya ofrecio todo su saldo"
  51.         screen.blit(letra.render("Gano sujeto1 con: %s " % textsujeto1, True, (255, 0, 0)), (50, 220))
  52.         ultima = True
  53.  
  54.         for event in pygame.event.get():
  55.             if event.type == pygame.QUIT:
  56.                 exit()
  57.  
  58.  
  59.  
  60. if __name__ == "__main__":
  61.  
  62.     try:
  63.       oferta = int(val)
  64.     except:
  65.       oferta = int(raw_input('Ingresa el precio inicial: '))
  66.  
  67.  
  68.     screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  69.     pygame.display.set_caption("Subasta")
  70.     fondo = pygame.image.load("lol.png")
  71.     screen.blit(fondo, (0, 0))
  72.     letra = pygame.font.Font(None, 40)
  73.     letra2 = pygame.font.Font(None, 60)
  74.     screen.blit(fondo, (0, 0))
  75.     pygame.display.flip()
  76.     time.sleep(2)
  77.     saldosujeto1 = int(random.randint(1000, 10000))# Saldo del sujeto 1
  78.     saldosujeto2 = int(random.randint(1000, 10000))# Saldo del sujeto 2
  79.     print saldosujeto1
  80.     print saldosujeto2
  81.  
  82.     if oferta < 0:
  83.         print "El numero es negativo"
  84.         exit()
  85.     else:
  86.     sujeto1 = int(oferta+random.randint(1, 10))# Primer grito
  87.     sujeto2 = int(oferta+random.randint(1, 10))# Primer grito
  88.     if sujeto1 == sujeto2:
  89.         sujeto1 = int(sujeto1+random.randint(1, 10))
  90.         sujeto2 = int(sujeto2+random.randint(1, 10))
  91.  
  92.     textoferta = str(oferta)
  93.     textsujeto1 = str(sujeto1)
  94.     textsujeto2 = str(sujeto2)
  95.     done = False
  96.     ultima = False
  97.     pygame.display.update()
  98.     subasta(oferta, sujeto1, sujeto2, saldosujeto1, saldosujeto2, done, ultima)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement