<commit_before>﻿from Tkinter import *
from tennisgame import *
import time

'''
TKinter code based on <NAME>’s A Simple Animation Engine
'''

class Presenter(object):
    
    def __init__(self, model):
        self.views = []
        self.model = model

    def ballGoesOverRightSide(self):
        try:
            self.model.playerOneScores()
        except AttributeError:
            print 'implement playerOneScores() or adapt...'
        self._updateScore()

    def ballGoesOverLeftSide(self):
        try:
            self.model.playerTwoScores()
        except AttributeError:
            print 'implement playerTwoScores() or adapt...'
        self._updateScore()

    def addView(self, view):
        self.views.append(view)

    def _updateScore(self):
        score = ""
        try:
            score = self.model.score() 
            if type(score) == tuple:
                score = self._prettyPrint(score)
        except AttributeError:
            print 'implement score() or adapt'
        except:
            pass #use default value for any other error
        for view in self.views:
            view.setScore(score)

    def _prettyPrint(self, result):
        return str(result[0]) + " - " + str(result[1])        
            

class TennisBall:
    '''Draws the moving ball to canvas, takes view to inform
    when out of bounds'''
    def __init__(self, canvas, xy, color, delta, view):
        self.canvas = canvas
        self.view = view

        self.id = self.canvas.create_oval(
            -10, -10,
            10, 10,
            fill=color
            )
		
        self.canvas.move(self.id, xy[0], xy[1])
        self.delta = delta
        self.start = self.right

    def __call__(self, wins = True):
        return self.start # get things going

    def right(self, wins = True):
        '''wins is for scripted game, if True, will stop when ball has moved to right side'''
        xy = self.canvas.coords(self.id)
        if xy[2] >= self.canvas.winfo_width():
            if not wins:
                return self.left()

        if xy[2] >= self.canvas.winfo_width() + 20:
            if wins:
                self.view.ballOnTheEdge(wins)
                self.wait()
                self.canvas.move(self.id, -self.canvas.winfo_width()-20, 0)
                return self.right()
            return self.left()

        self.canvas.move(self.id, self.delta, 0)
        return self.right

    def left(self, wins = True):
        xy = self.canvas.coords(self.id)
        if xy[0] < -20:
            self.view.ballOnTheEdge(wins)
            self.wait()
            return self.right()

        self.canvas.move(self.id, -self.delta, 0)
        return self.left

    def wait(self):
        time.sleep(2)



class Simulator(object):
    def __init__(self, presenter):
        self.presenter = presenter
        self.presenter.addView(self)

        self.root = Tk()
        self.root.title("Tennis Simulator")
        self.root.resizable(0, 0)

        self.scoreframe = Frame(self.root, bd=5, relief=SUNKEN)
        self.playerOneName = Label(self.scoreframe, text="Player 1", font=("Helvetica", 16))
        self.playerTwoName = Label(self.scoreframe, text="Player 2", font=("Helvetica", 16))
        self.scoreVar = StringVar()
        self.playerScores = Label(self.scoreframe, textvariable=self.scoreVar, font=("Helvetica", 16))
        self.scoreVar.set("0 - 0")
        self.playerOneName.pack(side=LEFT)
        self.playerTwoName.pack(side=RIGHT)
        self.playerScores.pack(side=BOTTOM)
        self.scoreframe.pack(fill=BOTH)

        self.gameframe = Frame(self.root, bd=5, relief=SUNKEN)
        self.gameframe.pack()

        self.canvas = Canvas(self.gameframe, width=500, height=200, bd=0, highlightthickness=0, background='green')
        self.canvas.pack()

        self.net = self.canvas.create_line(250, 0, 250, 200)
        self.root.update() # fix geometry

        self.finished = False

        self.ball = TennisBall(self.canvas, (100, 100), "gold", 10, self)

        self.timeToQuit = False

        # Script, True means player one wins. False player two wins.
        self.script = (True, True, True, True)

    def run(self):
        try:
            for scripted_win in self.script:
                wins = scripted_win
                while True and not self.timeToQuit:
                    self.ball = self.ball(wins)<commit_msg>script makes player one lose once<commit_after>﻿from Tkinter import *
from tennisgame import *
import time

'''
TKinter code based on <NAME>’s A Simple Animation Engine
'''

class Presenter(object):
    
    def __init__(self, model):
        self.views = []
        self.model = model

    def ballGoesOverRightSide(self):
        try:
            self.model.playerOneScores()
        except AttributeError:
            print 'implement playerOneScores() or adapt...'
        self._updateScore()

    def ballGoesOverLeftSide(self):
        try:
            self.model.playerTwoScores()
        except AttributeError:
            print 'implement playerTwoScores() or adapt...'
        self._updateScore()

    def addView(self, view):
        self.views.append(view)

    def _updateScore(self):
        score = ""
        try:
            score = self.model.score() 
            if type(score) == tuple:
                score = self._prettyPrint(score)
        except AttributeError:
            print 'implement score() or adapt'
        except:
            pass #use default value for any other error
        for view in self.views:
            view.setScore(score)

    def _prettyPrint(self, result):
        return str(result[0]) + " - " + str(result[1])        
            

class TennisBall:
    '''Draws the moving ball to canvas, takes view to inform
    when out of bounds'''
    def __init__(self, canvas, xy, color, delta, view):
        self.canvas = canvas
        self.view = view

        self.id = self.canvas.create_oval(
            -10, -10,
            10, 10,
            fill=color
            )
		
        self.canvas.move(self.id, xy[0], xy[1])
        self.delta = delta
        self.start = self.right

    def __call__(self, wins = True):
        return self.start # get things going

    def right(self, wins = True):
        '''wins is for scripted game, if True, will stop when ball has moved to right side'''
        xy = self.canvas.coords(self.id)
        if xy[2] >= self.canvas.winfo_width():
            if not wins:
                return self.left()

        if xy[2] >= self.canvas.winfo_width() + 20:
            if wins:
                self.view.ballOnTheEdge(wins)
                self.wait()
                self.canvas.move(self.id, -self.canvas.winfo_width()-20, 0)
                return self.right()
            return self.left()

        self.canvas.move(self.id, self.delta, 0)
        return self.right

    def left(self, wins = True):
        xy = self.canvas.coords(self.id)
        if xy[0] < -20:
            self.view.ballOnTheEdge(wins)
            self.wait()
            return self.right()

        self.canvas.move(self.id, -self.delta, 0)
        return self.left

    def wait(self):
        time.sleep(2)



class Simulator(object):
    def __init__(self, presenter):
        self.presenter = presenter
        self.presenter.addView(self)

        self.root = Tk()
        self.root.title("Tennis Simulator")
        self.root.resizable(0, 0)

        self.scoreframe = Frame(self.root, bd=5, relief=SUNKEN)
        self.playerOneName = Label(self.scoreframe, text="Player 1", font=("Helvetica", 16))
        self.playerTwoName = Label(self.scoreframe, text="Player 2", font=("Helvetica", 16))
        self.scoreVar = StringVar()
        self.playerScores = Label(self.scoreframe, textvariable=self.scoreVar, font=("Helvetica", 16))
        self.scoreVar.set("0 - 0")
        self.playerOneName.pack(side=LEFT)
        self.playerTwoName.pack(side=RIGHT)
        self.playerScores.pack(side=BOTTOM)
        self.scoreframe.pack(fill=BOTH)

        self.gameframe = Frame(self.root, bd=5, relief=SUNKEN)
        self.gameframe.pack()

        self.canvas = Canvas(self.gameframe, width=500, height=200, bd=0, highlightthickness=0, background='green')
        self.canvas.pack()

        self.net = self.canvas.create_line(250, 0, 250, 200)
        self.root.update() # fix geometry

        self.finished = False

        self.ball = TennisBall(self.canvas, (100, 100), "gold", 10, self)

        self.timeToQuit = False

        # Script, True means player one wins. False player two wins.
        self.script = (True, False, True, True, True)

    def run(self):
        try:
            for scripted_win in self.script:
                wins = scripted_win
                while True and not self.timeToQuit:
                    self.ball = self.ball(wins)
{'fraction_non_alphanumeric': 0.1147095459177896, 'fraction_numerical': 0.014720869663684747, 'mean_word_length': 1.9667450453476654, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1143113', 'n_tokens_mistral': 2806, 'n_tokens_neox': 2622, 'n_words': 641}