Beispiel #1
0
    def __init__(self):
        self.serviceIndex = 1 if Math.random(
        ) > 0.5 else 0  # Index of player that has initial service
        self.pause = True  # Start game in paused state
        self.keySet = set()

        self.canvas = __new__(
            fabric.Canvas('canvas', {
                backgroundColor: 'black',
                originX: 'center',
                originY: 'center'
            }))
        self.canvas.onWindowResise = self.resize  # Install draw callback, will be called asynch
        self.canvas.onWindowDraw = self.draw  # Install resize callback, will be called if resized
        self.canvas.lineWidth = 2
        self.canvas.clear()

        self.attributes = []  # All attributes will insert themselves here
        self.paddles = [Paddle(self, index)
                        for index in range(2)]  # Pass game as parameter self
        self.ball = Ball(self)
        self.scoreboard = Scoreboard(self)

        window.setInterval(self.update,
                           10)  # Install update callback, time in ms
        window.setInterval(self.draw, 20)  # Install draw callback, time in ms
        window.addEventListener('keydown', self.keydown)
        window.addEventListener('keyup', self.keyup)

        self.time = +__new__(Date)
Beispiel #2
0
    def __init__(self):
        self.serviceIndex = 1 if Math.random(
        ) > 0.5 else 0  # Index of player that has initial service
        self.pause = True  # Start game in paused state
        self.keyCode = None

        self.textFrame = document.getElementById('text_frame')
        self.canvasFrame = document.getElementById('canvas_frame')
        self.buttonsFrame = document.getElementById('buttons_frame')

        self.canvas = __new__(
            fabric.Canvas(
                'canvas', {
                    'backgroundColor': 'black',
                    'originX': 'center',
                    'originY': 'center'
                }))
        self.canvas.onWindowDraw = self.draw  # Install draw callback, will be called asynch
        self.canvas.lineWidth = 2
        self.canvas.clear()

        self.attributes = []  # All attributes will insert themselves here
        self.paddles = [Paddle(self, index)
                        for index in range(2)]  # Pass game as parameter self
        self.ball = Ball(self)
        self.scoreboard = Scoreboard(self)

        window.setInterval(self.update,
                           10)  # Install update callback, time in ms
        window.setInterval(self.draw, 20)  # Install draw callback, time in ms
        window.addEventListener('keydown', self.keydown)
        window.addEventListener('keyup', self.keyup)

        self.buttons = []

        for key in ('A', 'Z', 'K', 'M', 'space', 'enter'):
            button = document.getElementById(key)
            button.addEventListener(
                'mousedown',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, True)
                 )(key))  # Returns inner lambda
            button.addEventListener(
                'touchstart',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, True))(key))
            button.addEventListener(
                'mouseup',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, False))(key))
            button.addEventListener(
                'touchend',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, False))(key))
            button.style.cursor = 'pointer'
            button.style.userSelect = 'none'
            self.buttons.append(button)

        self.time = +__new__(Date)

        window.onresize = self.resize
        self.resize()
    def __init__(self):
        self.keyCode = None
        self.pause = True

        self.canvasFrame = document.getElementById('canvas_frame')
        self.canvas = __new__(
            fabric.Canvas(
                'canvas', {
                    'backgroundColor': 'black',
                    'originX': 'center',
                    'originY': 'center'
                }))
        self.canvas.onWindowDraw = self.draw  # Install draw callback, will be called asynch
        self.canvas.lineWidth = 2
        self.canvas.clear()

        set_size = 6

        self.attributes = []
        squares = [Square(self, index) for index in range(set_size)]
        self.squares = [Square.set(square) for square in squares]

        window.setInterval(self.update,
                           10)  # Install update callback, time in ms
        window.setInterval(self.draw, 20)  # Install draw callback, time in ms
        window.addEventListener('keydown', self.keydown)
        window.addEventListener('keyup', self.keyup)

        self.buttons = []

        for key in ('F', 'J', 'space'):
            button = document.getElementById(key)
            button.addEventListener(
                'mousedown',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, True)
                 )(key))  # Returns inner lambda
            button.addEventListener(
                'touchstart',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, True))(key))
            button.addEventListener(
                'mouseup',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, False))(key))
            button.addEventListener(
                'touchend',
                (lambda aKey: lambda: self.mouseOrTouch(aKey, False))(key))
            button.style.cursor = 'pointer'
            button.style.userSelect = 'none'
            self.buttons.append(button)

        self.time = +__new__(Date)
Beispiel #4
0
    def __init__ (self):
        self.pause = True                           # Start experiment in paused state
        self.keyCode = None
        
        self.textFrame = document.getElementById ('text_frame')
        self.canvasFrame = document.getElementById ('canvas_frame')
        self.buttonsFrame = document.getElementById ('buttons_frame')
        
        self.canvas = __new__ (fabric.Canvas ('canvas', {'backgroundColor': 'grey', 'originX': 'center', 'originY': 'center'}))
        self.canvas.onWindowDraw = self.draw        # Install draw callback, will be called asynch
        self.canvas.lineWidth = 2
        self.canvas.clear ()    

        self.set_size = 6
        self.attributes = []                        # All attributes will insert themselves here
        self.stimuli = [Stimuli(self, index) for index in range (self.set_size)]    # Pass game as parameter self
        self.fixation_point = Fixation(self)
        
        window.setInterval (self.update, 1)    # Install update callback, time in ms
        window.setInterval (self.draw, 20)      # Install draw callback, time in ms
        window.addEventListener ('keydown', self.keydown)
        window.addEventListener ('keyup', self.keyup)
        
        self.buttons = []
        
        for key in ('F', 'J','space'):
            button = document.getElementById (key)
            button.addEventListener ('mousedown', (lambda aKey: lambda: self.mouseOrTouch (aKey, True)) (key))  # Returns inner lambda
            button.addEventListener ('touchstart', (lambda aKey: lambda: self.mouseOrTouch (aKey, True)) (key))
            button.addEventListener ('mouseup', (lambda aKey: lambda: self.mouseOrTouch (aKey, False)) (key))
            button.addEventListener ('touchend', (lambda aKey: lambda: self.mouseOrTouch (aKey, False)) (key))
            button.style.cursor = 'pointer'
            button.style.userSelect = 'none'
            self.buttons.append (button)
        
            
        self.time = + __new__ (Date)
        
        self.start_exp_timer = self.time
        self.target_presented = bool
        self.isi_presented = bool
        self.all_presented = bool
        self.trial_set = bool
        self.target_color = []
        
        window.onresize = self.resize
        self.resize ()
Beispiel #5
0
def startTheGame():
    nonlocal canvas
    canvas = __new__(fabric.Canvas("canvas", {'width': w, 'height': h}))
    document.getElementById("canvas").style.border = '5px solid black'
    nonlocal started
    nonlocal player
    nonlocal apple
    nonlocal obstacle
    nonlocal mongoose
    player = Snake()
    apple = Apple()
    obstacle = Obstacle()
    mongoose = Mongoose()
    window.setTimeout(genMongoose, 2000)
    window.addEventListener('keydown', player.turn, True)
    document.addEventListener('click', player.turn_mobile)
    started = True