class Game: fpsClock = pygame.time.Clock() _gameHandler = GameHandler() def __init__(self): pass def run(self): self.loadContent() # Game Loop while (True): self.update() self.draw() self.fpsClock.tick(60) def update(self): self._gameHandler.handleInput() self._gameHandler.update() def draw(self): self._gameHandler.draw() def init(self): pass def loadContent(self): self._gameHandler.loadContent() pygame.init()
def __init__(self,defaultM): self.default_message=defaultM #default message that sends parameter for the roboter self.testHandler=TestHandler(defaultM) self.position = [0,0] #position of robot self.orientation=[1,0] #orientation of robot self.next_corner = [None, None] self.game = GameHandler(defaultM,kfirst="E") self.target=[3,0] self.aktivescan=False self.scanidx = 0 self.Field_to_Table= lookUpTable.LookUpTable() # class to cast from an edge to a field and back if self.game.first =="E": print("human player starts") self.aktion="waitUser" self.nextaktion="findUserInput"
def __init__(self, main_window, window_height, window_width): super().__init__() self.game_handler = GameHandler(self) # lists of 5 widgets self.p2_rows_widgets = self.init_player_rows_widgets(initial_height=0) self.p1_rows_widgets = self.init_player_rows_widgets( initial_height=360) # 2D lists. [row][hand] self.p2_card_widgets = [] self.p1_card_widgets = [] self.dealt_card = self.init_dealt_card_ui() self.instructions_label = self.init_instructions_label( height=window_height - 180) self.init_table_card_widgets() self.pointer = GamePointer(self, POINTER_HEIGHT) self.text_box = self.init_text_box() self.state = 0 # 0: playing, 1-5: showing final hands
def handleMessage(self,message): #handle message message=json.loads(message.decode('utf-8')) #decode the the message print("message:") print(message) if(message.get('Aktion')=="Test"): # for testing print("in test") return self.testHandler.handleMessage(message) if (message.get('Aktion') == "Befehl"): #determine in what state the server is to correctly respond print(self.game.game_on) if not self.game.game_on: #start new game self.game = GameHandler(self.default_message) if self.game.first == "E": self.aktion = "waitUser" self.nextaktion = "findUserInput" if self.aktion=="waitUser": #send wait return self.sendwait() if self.aktion == "UserInputFind": #look for marked field if self.aktivescan: if message.get('found'): #merked field was found inputvalue =self.Field_to_Table.lookUpTable(self.position) return self.endscan(inputvalue) if self.scanidx >= len(self.neutrals): # walked through whole field and npthing found x = input("where did you play?") return self.endscan(x) if self.position == self.Field_to_Table.lookUpField(self.neutrals[self.scanidx]): #nothing found on the current posiiton print("ist das selbe erhöhen") self.scanidx = self.scanidx + 1 return self.handleScan() #determine where to scan next if self.aktion=="sendprep": print("send prep") return self.sendprep() if (self.aktion == "waiting" and self.nextaktion=="UserInputFind"): if self.nextaktion == "UserInputFind": # wenn nicht weitersuchen print("in findUserInput") self.neutrals = self.game.getNeutral() self.scanidx = 0 self.aktivescan = True self.aktion = "UserInputFind" self.nextaktion = "makemove" return self.handleScan() if message.get('Aktion') == "endwait": print("endwait on server")
import json import os import sys from flask import abort, Flask, jsonify, request, send_from_directory from flask_cors import CORS from GameHandler import GameHandler if not os.path.exists('react-front-end/build'): print( 'The react frontend is not built yet. Please go into the "react-front-end" folder and run "npm install", "npm run build"' ) sys.exit(1) app = Flask('chess', static_folder='react-front-end/build') CORS(app) games_handler = GameHandler() @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def index(path): """ The route to the react frontend. """ if path != "" and os.path.exists(app.static_folder + '/' + path): return send_from_directory(app.static_folder, path) else: return send_from_directory(app.static_folder, 'index.html') @app.route('/api/', methods=['GET', 'POST'])
from GameHandler import GameHandler from Card import Card hand1 = Card.list2hand([0, 2, 4, 6]) hand2 = Card.list2hand([1, 3, 5, 7]) g = GameHandler("Alice", "Bill") g.gameLoop()
import qi import os from GameHandler import GameHandler if __name__ == "__main__": ip = os.environ['PEPPER_IP'] connection_url = ip + ":9559" app = qi.Application(["--qi-url=" + connection_url]) app.start() session = app.session motion = session.service('ALMotion') leds = session.service("ALLeds") motion.setExternalCollisionProtectionEnabled('All', False) motion.setCollisionProtectionEnabled('Arms', True) print('arms collison protection: ' + str(motion.getCollisionProtectionEnabled('Arms'))) print('external collison protection: ' + str(motion.getExternalCollisionProtectionEnabled('All'))) motion.wakeUp() GameHandler = GameHandler(session, ip, motion, leds)
def main(): GameHandler()