def __init__(self): print("Pygame Version: {ver}".format(ver=pygame.ver)) pygame.init() pygame.display.set_caption("Circles") self.WindowSize = (1920, 1080) self.BGroundColor = (255, 128, 45) self.screen = pygame.display.set_mode(self.WindowSize, pygame.FULLSCREEN) self.bGameShouldLoop = True self.EL = EventListener(self.screen) self.screen.fill((255, 128, 45))
class Game: ### THIS IS GameInstanceClass, lets call it GIC print "Game Instance created." def __init__(self): print "Starting Game.__init__()." # Window init self.RESOLUTION = 1024, 768 TITLE_TEXT = "pedeRPG" self.window = sf.RenderWindow(sf.VideoMode(*self.RESOLUTION), TITLE_TEXT) # Create control scheme self.controls = {'up':0, 'down':0, 'left':0, 'right':0, 'rotateL':0, 'rotateR':0} self.events = EventListener() # Create map class starMap = WorldCreator.StarMap() # Create star data starMap.randomStarGenerator() ## Create Player ## TODO # Player.SpaceShip(PARAMETERS) self.playerOne = Player(self) print "Game.__init__ finished. Starting gameLoop." # START OUR GAME LOOP! self.gameLoop() def gameLoop(self): # Game runs while the window is open while self.window.is_open: # We start every iteration with new inputs self.events.listen(self) # Calculate how these inputs change our world, player, etc. self.calculateIteration() # DRAW - RENDER EVERYTHING # clear screen self.window.clear(sf.Color.TRANSPARENT) self.window.draw(self.playerOne.shape) self.window.display() def calculateIteration(self): ## TODO # Calculate everything self.playerOne.movePlayer(self)
def __init__(self): # The Abi File parser self.__abiParser = AbiParser() # The Event Listener class instance self.__eventListener = EventListener() # The Event Report class instance self.__eventReport = EventReport() # Variable to store the action chosen self.__action = None
def __init__(self): print "Starting Game.__init__()." # Window init self.RESOLUTION = 1024, 768 TITLE_TEXT = "pedeRPG" self.window = sf.RenderWindow(sf.VideoMode(*self.RESOLUTION), TITLE_TEXT) # Create control scheme self.controls = {'up':0, 'down':0, 'left':0, 'right':0, 'rotateL':0, 'rotateR':0} self.events = EventListener() # Create map class starMap = WorldCreator.StarMap() # Create star data starMap.randomStarGenerator() ## Create Player ## TODO # Player.SpaceShip(PARAMETERS) self.playerOne = Player(self) print "Game.__init__ finished. Starting gameLoop." # START OUR GAME LOOP! self.gameLoop()
class GI: def __init__(self): print("Pygame Version: {ver}".format(ver=pygame.ver)) pygame.init() pygame.display.set_caption("Circles") self.WindowSize = (1920, 1080) self.BGroundColor = (255, 128, 45) self.screen = pygame.display.set_mode(self.WindowSize, pygame.FULLSCREEN) self.bGameShouldLoop = True self.EL = EventListener(self.screen) self.screen.fill((255, 128, 45)) def Update(self): if self.bGameShouldLoop: self.EL.CheckEvents() self.screen.fill(self.BGroundColor) for x in self.EL.circles: if x.radius < self.WindowSize[0]: pygame.draw.circle(self.screen, x.color, (x.Location[0], x.Location[1]), x.radius, x.thickness) x.UpdateSize() else: if x.thickness == 0: self.BGroundColor = x.color self.screen.fill(self.BGroundColor) for i in self.EL.circles: if i != x: self.EL.circles.remove(i) else: break self.EL.circles.remove(x) pygame.display.flip()
class Connector: """ The class is used to create a connection to the blockchain using the web3.py library """ def __init__(self): # The Abi File parser self.__abiParser = AbiParser() # The Event Listener class instance self.__eventListener = EventListener() # The Event Report class instance self.__eventReport = EventReport() # Variable to store the action chosen self.__action = None def connectToWeb3(self, privateKey, provider, abipath, contAddr): """ This method creates a connection to blockchain using the Web3 library """ w3 = Web3(Web3.HTTPProvider(provider)) # A bool to check if a connection was made checkConnection = w3.isConnected() if not checkConnection: Logger.fatal("Couldn't connect to the provider") print(HELP_MSG) return # The length of the private key provided by the user pkLen = len(privateKey) if pkLen != 64: Logger.fatal("You have entered an unvalid private key") return pk = "0x" + privateKey account = w3.eth.account.privateKeyToAccount(pk) accountAddress = account.address # Web3 method to get all accounts on blockchain accounts = w3.eth.accounts # Check is the account derived from the private key is a legitime address if (accountAddress not in accounts): Logger.fatal( "Your public address is not a valid address on the blockchain") return # Get the contract's compiled ABI file abi = AbiParser().parseAbi(abipath) # Check if the contract is valid on the blockchain try: w3.eth.getCode(contAddr) except exceptions.InvalidAddress: Logger.fatal("You have entered an invalid smart contract address") return contractAddress = w3.toChecksumAddress(contAddr) # Initialize a contract instance contract = w3.eth.contract(address=contractAddress, abi=abi) # Set the access account of the blockchain print("") w3.eth.defaultAccount = accountAddress Logger.info("You are now logged in with address: " + w3.eth.defaultAccount) # Start the program while True: try: print("") self.initializeAction(contract, w3, accountAddress, pk) time.sleep(2) except KeyboardInterrupt: Logger.info("Program interrupted! Exiting...") break def getAction(self, prompt): """ This method grabs the user's choice """ while True: action = input(prompt).strip().lower() if action in ('1', '2', '3'): return int(action) else: Logger.info("Invalid choice! Please try again") def initializeAction(self, contract, web3, address, privateKey): """ The method initializes the screen """ print("Choose what you would like to do: ") print("[1] : Report an event") print("[2] : Listen for current events") print("[3] : Exit") try: self.__action = self.getAction("Choose an action: ") except EOFError: Logger.info("Program interrupted here! Exiting...") sys.exit() if self.__action == 1: self.__eventReport.reportEvent(contract, web3, address, privateKey) elif self.__action == 2: self.__eventListener.listenForEvents(contract, web3) elif self.__action == 3: Logger.info("Exiting...") sys.exit()