Example #1
0
    def __init__(self, brachlist, commlist, stucklist):
        print "Init Bot..."
        print _version
        print "Reading Config of botsetting..."

        cleancfg(CFG_FILENAME)
        config = ConfigParser.RawConfigParser()
        config.read([CFG_FILENAME])
        self.BIMGDIR = config.get('botsetting', 'BIMGDIR')
        self.DefaultTH = float(config.get('botsetting', 'DefaultTH'))

        self.bdict = readimgs(brachlist, self.BIMGDIR)
        self.commdict = readimgs(commlist, self.BIMGDIR)
        self.bstuckdict = readimgs(stucklist, self.BIMGDIR)

        self.bwin = "bwin2"
        self.bstart = "btz"
        self.botdelay = 1

        #self.st_all = dict(self.bdict.items()+self.commdict.items())
        self.m = PyMouse()
        self.screen = GameScreen()

        self.multiplayer = False
        self.strict = False

        self.starttime = time.time()
        self.lasttime = time.time()

        print "Bot initial done!!!"
Example #2
0
	def _init_gamescreen(self):
		self.game = GameScreen(19, 11, 5)
		def back():
			self.menu.visible = True
			self.game.visible = False
			self.game.reset()
		def reset():
			self.game.tiles = self.game.init_tiles(self.game.transform)
		back_button = Button((50,10),on_click=back,text="return")
		reset_button = Button((300,10),on_click=reset,text="reset")
		self.game.buttons = (back_button,reset_button)
Example #3
0
 def __init__(self, size, scale):
     self.size = size
     self.scaledSize = tuple(i * scale for i in size)
     self.isRunning = True
     self.game = GameScreen(size)
     self.menu = MenuScreen(size)
     self.screen = self.game
Example #4
0
class MainGameState(GameState):
    engine = Engine()
    gamescreen = GameScreen()

    def render(self, fg_grid, bg0_grid, bg1_grid):
        # print 'this is the main game state'
        self.gamescreen.render(self.engine, fg_grid, bg0_grid, bg1_grid)

    def set_screen_width_height(self, dimensions):
        super(MainGameState, self).set_screen_width_height(dimensions)
        self.gamescreen.set_screen_width_height(dimensions)

    def process_inputs(self, delta):
        self.engine.process_inputs(delta)
Example #5
0
 def openGame(self,widget):
     game = GameScreen()
     print self.getPlayerA()
     print self.getPlayerB()
     game.start(self.getPlayerA(),self.getPlayerB())
Example #6
0
 def __init__(self, **kwargs):
     super(GameManager, self).__init__(**kwargs)
     self.add_widget(VocationSelectScreen(name="VocationSelect"))
     self.add_widget(GameScreen(name="GameScreen"))
Example #7
0
import pygame
from Engine import Engine
from GameScreen import GameScreen
from MenuScreen import MenuScreen
from GameoverScreen import GameoverScreen

pygame.init()
pygame.display.set_caption("Bullet Hell")

img = pygame.image.load("data/new_bullet.png")
pygame.display.set_icon(img)

size = width, height = 800, 600
engine = Engine()
engine.setResolution(size)
engine.registerScreen('Menu', MenuScreen(engine))
engine.registerScreen('Gameplay', GameScreen(engine))
engine.registerScreen('Gameover', GameoverScreen(engine))

engine.setActiveScreen('Menu')

engine.mainLoop()
Example #8
0
class App:
	"""
	The minesweeper game app. Has two main screens, a menu screen, and a game screen.
	"""
	def __init__(self):
		"""
		Constructor
		"""
		self.size = self.width, self.height = int(640*1.5), int(400*1.5)
		self._display_surf = None
		self._running = True
		self.font_holder = FontHolder()
		self._init_gamescreen()
		self.queue = []

	def _init_gamescreen(self):
		self.game = GameScreen(19, 11, 5)
		def back():
			self.menu.visible = True
			self.game.visible = False
			self.game.reset()
		def reset():
			self.game.tiles = self.game.init_tiles(self.game.transform)
		back_button = Button((50,10),on_click=back,text="return")
		reset_button = Button((300,10),on_click=reset,text="reset")
		self.game.buttons = (back_button,reset_button)


	def init_menu(self):
		"""
		Sets up the menu and its buttons.
		"""
		self.menu = Menu()

		def open_game():
			self.game.visible = True
			self.menu.visible = False
		def easy():
			self.game.width=8
			self.game.height=8
			self.game.num_bombs = 10
			self.game.tiles = self.game.init_tiles(self.game.transform)
			open_game()
		def medium():
			self.game.width = 16
			self.game.height = 16
			self.game.num_bombs = 40
			self.game.tiles = self.game.init_tiles(self.game.transform)
			open_game()
		def hard():
			self.game.width = 24
			self.game.height = 24
			self.game.num_bombs = 99
			self.game.tiles = self.game.init_tiles(self.game.transform)
			open_game()
		easy_button = Button((50, 55), on_click=easy, buffer=(10, 2))
		medium_button = Button((50, 55*2), on_click=medium, buffer=(10, 2))
		hard_button = Button((50, 55*3), on_click=hard, buffer=(10, 2))
		self.menu.buttons = (easy_button,medium_button,hard_button)

	def on_init(self):
		"""
		Initializes pygame and font handler, and sets up the surface and main menu.
		"""
		pygame.init()
		pygame.font.init()

		self._display_surf = pygame.display.set_mode(self.size,pygame.HWSURFACE)
		self._display_surf.fill(pygame.Color('black'))
		self._running = True

		self.init_menu()

	def on_event(self, event):
		"""
		Handles events thrown by pygame.
		:param event: event to handle
		"""
		if event.type == pygame.QUIT:
			self._running = False
		elif event.type == pygame.MOUSEBUTTONDOWN:
			if event.button == 1:
				mouse_pos = pygame.mouse.get_pos()
				if self.menu.visible:
					for b in self.menu.buttons:
						if b.rect.collidepoint(mouse_pos):
							b.on_click()
				elif self.game.visible:
					for column in self.game.tiles:
						for tile in column:
							if tile.rect.collidepoint(mouse_pos) and not tile.is_flagged:
								self.game.cascade(tile)
					for b in self.game.buttons:
						if b.rect.collidepoint(mouse_pos):
							b.on_click()
			elif event.button == 3:
				mouse_pos = pygame.mouse.get_pos()
				if self.game.visible:
					for column in self.game.tiles:
						for tile in column:
							if tile.rect.collidepoint(mouse_pos):
								tile.is_flagged = not tile.is_flagged
			elif event.button == 4:
				self._display_surf.scroll(0,-1)
			elif event.button == 5:
				self._display_surf.scroll(0,5)
		elif event.type == pygame.KEYDOWN:
			if event.key == pygame.K_a:
				mouse_pos = pygame.mouse.get_pos()
				if self.game.visible:
					for column in self.game.tiles:
						for tile in column:
							if tile.rect.collidepoint(mouse_pos):
								tile.is_flagged = not tile.is_flagged

	def on_loop(self):
		"""
		Checks whether you've won the game.
		:return:
		"""
		# TODO set up loop

	def on_render(self):
		"""
		Draws the menu or the main game screen.
		"""
		self.menu.draw(self._display_surf, self.font_holder)
		self.game.draw(self._display_surf, self.font_holder)
		pygame.display.flip()

	def on_cleanup(self):
		"""
		Quits pygame.
		"""
		pygame.quit()

	def on_execute(self):
		"""
		Runs the game.
		"""
		self.on_init()
		while self._running:
			for event in pygame.event.get():
				self.on_event(event)
			self.on_loop()
			self.on_render()
		self.on_cleanup()
Example #9
0
################

if __name__ != "__main__":
    print "Unknown run configuration"
    exit()

parser = argparse.ArgumentParser()
parser.add_argument('--bci', nargs='+', help="IP and port of the BCI machine.  Just specify port to make a server connection", required=True)
parser.add_argument('--tms', nargs='+', help="IP and port of the TMS machine.  Just specify port to make a server connection", required=True)
args = parser.parse_args()

#network sockets
bciSocket = TCPServer(int(args.bci[0])) if len(args.bci) == 1 else TCPClient(args.bci[0], int(args.bci[1]))
tmsSocket = TCPServer(int(args.tms[0])) if len(args.tms) == 1 else TCPClient(args.tms[0], int(args.tms[1]))

x = GameScreen(pyScreen,backImage,pygame.color.Color(121,74,0,0))
#x.addTextElem("fps","FPS: ",1069,33,pygame.color.Color(255,229,187,255),pygame.color.Color(121,74,0,0),17)
x.addTextElem("score","Score: ",1164,55,pygame.color.Color(255,229,187,255),pygame.color.Color(121,74,0,0),36)
x.addTextElem("attempts","Attempts: ",1164,110,pygame.color.Color(255,229,187,255),pygame.color.Color(121,74,0,0),36)
x.addTextElem("bigAnyKey","Press space to play",646,407,pygame.color.Color(255,235,175,255),pygame.color.Color(121,74,0,0),72)
x.addTextElem("bigScore","Score: ",646,387,pygame.color.Color(255,235,175,255),pygame.color.Color(121,74,0,0),72)
x.addTextElem("bigAttempts","Attempts: ",646,487,pygame.color.Color(255,235,175,255),pygame.color.Color(121,74,0,0),72)
x.addTextElem("countdown","0",646,407,pygame.color.Color(255,235,175,255),pygame.color.Color(121,74,0,0),100)

clock=pygame.time.Clock()

goodScore = 0
badScore = 0
attempts = 0
gunOrientation = 0
phase = 0
Example #10
0
class Robot:
    def __init__(self, brachlist, commlist, stucklist):
        print "Init Bot..."
        print _version
        print "Reading Config of botsetting..."

        cleancfg(CFG_FILENAME)
        config = ConfigParser.RawConfigParser()
        config.read([CFG_FILENAME])
        self.BIMGDIR = config.get('botsetting', 'BIMGDIR')
        self.DefaultTH = float(config.get('botsetting', 'DefaultTH'))

        self.bdict = readimgs(brachlist, self.BIMGDIR)
        self.commdict = readimgs(commlist, self.BIMGDIR)
        self.bstuckdict = readimgs(stucklist, self.BIMGDIR)

        self.bwin = "bwin2"
        self.bstart = "btz"
        self.botdelay = 1

        #self.st_all = dict(self.bdict.items()+self.commdict.items())
        self.m = PyMouse()
        self.screen = GameScreen()

        self.multiplayer = False
        self.strict = False

        self.starttime = time.time()
        self.lasttime = time.time()

        print "Bot initial done!!!"

    def beforefunc(self):
        nprint("---->No status Found! Call beforefunc!\n")

    def afterfunc(self, st, sltime):
        print "\n======================"
        self.lasttime = time.time()
        print "Time For this Loop: ", int(self.lasttime - sltime)
        print "Avg time per Loop: ", int(self.lasttime - self.starttime) / st
        print "Total time: ", int(self.lasttime -
                                  self.starttime), "For Loop Count: ", st
        #put statics and others here
        print "======================\n"

    def mainbot(self, t):
        if t == 0:
            t = 1000
        st = 0
        cnt = 0
        while t - st > 0:
            sltime = time.time()
            cnt += 1
            prgbar = "**** Looping Count ({}/{}): {}% ***\r".format(
                cnt, st, st * 100.0 / t * 1.0)
            pprint(prgbar)

            delay(self.botdelay)
            ss = self.screen.gstatus(self.commdict,
                                     threshold=self.DefaultTH,
                                     strict=self.strict,
                                     mp=self.multiplayer)

            if len(ss) == 0:
                nprint("---->Checking stuck!\t\n")
                ss = self.screen.gstatus(self.bstuckdict,
                                         threshold=self.DefaultTH,
                                         strict=self.strict,
                                         mp=self.multiplayer)
                if len(ss) == 0:
                    self.beforefunc()
                    continue

            for s, w, h, pt in ss:
                if s.startswith("b"):
                    bclick(self.m, w, h, pt)

                if s == self.bstart:
                    st += 1
                    self.afterfunc(st, sltime)
        #end while
        print "---->Quite script as MAX hit!"