def __init__(self, handle): activity.Activity.__init__(self, handle) self._activity = run.Game(self) self.build_toolbar() self._pygamecanvas = sugargame.canvas.PygameCanvas(self) self.set_canvas(self._pygamecanvas) self._pygamecanvas.run_pygame(self._activity.loop)
def __init__(self, handle): activity.Activity.__init__(self, handle) self.game = run.Game(self) self.build_toolbar() self.game.canvas = self._pygamecanvas = sugargame.canvas.PygameCanvas( self, main=self.game.run, modules=[pygame.display, pygame.font, pygame.camera]) self.set_canvas(self._pygamecanvas) Gdk.Screen.get_default().connect('size-changed', self.__configure_cb)
import run a = "MinMax(self,1,depth_of_search=5)" b = "MonteCarlo(self,2,iter_max=10)" players_1 = [] players_2 = [] iter_max = [i * 100 for i in range(11)] # depth_of_search = [i for i in range(11)] # print(iter_max, depth_of_search) print(iter_max) for a in iter_max: players_1.append("MonteCarlo(self,1,iter_max=" + str(a) + ")") players_2.append("MonteCarlo(self,2,iter_max=" + str(a) + ")") board_size = 4, 6, 8 number_of_plays = 10 play_number = 0 game = run.Game() while play_number < number_of_plays: play_number += 1 for size in board_size: for player_1 in players_1: for player_2 in players_2: #print(player_1, player_2, size) game.game_start(player_1, player_2, size)
import pygame as pg import run from settings import window, colors g = run.Game() class MenuSet: def __init__(self): pg.init() self.running = True self.UP_KEY, self.DOWN_KEY, self.START_KEY, self.BACK_KEY = False, False, False, False self.DISPLAY_W, self.DISPLAY_H = window['WIDTH'], window['HEIGHT'] self.display = pg.Surface((self.DISPLAY_W, self.DISPLAY_H)) self.window = pg.display.set_mode(((self.DISPLAY_W, self.DISPLAY_H))) self.font_name = pg.font.get_default_font() self.main_menu = MainMenu(self) self.curr_menu = self.main_menu def check_events(self): for event in pg.event.get(): if event.type == pg.QUIT: self.running = False self.curr_menu.run_display = False if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self.START_KEY = True if event.key == pg.K_BACKSPACE: self.BACK_KEY = True if event.key == pg.K_DOWN: self.DOWN_KEY = True if event.key == pg.K_UP:
def __init__(self): self.screen = pg.display.set_mode((0, 0), pg.FULLSCREEN) pg.font.init() pg.display.set_caption("Main Menu") pg.font.init() self.click = (0, 0) self.size = self.screen.get_size() self.pos = (self.size[0] / 2, self.size[1] / 2) while True: for event in pg.event.get(): if event.type == pg.QUIT: sys.exit(0) elif event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE: sys.exit(0) elif event.type == pg.KEYDOWN and event.key == pg.K_SPACE: run.Game() elif event.type == pg.MOUSEBUTTONDOWN: self.click = pg.mouse.get_pos() if (self.click[0] > self.circlee.bottomleft[0]) and ( self.click[0] < self.circlee.bottomright[0] ) and (self.click[1] > self.circlee.topleft[1]) and ( self.click[1] < self.circlee.bottomright[1]): self.diffile = open("diff.txt", "w") self.poziom = "Easy" self.diffile.write(self.poziom) self.diffile.close() if (self.click[0] > self.circlem.bottomleft[0]) and ( self.click[0] < self.circlem.bottomright[0] ) and (self.click[1] > self.circlem.topleft[1]) and ( self.click[1] < self.circlem.bottomright[1]): self.diffile = open("diff.txt", "w") self.poziom = "Medium" self.diffile.write(self.poziom) self.diffile.close() if (self.click[0] > self.circleh.bottomleft[0]) and ( self.click[0] < self.circleh.bottomright[0] ) and (self.click[1] > self.circleh.topleft[1]) and ( self.click[1] < self.circleh.bottomright[1]): self.diffile = open("diff.txt", "w") self.poziom = "Hard" self.diffile.write(self.poziom) self.diffile.close() self.screen.fill((0, 0, 0)) myfont = pg.font.SysFont('Comic Sans MS', 80) textsurface = myfont.render("Gooood Spaceable", True, (222, 132, 50)) self.screen.blit(textsurface, (self.pos[0] - 356, self.pos[1] - 200)) myfont = pg.font.SysFont('Comic Sans MS', 30) textsurface = myfont.render("Press <space> to play!", True, (50, 180, 130)) self.screen.blit(textsurface, (self.pos[0] - 170, self.pos[1] + 100)) self.circlee = pg.draw.circle( self.screen, (59, 170, 70), (int(self.pos[0] - 80), int(self.pos[1] - 30)), 20) self.circlem = pg.draw.circle( self.screen, (200, 200, 20), (int(self.pos[0] - 20), int(self.pos[1] - 30)), 20) self.circleh = pg.draw.circle( self.screen, (170, 70, 80), (int(self.pos[0] + 40), int(self.pos[1] - 30)), 20) diffread = open("diff.txt", "r") diffread = diffread.read() myfont = pg.font.SysFont('Comic Sans MS', 30) textsurface = myfont.render("Difficulty: " + str(diffread), True, (200, 160, 220)) self.screen.blit(textsurface, (self.pos[0] - 140, self.pos[1])) myfont = pg.font.SysFont('Comic Sans MS', 30) textsurface = myfont.render( "Use <w,s,a,d> or <arrows> to move and <space> to shoot!", True, (50, 100, 130)) self.screen.blit(textsurface, (self.pos[0] - 390, self.pos[1] + 60)) pg.display.flip()