Commit 1ef01897 authored by nouman.ashraf's avatar nouman.ashraf

Initial commit

parents
import pygame
import time
import random
pygame.init()
width = 800
height = 600
black = (0,0,0)
white = (255,255,255)
red = (200,0,0)
green = (0,200,0)
brightred = (255,0,0)
brightgreen = (0,255,0)
display = pygame.display.set_mode((width,height))
pygame.display.set_caption('Stock Market Game')
clock = pygame.time.Clock()
def money(credit):
font = pygame.font.SysFont(None, 25)
text = font.render("Money: "+str(credit), True, black)
display.blit(text. (0,0))
def items():
items = ["Computer","Apple_iphone","Comic book"]
computer_price = 10
Apple_iphone_price = 100
comicbook_price = 25
itemprices = [computer_price,Apple_iphone_price,comicbook_price]
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def message_display(text):
largeText = pygame.font.Font('freesansbold.ttf',60)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((width/2),(height/2))
display.blit(TextSurf, TextRect)
pygame.display.update()
main()
def button(m,x,y,w,h,nh,ih,action=None):
mouse = pygame.mouse.get_pos()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(display, ih,(x,y,w,h))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(display, nh,(x,y,w,h))
text = pygame.font.Font("freesansbold.ttf",20)
textSurf, textRect = text_objects(m, text)
textRect.center = ((x+(w/2)), (y+(h/2) )
display.blit(textSurf, textRect)
def endgame():
pygame.quit()
quit()
def gamestart():
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
display.fill(white)
largeText = pygame.font.Font('freesansbold.ttf',60)
TextSurf, TextRect = text_objects("Stock Market Game", largeText)
TextRect.center = ((width/2),(height/2))
display.blit(TextSurf, TextRect)
button("Start",150,450,100,50,green,brightgreen,main)
button("Quit ",550,450,100,50,red,brightred, endgame)
pygame.display.update()
clock.tick(15)
def main():
money = 500
maingame = False
while not maingame:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
pygame.display.update()
gamestart()
main()
pygame.quit()
quit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment