def buy_coal(): BUY = pygame.image.load('../media/images/buy.gif') SCREEN.blit(BUY, (0, 0)) text = drawtext('BUY COAL POWER PLANT: 100000/-', 20) SCREEN.blit(text, (250, 200)) while True: process() pygame.display.update() clicked = pygame.mouse.get_pressed() pos = pygame.mouse.get_pos() if clicked[0] is 1: if 660 < pos[0] < 715 and 190 < pos[1] < 220: break elif 420 < pos[0] < 540 and 350 < pos[1] < 400: a = [] a = chkavail() if a[1] is 1: text1 = drawtext('You have already got one unit', 20) SCREEN.blit(text1, (300, 320)) else: f = open('../data_files/money.txt', 'r') for line in f: line = line[:-1] f.close() b = int(line) if b > 100000: b -= 100000 f = open('../data_files/money.txt', 'w') f.write(str(b) + '\n') text1 = drawtext('You bought one Coal Power Plant', 20) SCREEN.blit(text1, (300, 300)) a[1] = 1 f = open('../data_files/availability.txt', 'w') for i in range(12): f.write(str(a[i]) + '\n') f.close() pygame.time.delay(200) else: tr = drawtext('You dont have enough money', 20) SCREEN.blit(tr, (300, 320)) CLOCK.tick(FPS)
from process import process from textinput import drawtext from mainmenu import mainmenu from source_files.gamestart import gamestart from available import chkavail pygame.init() WIDTH = 960 HEIGHT = 640 FPS = 24 CLOCK = pygame.time.Clock() SCREEN = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32) text = drawtext('PRODUCTION GROUND', 32) BACKGROUND = pygame.image.load('../media/images/main_back.png') # music module pygame.mixer.music.load('../media/music/bensound-slowmotion.mp3') pygame.mixer.music.play(-1) # game start module gamestart() # MAIN MENU mainmenu() while True:
def pressed_coal(): print("you clcicked coal") i = 0 NEWSCREEN.blit(NEWWINDOW, (0, 0)) text = drawtext('COAL POWER PLANT', 26) start = drawtext('START', 20) stop = drawtext('STOP', 20) resources = drawtext('RESOURCES', 20) one = drawtext('Remaining Resources:', 20) two = drawtext('Production Per Hour:', 20) three = drawtext('Total Production:', 20) four = drawtext('Profit Earned:', 20) five = drawtext('Total Pollution:', 20) NEWSCREEN.blit(text, (300, 120)) NEWSCREEN.blit(start, (200, 470)) NEWSCREEN.blit(stop, (400, 470)) NEWSCREEN.blit(resources, (600, 470)) NEWSCREEN.blit(one, (250, 200)) NEWSCREEN.blit(two, (250, 220)) NEWSCREEN.blit(three, (250, 240)) NEWSCREEN.blit(four, (250, 260)) NEWSCREEN.blit(five, (250, 280)) while True: process() pressed = pygame.mouse.get_pressed() pos = pygame.mouse.get_pos() if pressed[0] is 1: if pos[0] > 740 and pos[0] < 780 and pos[1] > 120 and pos[1] < 160: break elif pos[0] > 190 and pos[0] < 370 and pos[1] > 460 and pos[ 1] < 500: t1 = drawtext('The production has started', 20) NEWSCREEN.blit(t1, (350, 400)) starts(10) print('pressed start') elif pos[0] > 390 and pos[0] < 570 and pos[1] > 460 and pos[ 1] < 500: t2 = drawtext('The production has stopped', 20) NEWSCREEN.blit(t2, (350, 430)) print('pressed stop') elif pos[0] > 590 and pos[0] < 770 and pos[1] > 460 and pos[ 1] < 500: t3 = drawtext('The resources remained are: 20%', 20) NEWSCREEN.blit(t3, (350, 370)) print('presses resources') # outputting from the file f = open('../data_files/coal.txt', 'r') t = 0 for line in f: line = line[:-1] text = drawtext(line, 20) NEWSCREEN.blit(text, (450, 200 + t)) t += 20 pygame.display.update() CLOCK.tick(24) f.close() print('got out of the while loop')
def inventory(): INVENT = pygame.image.load('../media/images/inventory.jpg') #file operations while True: process() SCREEN.blit(INVENT, (0, 0)) a = [] a = chkavail() text1 = drawtext(str(a[0])+'/1', 20) SCREEN.blit(text1, (250, 217)) text1 = drawtext(str(a[1])+'/1', 20) SCREEN.blit(text1, (530, 220)) text1 = drawtext(str(a[2]+a[3])+'/2', 20) SCREEN.blit(text1, (810, 215)) text1 = drawtext(str(a[4]+a[5])+'/2', 20) SCREEN.blit(text1, (200, 480)) text1 = drawtext(str(a[6]+a[7])+'/2', 20) SCREEN.blit(text1, (410, 480)) text1 = drawtext(str(a[8]+a[9])+'/2', 20) SCREEN.blit(text1, (640, 480)) text1 = drawtext(str(a[10]+a[11])+'/2', 20) SCREEN.blit(text1, (860, 480)) pygame.display.update() clicked = pygame.mouse.get_pressed() pos = pygame.mouse.get_pos() if clicked[0] is 1: if 20 < pos[0] < 70 and 20 < pos[1] < 55: break elif 120 < pos[0] < 280 and 247 < pos[1] < 290: buy_atomic() elif 400 < pos[0] < 560 and 250 < pos[1] < 290: buy_coal() elif 680 < pos[0] < 845 and 245 < pos[1] < 294: buy_natural() elif 75 < pos[0] < 240 and 500 < pos[1] < 560: buy_solar() elif 290 < pos[0] < 450 and 500 < pos[1] < 560: buy_wind() elif 517 < pos[0] < 650 and 510 < pos[1] < 560: buy_hydro() elif 740 < pos[0] < 900 and 510 < pos[1] < 560: buy_geothermal() CLOCK.tick(FPS)