Exemple #1
0
    def __init__(self):
        title = "Trip: Down The Rabbit Hole"  #working title
        self.canvas_width = 500
        self.canvas_height = 500
        self.frame = simplegui.create_frame(title, self.canvas_width,
                                            self.canvas_height)
        self.frame.set_canvas_background("rgb(28, 17, 23)")
        self.state = "start"

        self.start_screen = StartScreen(self.canvas_width, self.canvas_height)
        self.end_screen = EndScreen(self.canvas_width, self.canvas_height)

        # Player
        self.player = Wizard(
            Vector(self.canvas_width / 2, self.canvas_height / 2))
        self.health = PlayerHealthbar(self.player, (20, 20), (170, 50))
        self.score = Score((self.canvas_width - 150, 40))
        self.floor = 0

        # Interactions
        self.keyboard = Keyboard()
        self.mouse = Mouse((self.canvas_width / 2, self.canvas_height / 2))
        self.player_input = PlayerInputInteraction(self.player, self.keyboard,
                                                   self.mouse)
        self.player_game = None

        # Map Generation
        self.__min_room_size = 256
        self.__max_rooms = 12
        self.__random_rooms = 0.4
        self.map = None
    def __init__(self):
        """
        Initializer to create frame, sets handlers and initialize list of balls to be empty
        """
        self._frame = simplegui.create_frame("Recurrence simulator",
                                            CANVAS_WIDTH, CANVAS_HEIGHT)
        self._frame.set_draw_handler(self.draw)
        self._frame.set_mouseclick_handler(self.click)
        self._frame.set_canvas_background("Blue")

        # add UI to choose recurrence
        self._reduction_label = self._frame.add_label("Recurrence", 200)
        self._frame.add_button("Select number of calls", self.set_child_type, 200)
        self._frame.add_button("Select type of reduction", self.set_reduction_type, 200)
        self._frame.add_button("Select amount of work", self.set_work_type, 200)

        # add label with current recurrence
        self._frame.add_input("Set initial value for n", self.set_capacity, 200)
        self._frame.add_button("Reset simulation", self.reset, 200)

        # initialize state of UI
        self._current_reduction_type = 0
        self._current_child_type = 1
        self._current_work_type = 1
        self.update_recur()

        # initialize UI quantities
        self._total_work = 0
        self._initial_capacity = 16
        self._broom_list = []
        self._frame.start()
        self.reset()
Exemple #3
0
 def __init__(self, game):
     self._draw_instruction = False
     self._rows = game.get_grid_height()
     self._cols = game.get_grid_width()
     self._frame = simplegui.create_frame(
         '2048', self._cols * TILE_SIZE + 2 * BORDER_SIZE,
         self._rows * TILE_SIZE + 2 * BORDER_SIZE)
     self._frame.add_button('New Game', self.start, 100)
     for labels in range(20):
         self._frame.add_label("", 200)
     self._button = self._frame.add_button("How to Play", self.instruction,
                                           100)
     self._frame.set_keydown_handler(self.keydown)
     self._frame.set_draw_handler(self.draw)
     self._frame.set_canvas_background("#BCADA1")
     self._frame.start()
     self._game = game
     url = URL
     self._tiles = simplegui.load_image(url)
     self._directions = {
         "up": UP,
         "down": DOWN,
         "left": LEFT,
         "right": RIGHT
     }
 def __init__(self, tree):
     self._tree = tree
     self.canvas_width, self.canvas_height = self.get_box_size(self._tree)
     self._frame = simplegui.create_frame("Tree Diagram", self.canvas_width, self.canvas_height)
     self._frame.set_canvas_background("White")
     self._frame.set_draw_handler(self.draw)
     self._frame.start()
Exemple #5
0
 def t2048_new_game(self):
     frame = simplegui.create_frame('2048', 420, 460)
     frame.set_canvas_background("White")
     frame.set_draw_handler(draw)
     frame.set_keydown_handler(keydown)
     init()
     frame.start()
Exemple #6
0
 def run(self):
     frame = simplegui.create_frame(self.title, 200, 200, 150)
     self.timer = simplegui.create_timer(100, self.timerhandler)
     frame.set_draw_handler(self.drawhandler)
     button_start = frame.add_button('Start', self.start, 150)
     button_stop = frame.add_button('Stop', self.stop, 150)
     button_clear = frame.add_button('Clear', self.clear, 150)
     frame.start()
Exemple #7
0
def main():
    global currentWorld
    currentWorld = world()
    global path, visited
    path = []
    visited = []
    # generateBenchmark()
    return
    frame = simplegui.create_frame("Heuristic Search", 1280, 960)
    frame.add_button("Generate Map", generateMap, 100)
    frame.add_button("Update Start/Goal", currentWorld.rotateSNGHandler, 100)
    frame.set_draw_handler(draw_handler)
    global inputWeight
    inputWeight = frame.add_input("Weight", input_handler, 50)
    inputWeight.set_text(str(WEIGHT))

    frame.add_label("")
    frame.add_label("Heuristic:")
    frame.add_button("Euclidean", setheuristicE, 100)
    frame.add_button("Manhattan", setheuristicM, 100)
    frame.add_button("Euclidean Squared", setheuristicES, 100)
    frame.add_button("Chebyshev", setheuristicC, 100)
    frame.add_button("Octile", setheuristicO, 100)
    frame.add_button("Mini Manhattan", setheuristicMM, 100)

    frame.add_label("")
    frame.add_label("Search Algorithm:")
    frame.add_button("UCS", ucsSolve, 100)
    frame.add_button("A*", aStarSolve, 100)
    frame.add_button("Weighted A*", weightedAStarSolve, 100)
    frame.add_button("Sequential A*", sequentialAStarSolve, 100)

    frame.add_label("")
    global algo, heur, status, visitedCells, pathLen
    algo = frame.add_label("Current Algorithm: N/A")
    heur = frame.add_label("Current Heuristic: N/A")
    status = frame.add_label("Current Status: N/A")
    visitedCells = frame.add_label("# of Visited Cells: N/A")
    pathLen = frame.add_label("Length of Path: N/A")

    frame.add_label("")
    frame.add_label("Key:")
    frame.add_label("Green = Start")
    frame.add_label("Red = Goal")
    frame.add_label("White = Unblocked")
    frame.add_label("Black = Blocked")
    frame.add_label("Gray = Hard to Traverse")
    frame.add_label("Light Blue = Unblocked Highway")
    frame.add_label("Blue = Hard Traverse Highway")
    frame.add_label("Light Green = Visited")
    frame.add_label("Green = Path")

    frame.add_label("")
    frame.add_button("Save Map", currentWorld.saveCurrentMap, 100)
    frame.add_button("Load Map", currentWorld.callLoad, 100)
    frame.add_button("Wipe Path", wipePath, 100)

    frame.start()
def play_rps():
    frame = simplegui.create_frame("Home", 300, 200)
    frame.add_button("Rock", rock)
    frame.add_button("Paper", paper)
    frame.add_button("Scissors", scissors)
    frame.set_draw_handler(draw)

    # Start the frame animation
    frame.start()
Exemple #9
0
 def __init__(self, tree):
     """ Create GUI """
     self._tree = tree
     self._canvas_width, self._canvas_height = self.get_box_size(tree)
     self._frame = simplegui.create_frame("Draw a tree", self._canvas_width,
                                          self._canvas_height)
     self._frame.set_canvas_background("White")
     self._frame.set_draw_handler(self.draw)
     self._frame.start()
 def __init__(self, tree):
     """
     Create GUI
     """
     self._tree = tree
     self._canvas_width, self._canvas_height = self.get_box_size(tree)
     self._frame = simplegui.create_frame("Draw a tree", self._canvas_width, self._canvas_height)
     self._frame.set_canvas_background("White")
     self._frame.set_draw_handler(self.draw)
     self._frame.start()
Exemple #11
0
 def StartGame(self) -> None:
     """Initialises the game."""
     self.frame = simplegui.create_frame('Drawing', CANVAS_WIDTH,
                                         CANVAS_HEIGHT)
     self.frame.set_draw_handler(self.Draw)
     self.frame.set_keydown_handler(self.KeyDown)
     self.frame.set_keyup_handler(self.KeyUp)
     self.timer = simplegui.create_timer(1000, self.Tick)
     #self.timer.start()
     self.frame.start()
Exemple #12
0
def run_gui(): 
    """
    Create a frame and assign draw handler
    """
    frame = simplegui.create_frame("Indexed grid", CANVAS_WIDTH, CANVAS_HEIGHT)
    frame.set_canvas_background("White")
    frame.set_draw_handler(draw)
    
    # Start the frame animation
    frame.start()
Exemple #13
0
    def setup_frame(self):
        """ Create GUI frame and add handlers. """
        self._frame = simplegui.create_frame("Tic-Tac-Toe", GUI_WIDTH,
                                             GUI_HEIGHT)
        self._frame.set_canvas_background('White')

        # Set handlers
        self._frame.set_draw_handler(self.draw)
        self._frame.set_mouseclick_handler(self.click)
        self._frame.add_button("New Game", self.newgame)
        self._label = self._frame.add_label("")
Exemple #14
0
 def __init__(self):
     """ 
     Initializer to create frame, sets handlers and initialize list of balls to be empty
     """
     self.simulation = Simulation()
     self._frame = simplegui.create_frame("ball/ball collision simulator",
                                          CANVAS_WIDTH, CANVAS_HEIGHT)
     self._frame.set_draw_handler(self.draw)
     self._frame.set_mouseclick_handler(self.click)
     self._prev_time = time.time()
     self._frame_rate = 60.0
Exemple #15
0
    def __init__(self):

        #Boiler Plate Loading and setting of Variables
        self.__location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        self.fcat = os.path.join(self.__location__,
                                 'images/sprites/catmandoRight.png')
        self.fcatleft = os.path.join(self.__location__,
                                     'images/sprites/catmandoLeft.png')
        self.fman = os.path.join(self.__location__,
                                 'images/sprites/kramer_sprites.png')
        self.fmanleft = os.path.join(self.__location__,
                                     'images/sprites/kramer_sprites_left.png')
        self.fwiz = os.path.join(self.__location__,
                                 'images/sprites/wizzardRight.png')
        self.fwizleft = os.path.join(self.__location__,
                                     'images/sprites/wizzardLeft.png')
        self.lives = os.path.join(self.__location__, 'images/lives.png')
        self.error = os.path.join(self.__location__,
                                  'images/sprites/error.png')
        self.load = os.path.join(self.__location__, 'images/loading.png')
        self.loading = simplegui._load_local_image(self.load)
        self.back = os.path.join(self.__location__,
                                 'images/1280x720GameBackground.png')
        self.background = simplegui._load_local_image(self.back)
        self.level = 0
        self.player = Player(self.fcat, self.fcatleft, 16, 16)
        self.keyboard = KeyBoard()
        self.enemies = []
        self.gui = Gui(self.lives, self.lives, 1, 1, self.player)
        self.counter = 0
        self.gameOver = False

        # Load from correct directories to work on all systems.
        __location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        soundeffect = os.path.join(__location__,
                                   'Sounds/bensound-jazzyfrenchy.ogg')
        self.music1 = simplegui._load_local_sound(soundeffect)

        soundeffect = os.path.join(__location__,
                                   'Sounds/bensound-theelevatorbossanova.ogg')
        self.music2 = simplegui._load_local_sound(soundeffect)

        soundeffect = os.path.join(
            __location__, 'Sounds/Captive_Portal_-_03_-_An_Example_For.ogg')
        self.music3 = simplegui._load_local_sound(soundeffect)

        self.interaction = Interaction(self.player, self.keyboard,
                                       self.enemies, self.gui)
        self.frame = simplegui.create_frame("Catmando", WIDTH, HEIGHT)
        self.frame.set_draw_handler(self.draw)
        self.frame.set_keydown_handler(self.keyboard.keyDown)
        self.frame.set_keyup_handler(self.keyboard.keyUp)
Exemple #16
0
def main():
    vec1 = Vector(1, 1)
    print(vec1)
    print(vec1.magnitude())
    print(vec1.norm())
    print(vec1.norm().magnitude())
    vec2 = Vector(-1, -1)
    print(vec1 + vec2)
    vec1.scalar_mul(5)
    print(vec1)
    frame = simplegui.create_frame('this frame', 400, 400)
    frame.start()
Exemple #17
0
def main():
    global time, color
    time = 0
    color = 'white'
    frame = simplegui.create_frame('My Timer', 200, 200, 100)
    global timer
    timer = simplegui.create_timer(1, timerHandler)
    frame.set_draw_handler(draw)
    frame.add_button('Start', Start, 100)
    frame.add_button('Stop', Stop, 100)
    frame.add_button('Clear', Clear, 100)
    frame.start()
Exemple #18
0
def main():
    pass
    # create frame
    frame = simplegui.create_frame("Pong", CANVA_WIDTH, CANVA_HEIGHT)
    # register event handlers
    frame.set_draw_handler(draw)
    frame.set_keydown_handler(keydown)
    frame.set_keyup_handler(keyup)
    # add restart button
    frame.add_button("Restart", init, 100)
    # start frame
    frame.start()
Exemple #19
0
def main():
    global t, color
    t = 0
    color = 'white'
    frame = simplegui.create_frame('Timer', 200, 200, 150)
    # 1000 / 100 = 10, 即t自加10次为一秒
    global timer
    timer = simplegui.create_timer(100, timerHandler)
    frame.set_draw_handler(drawHandler)
    button_start = frame.add_button('Start', Start, 150)
    button_stop = frame.add_button('Stop', Stop, 150)
    button_clear = frame.add_button('Clear', Clear, 150)
    frame.start()
 def __init__(self):
     """
     Create a frame and load the cancer data
     """
     self._frame = simplegui.create_frame("Cancer risk visualization", CANVAS_WIDTH, CANVAS_HEIGHT)
     self._frame.set_canvas_background("White")
     self._frame.set_draw_handler(self.draw)
     self._frame.add_input("Enter cutoff (scaled by 0.00001)", self.enter_cutoff, 200)
     self._frame.add_button("Print data table in CSV", self.print_table, 200)
     self._data_table = self.load_data()
     self.enter_cutoff("0.0")
     self._USA_Counties = simplegui.load_image(MAP_URL)
     self._frame.start()
Exemple #21
0
 def setup_frame(self):
     """
     Create GUI frame and add handlers.
     """
     self._frame = simplegui.create_frame("Tic-Tac-Toe",
                                          GUI_WIDTH,
                                          GUI_HEIGHT)
     self._frame.set_canvas_background('White')
     
     # Set handlers
     self._frame.set_draw_handler(self.draw)
     self._frame.set_mouseclick_handler(self.click)
     self._frame.add_button("New Game", self.newgame)
     self._label = self._frame.add_label("")
Exemple #22
0
 def __init__(self):
     """
     Create a frame and load the cancer data
     """
     self._frame = simplegui.create_frame("Cancer risk visualization",
                                          CANVAS_WIDTH, CANVAS_HEIGHT)
     self._frame.set_canvas_background("White")
     self._frame.set_draw_handler(self.draw)
     self._frame.add_input("Enter cutoff (scaled by 0.00001)",
                           self.enter_cutoff, 200)
     self._frame.add_button("Print data table in CSV", self.print_table,
                            200)
     self._data_table = self.load_data()
     self.enter_cutoff("0.0")
     self._USA_Counties = simplegui.load_image(MAP_URL)
     self._frame.start()
Exemple #23
0
 def __init__(self, game):
     """ 
     Create frame and timers, register event handlers
     """
     self.game = game
     self._grid_height = self.game.get_grid_height()
     self._grid_width = self.game.get_grid_width()
     self._frame = simplegui.create_frame("Interactive Game of Life demo",
                                          self._grid_width * CELL_SIZE,
                                          self._grid_height * CELL_SIZE)
     self._frame.set_canvas_background("White")
     self._frame.add_button("Clear all", self.clear, 100)
     self._frame.add_button("Step", self.step, 100)
     self._frame.add_button("Ten steps", self.ten_steps, 100)
     self._frame.set_mousedrag_handler(self.add_cell_index)
     self._frame.set_draw_handler(self.draw)
Exemple #24
0
 def __init__(self, game):
     self._rows = game.get_grid_height()
     self._cols = game.get_grid_width()
     self._frame = simplegui.create_frame('2048',
                     self._cols * TILE_SIZE + 2 * BORDER_SIZE,
                     self._rows * TILE_SIZE + 2 * BORDER_SIZE)
     self._frame.add_button('New Game', self.start)
     self._frame.set_keydown_handler(self.keydown)
     self._frame.set_draw_handler(self.draw)
     self._frame.set_canvas_background("#BCADA1")
     self._frame.start()
     self._game = game
     url = codeskulptor.file2url(IMAGENAME)
     self._tiles = simplegui.load_image(url)
     self._directions = {"up": UP, "down": DOWN,
                         "left": LEFT, "right": RIGHT}
Exemple #25
0
 def __init__(self, game):
     """ 
     Initializer to create frame, sets handlers and initialize game
     """
     self._frame = simplegui.create_frame("Mancala Solitaire", 
                                         CANVAS_SIZE[0], CANVAS_SIZE[1])
     self._frame.set_canvas_background("White")
     self._frame.set_draw_handler(self.draw)
     self._frame.add_button("New board", self.new_board, 200)
     self._frame.add_button("Restart board", self.restart_board, 200)
     self._frame.add_button("Make move", self.make_move, 200)
     self._frame.set_mouseclick_handler(self.click_move)
     
     # fire up game and frame
     self._game = game
     self.new_board()
    def __init__(self, game):
        """ 
        Initializer to create frame, sets handlers and initialize game
        """
        self._frame = simplegui.create_frame("Mancala Solitaire",
                                             CANVAS_SIZE[0], CANVAS_SIZE[1])
        self._frame.set_canvas_background("White")
        self._frame.set_draw_handler(self.draw)
        self._frame.add_button("New board", self.new_board, 200)
        self._frame.add_button("Restart board", self.restart_board, 200)
        self._frame.add_button("Make move", self.make_move, 200)
        self._frame.set_mouseclick_handler(self.click_move)

        # fire up game and frame
        self._game = game
        self.new_board()
Exemple #27
0
    def __init__(self, simulation):
        """ Create frame and timers, register event handlers """
        self._simulation = simulation
        self._grid_height = self._simulation.get_grid_height()
        self._grid_width = self._simulation.get_grid_width()
        self._frame = simplegui.create_frame("Zombie Apocalypse simulation", self._grid_width * CELL_SIZE, self._grid_height * CELL_SIZE)
        self._frame.set_canvas_background("White")
        self._frame.add_button("Clear all", self.clear, 200)
        self._item_type = OBSTACLE

        label = LABEL_STRING + NAME_MAP[self._item_type]
        self._item_label = self._frame.add_button(label, self.toggle_item, 200)
        self._frame.add_button("Humans flee", self.flee, 200)
        self._frame.add_button("Zombies stalk", self.stalk, 200)
        self._frame.set_mouseclick_handler(self.add_item)
        self._frame.set_draw_handler(self.draw)
 def __init__(self, simulation):
     """ 
     Create frame and timers, register event handlers
     """
     self._simulation = simulation
     self._grid_height = self._simulation.get_grid_height()
     self._grid_width = self._simulation.get_grid_width()
     self._frame = simplegui.create_frame("Zombie Apocalypse simulation", 
                                         self._grid_width * CELL_SIZE, self._grid_height * CELL_SIZE)
     self._frame.set_canvas_background("White")
     self._frame.add_button("Clear all", self.clear, 200)
     self._item_type = OBSTACLE
     self._item_label = self._frame.add_button(LABEL_STRING + self._item_type, self.toggle_item, 200)
     self._frame.add_button("Humans flee", self.flee, 200)
     self._frame.add_button("Zombies stalk", self.stalk, 200)
     self._frame.set_mouseclick_handler(self.add_item)
     self._frame.set_draw_handler(self.draw)
Exemple #29
0
 def __init__(self):
     """
     Initialize the simulation
     """
     self._frame = simplegui.create_frame("Monty Hall problem",
                                          CANVAS_WIDTH, CANVAS_HEIGHT,
                                          CONTROL_WIDTH)
     self._frame.set_canvas_background("White")
     self._frame.add_button("Clear", self.clear, CONTROL_WIDTH)
     self._frame.add_button("Add door", self.add_door, CONTROL_WIDTH)
     self._frame.set_mouseclick_handler(self.click)
     self._frame.add_label("")
     self._win_label = self._frame.add_label("Wins = 0")
     self._lose_label = self._frame.add_label("Loses = 0")
     self.clear()
     self._frame.set_draw_handler(self.draw)
     self._frame.start()
Exemple #30
0
    def __init__(self, puzzle):
        """ Create frame and timers, register event handlers """
        self._puzzle = puzzle
        self._puzzle_height = puzzle.get_height()
        self._puzzle_width = puzzle.get_width()

        self._frame = simplegui.create_frame("The Fifteen puzzle",
                                             self._puzzle_width * TILE_SIZE,
                                             self._puzzle_height * TILE_SIZE)
        self._solution = ""
        self._current_moves = ""
        self._frame.add_button("Solve", self.solve, 100)
        self._frame.add_input("Enter moves", self.enter_moves, 100)
        self._frame.add_button("Print moves", self.print_moves, 100)
        self._frame.set_draw_handler(self.draw)
        self._frame.set_keydown_handler(self.keydown)
        self._timer = simplegui.create_timer(250, self.tick)
        self._timer.start()
        self._frame.start()
Exemple #31
0
    def __init__(self, game):
        """ Initialize GUI """
        self._game = game
        self._tiling_size = self._game.get_tiling_size()
        self.init_grid()

        canvas_width = 2 * EDGE_LENGTH + (3 * self._tiling_size * EDGE_LENGTH / 2)
        canvas_height = (self._tiling_size + 1) * HEX_HEIGHT
        self._mouse_drag = False
        self._frame = simplegui.create_frame("Tantrix Solitaire demo", canvas_width, canvas_height)
        self._frame.add_button("Is legal?", self.check_legal, 200)
        self._frame.add_button("Yellow loop of length 10?", self.yellow_loop, 200)
        self._frame.add_button("Red loop of length 10?", self.red_loop, 200)
        self._frame.add_button("Blue loop of length 10?", self.blue_loop, 200)
        self._frame.set_draw_handler(self.draw)
        self._frame.set_canvas_background("White")
        self._frame.set_mouseclick_handler(self.click)
        self._frame.set_mousedrag_handler(self.drag)
        self._frame.start()
    def __init__(self, game):
        """ Create frame and timers, register event handlers """
        self.game = game
        self.frame = simplegui.create_frame("Word Wrangler", CANVAS_WIDTH,
                                            CANVAS_HEIGHT, 250)
        self.frame.set_canvas_background("Blue")

        self.enter_input = self.frame.add_input("Enter word for new game",
                                                self.enter_start_word, 250)
        labelmsg = "Stars correspond to hidden words formed using letters "
        labelmsg += "from the entered word. Hidden words are listed in alphabetical order"
        self.frame.add_label(labelmsg, 250)
        self.frame.add_label("", 250)
        self.guess_label = self.frame.add_input("Enter a word",
                                                self.enter_guess, 250)
        self.frame.add_label("For a hint, click on a starred word", 250)
        self.frame.set_mouseclick_handler(self.peek)
        self.frame.set_draw_handler(self.draw)

        self.enter_input.set_text("python")
        self.game.start_game("python")
    def __init__(self, puzzle):
        """
        Create frame and timers, register event handlers
        """
        self._puzzle = puzzle
        self._puzzle_height = puzzle.get_height()
        self._puzzle_width = puzzle.get_width()

        self._frame = simplegui.create_frame("The Fifteen puzzle",
                                             self._puzzle_width * TILE_SIZE,
                                             self._puzzle_height * TILE_SIZE)
        self._solution = ""
        self._current_moves = ""
        self._frame.add_button("Solve", self.solve, 100)
        self._frame.add_input("Enter moves", self.enter_moves, 100)
        self._frame.add_button("Print moves", self.print_moves, 100)
        self._frame.set_draw_handler(self.draw)
        self._frame.set_keydown_handler(self.keydown)
        self._timer = simplegui.create_timer(250, self.tick)
        self._timer.start()
        self._frame.start()
    def __init__(self, tree: KdTree, canvas_size: list):
        """
        Initializer to create frame, sets handlers and initialize game
        """
        self._frame = simplegui.create_frame("KD tree", canvas_size[0], canvas_size[1])  #
        self._frame.set_canvas_background("White")
        self._frame.set_draw_handler(self.draw)

        self.isLive = False

        self._frame.set_mouseclick_handler(self.click_move)
        self._frame.add_button("Draw", self.is_live, 100)
        self._frame.add_button("Clustered Data", self.clustered_data_new_game, 50)
        self._frame.add_button("Random Data", self.random_data_new_game, 50)
        self._frame.add_button("Restart", self.restart_game, 100)
        self.range_input = self._frame.add_input('Range', self.calculate_number_of_points_in_rect, 100)
        self.nearest_point_input = self._frame.add_input('Nearest Point', self.calculate_nearest_point, 100)
        self.file_path = self._frame.add_input('File Path', self.load_from_file, 100)

        # # fire up game and frame
        self.tree = tree
Exemple #35
0
    def __init__(self, game):
        self._game = game
        self._rows = game.get_grid_height()
        self._cols = game.get_grid_width()
        self._frame = simplegui.create_frame('2048',
                        self._cols * TILE_SIZE + 2 * BORDER_SIZE,
                        self._rows * TILE_SIZE + 2 * BORDER_SIZE)
        self._frame.add_button('New Game', self.start)
        self._frame.set_keydown_handler(self.keydown)
        self._frame.set_draw_handler(self.draw)
        self._frame.set_canvas_background("#BCADA1")
        # url = codeskulptor.file2url(IMAGENAME)
        # url = 'http://commondatastorage.googleapis.com/codeskulptor-assets/' \
        #        + IMAGENAME
        url = 'https://raw.githubusercontent.com/guohengkai/' \
                + 'hw-poc/master/assets/' + IMAGENAME

        self._tiles = simplegui.load_image(url)
        self._directions = {"up": UP, "down": DOWN,
                            "left": LEFT, "right": RIGHT}
        self._frame.start()
Exemple #36
0
    def __init__(self, simulation):
        """
        Create frame and timers, register event handlers
        """
        self._simulation = simulation
        self._grid_height = self._simulation.get_grid_height()
        self._grid_width = self._simulation.get_grid_width()
        self._frame = simplegui.create_frame("Weighted Distance Calculator",
                                             self._grid_width * CELL_SIZE,
                                             self._grid_height * CELL_SIZE)
        self._frame.set_canvas_background("White")
        #self._frame.add_button("Clear all", self.clear, 200)
        self._item_type = ZOMBIE
        global Z_SIDE_LIST_LENGTH
        Z_SIDE_LIST_LENGTH = len(self._simulation.get_z_side_list())
        global Z_SIDE_LIST_INDEX
        Z_SIDE_LIST_INDEX = Z_SIDE_LIST_LENGTH-1

        label = LABEL_STRING + NAME_MAP[self._item_type]
        self._item_label = self._frame.add_button(label,
                                                  self.toggle_item, 200)
        #Some ugly code, consider reworking this.
        #Takes z_side_list from simulation, increments the GUIs index and modulos against the length of the list
        z_label = "Set Z to " + self._simulation.get_z_side_list()[(Z_SIDE_LIST_INDEX+1) % Z_SIDE_LIST_LENGTH]
        self._z_button_label = self._frame.add_button(z_label, self.toggle_z_side, 200)
        self._frame.add_button("Calculate Length", self.calculate, 200)
        self._frame.add_button("Trace Path", self.stalk, 200)
        self._text_a_hall = self._frame.add_input('A-Hall', self.input_aside_hall, 200)
        self._text_a_cabinet = self._frame.add_input('A-Cabinet', self.input_aside_cabinet, 200)
        self._text_z_hall = self._frame.add_input('Z-Hall', self.input_zside_hall, 200)
        self._text_z_cabinet = self._frame.add_input('Z-Cabinet', self.input_zside_cabinet, 200)
        self._frame.add_button("Input A+Z Sides", self.process_input_a_z_sides, 200)
        self._frame.set_mouseclick_handler(self.add_item)
        self._frame.set_draw_handler(self.draw)
        
        #queue for storing thread results
        self._result_queue = Queue()
        
        #flag to keep track if input is currently being processed
        self._processing_input = False
Exemple #37
0
 def __init__(self, game):
     self._rows = game.get_grid_height()
     self._cols = game.get_grid_width()
     self._frame = simplegui.create_frame(
         '2048', self._cols * TILE_SIZE + 2 * BORDER_SIZE,
         self._rows * TILE_SIZE + 2 * BORDER_SIZE)
     self._frame.add_button('New Game', self.start)
     self._frame.set_keydown_handler(self.keydown)
     self._frame.set_draw_handler(self.draw)
     self._frame.set_canvas_background("#BCADA1")
     #self._frame.start() # this did not work, as the frame disturbed the initialization process while starting
     self._game = game
     #url = codeskulptor.file2url(IMAGENAME) # this is the origial version
     url = 'http://codeskulptor-assets.commondatastorage.googleapis.com/assets_2048.png'
     self._tiles = simplegui.load_image(url)
     self._directions = {
         "up": UP,
         "down": DOWN,
         "left": LEFT,
         "right": RIGHT
     }
     self._frame.start()
    def __init__(self, game):
        """ 
        Create frame and timers, register event handlers
        """
        self.game = game
        self.frame = simplegui.create_frame("Word Wrangler", 
                                            CANVAS_WIDTH, CANVAS_HEIGHT, 250)
        self.frame.set_canvas_background("Blue")        
               
        self.enter_input = self.frame.add_input("Enter word for new game", 
                                                self.enter_start_word, 250)
        labelmsg = "Stars correspond to hidden words formed using letters "
        labelmsg += "from the entered word. Hidden words are listed in alphabetical order"
        self.frame.add_label(labelmsg, 250)
        self.frame.add_label("", 250)
        self.guess_label = self.frame.add_input("Enter a word", 
                                                self.enter_guess, 250)       
        self.frame.add_label("For a hint, click on a starred word", 250)
        self.frame.set_mouseclick_handler(self.peek)
        self.frame.set_draw_handler(self.draw)

        self.enter_input.set_text("python")
        self.game.start_game("python")
    def __init__(self):
        """
        Initializer to create frame, sets handlers and initialize list of balls to be empty
        """
        self._frame = simplegui.create_frame("Recurrence simulator",
                                             CANVAS_WIDTH, CANVAS_HEIGHT)
        self._frame.set_draw_handler(self.draw)
        self._frame.set_mouseclick_handler(self.click)
        self._frame.set_canvas_background("Blue")

        # add UI to choose recurrence
        self._reduction_label = self._frame.add_label("Recurrence", 200)
        self._frame.add_button("Select number of calls", self.set_child_type,
                               200)
        self._frame.add_button("Select type of reduction",
                               self.set_reduction_type, 200)
        self._frame.add_button("Select amount of work", self.set_work_type,
                               200)

        # add label with current recurrence
        self._frame.add_input("Set initial value for n", self.set_capacity,
                              200)
        self._frame.add_button("Reset simulation", self.reset, 200)

        # initialize state of UI
        self._current_reduction_type = 0
        self._current_child_type = 1
        self._current_work_type = 1
        self.update_recur()

        # initialize UI quantities
        self._total_work = 0
        self._initial_capacity = 16
        self._broom_list = []
        self._frame.start()
        self.reset()
        paddle2_vel[1] -=acc
    if key ==simplegui.KEY_MAP["right"]:
        paddle2_vel[1] =0


#复位函数
def restart():
    global width,height,ball_pos,paddle1_pos,paddle2_pos,score1,score2,half_pad_width
    global half_pad_height,ball_radius
    ball_pos=[width/2,height/2]
    score1=0
    score2=0
    new_game()
#注册函数

f = simplegui.create_frame("Pong",width,height)

f.set_draw_handler(draw)

f.set_keydown_handler(keydown)

f.set_keyup_handler(keyup)

f.add_button("Restart",restart,100)





#start frame
new_game()
# -*- coding: utf-8 -*-

# keyboard echo
from SimpleGUICS2Pygame import simpleguics2pygame as simplegui

# initialize state
current_key = ' '

# event handlers
def key_down(key):
    global current_key
    current_key = chr(key)

def key_up(key):
    global current_key
    current_key = 'UP'

def draw(canvas):
    canvas.draw_text(current_key, [20, 30], 15, "White")

# create a frame
frame = simplegui.create_frame("echo", 50, 50)

# register event handlers
frame.set_keydown_handler(key_down)
frame.set_keyup_handler(key_up)
frame.set_draw_handler(draw)

# start frame
frame.start()
        print ""
        new_game()
    else:
        if secret_number > guess_number:
            print "Higher!"
            print ""
        else:
            print "Lower!"
            print ""

        if times == 0:
            print "You ran out of guesses. The number is ", secret_number
            print ""
            new_game()

# create frame
frame = simplegui.create_frame("Guess the number", 200,200)

# register event handlers for control elements
# create control element for window
frame.add_button("Range is [0, 100)", range100, 200)
frame.add_button("Range is [0, 1000)", range1000, 200)
frame.add_input("Enter a guess", get_input, 200)

new_game()

# start frame
frame.start()

# always remenber to check your completed program against
Exemple #43
0
			turns += 1
			state = 1
		else:
			pass


def draw(canvas):
	a = 0
	l.set_text("Turns = %s" % turns)
	if len(seen) != 16:
		for num in cards:
			canvas.draw_text(str(num), [5 + 50 * a, 78], 80, "White")
			a += 1
		for n in unsee:
			if n not in seen and n not in exposed:
				canvas.draw_polygon([[50 * n, 0], [50 * (n + 1), 0], [50 * (n + 1), 100], [50 * n, 100]], 2,
						    line_color="Blue", fill_color="Blue")
			canvas.draw_line([50 * (n + 1), 0], [50 * (n + 1), 100], line_width=5, line_color="Black")
	else:
		canvas.draw_text("You Win! Score: %s" % (turns-1), [100, 78], 80, "White")


frame = game.create_frame("Memory", 800, 100)
frame.add_button("Restart", new_game, 200)
l = frame.add_label("Turns = %s" % turns)

frame.set_mouseclick_handler(mouseclick)
frame.set_draw_handler(draw)

new_game()
frame.start()
    x = (birds[0].bird_pos[0] + (RADIUS * (math.cos(math.radians(45)))))
    y = (birds[0].bird_pos[1] + (RADIUS * (math.sin(math.radians(45)))))
    new_pos = [x,y]    
    
    
def updateCBottomLeft():
    global new_pos
    x = (birds[0].bird_pos[0] - (RADIUS * (math.cos(math.radians(45)))))
    y = (birds[0].bird_pos[1] + (RADIUS * (math.sin(math.radians(45)))))
    new_pos = [x,y]


    

    
frame=simplegui.create_frame("Birds Formation Simulation",WIDTH,HEIGHT)

frame.set_mouseclick_handler(mouseclick)
frame.set_draw_handler(draw_handler)

labelA = frame.add_label('Formation Control')
button1 = frame.add_button('Circle Formation', button_handler_c)
label1 = frame.add_label(' ')
button2 = frame.add_button('V Formation', button_handler_v)
label2 = frame.add_label(' ')
label3 = frame.add_label(' ')
label4 = frame.add_label(' ')
labelA = frame.add_label('Circle Diameter Control')
buttonA = frame.add_button('+', button_cplus, 25)
label5 = frame.add_label(' ')
buttonB = frame.add_button('-', button_cminus, 25)
current_key = ''

#事件处理函数

def keydown(key):
    global current_key
    current_key = chr(key)



def keyup(key):
    global current_key
    current_key = chr(key)

def  draw(canvas):
    canvas.draw_text(current_key,[10,25],20,"Green")

#注册事件


f = simplegui.create_frame("Echo",35,35)

f.set_keydown_handler(keydown)

f.set_keyup_handler(keyup)

f.set_draw_handler(draw)


f.start()
Exemple #46
0
        return 3 * bet
    else:
        return 2 * bet


def print_values():
    """ prints the game values to the console """
    print("Player hand:", str(player), "value", str(player.get_value()))
    print("Dealer:", str(dealer), "value", str(dealer.get_value()))
    print("Balance:", str(balance), "Bet:", str(bet), "Score:", str(score))
    if not in_play:
        print("Outcome:", outcome)
    print("")

# initialization frame
frame = simplegui.create_frame("Blackjack", BG_SIZE[0], BG_SIZE[1])
frame.set_canvas_background("Green")

#create buttons, labels, input and canvas callback
frame.add_button("Deal", deal, 200)
frame.add_button("Hit",  hit, 200)
frame.add_button("Stand", stand, 200)
frame.add_label("")
frame.add_label("Select deck:")
frame.add_button("Standard", standard, 100)
frame.add_button("Fancy", fancy, 100)
frame.add_label("")
bet_input = frame.add_input("Enter your bet:", set_bet, 100)
bet_input.set_text(str(temp_bet))
frame.add_label("(changed on the next deal)")
frame.add_label("")
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

message = "Welcome!"

# Handler for button click
def click():
    global message
    message = "Good job!"

# Handler to draw on canvas
def draw(canvas):
    canvas.draw_text(message, [50,112], 48, "Red")

# Create a frame and assign callbacks to event handlers
frame = simplegui.create_frame("Home", 300, 200)

frame.set_canvas_background('#00FFFF')
frame.add_button("Click me", click)
frame.set_draw_handler(draw)

# Start the frame animation
frame.start()
def draw(canvas):
    
    canvas.draw_text("Blackjack",[30,100],40,"Red");
    canvas.draw_text("Score "+str(score),[400,100],30,"Red");
    dealer.draw(canvas,[30,200]);
    if in_play:
        message="Hit or Stand?";
    else:
        message="New Deal?"
    canvas.draw_text(message,[30,350],30,"Red");
    player.draw(canvas,[30,400])    
    canvas.draw_text("Player",[30,550],30,"Red");
    canvas.draw_text("Dealer",[30,180],30,"Red");


frame = simplegui.create_frame("Blackjack", 800, 600)
frame.set_canvas_background("Green")


frame.add_button("Deal", deal, 200)
frame.add_button("Hit",  hit, 200)
frame.add_button("Stand", stand, 200)
frame.set_draw_handler(draw)




frame.start();

deck=Deck();
player=Hand("Player");
    try:
        brush_size = float(inp)
        size_abs = math.fabs(brush_size)
        test_positive = 1 / (1 + brush_size / size_abs)
        size_msg = str(brush_size)
    except (ValueError, ZeroDivisionError):
        size_msg = 'Pleas input a positive number.'
    
    
def brush_of_painter(pos):
    
    global brush_shape, brush_size
    
    if ((brush_shape in ['t', 'r', 'c']) and (brush_size > 0)):
        t = Traces(pos, brush_shape, brush_size)
        history_draw.append(t)
    
        
frame = simplegui.create_frame(title, canvas_width,
                               canvas_height, control_width)
frame.set_draw_handler(draw)
shape_label = frame.add_label(shape_msg)
size_label = frame.add_label(size_msg)
frame.add_label('Input t to select brush with TRIANGLE')
frame.add_label('Input r to select brush with RECTANGLE')
frame.add_input('Input c to select brush with CIRCLE', shape_choice, 110)
frame.add_input('Size:(input a number here) ', size_choice, 110)
#frame.add_input('Color_1:(input an integer here) ', size_choice, 110)
frame.set_mouseclick_handler(brush_of_painter)
frame.start()
CANVAS_WIDTH = 400
CANVAS_HEIGHT = 300


def draw(canvas):
    """
    Draw a simple text.

    :param canvas: simplegui.Canvas
    """
    text = "Canvas"

    font_size = 40
    text_width = frame.get_canvas_textwidth(text, font_size)

    canvas.draw_text(text, ((CANVAS_WIDTH - text_width) // 2, CANVAS_HEIGHT // 2 + font_size // 4), font_size, "Green")


# Main
frame = simplegui.create_frame("Title", CANVAS_WIDTH, CANVAS_HEIGHT)

frame.add_label("Control Panel")

frame.add_label("")
frame.add_button("Quit", frame.stop)

frame.set_draw_handler(draw)

frame.start()
__author__ = 'Pri'

import SimpleGUICS2Pygame.simpleguics2pygame as simplegui


# define draw handler
def draw(canvas):
    canvas.draw_circle([90, 200], 20, 10, "White")
    canvas.draw_circle([210, 200], 20, 10, "White")
    canvas.draw_line((50, 180), (250, 180), 40, "Red")
    canvas.draw_line((55, 170), (90, 120), 5, "Red")
    canvas.draw_line((90, 120), (130, 120), 5, "Red")
    canvas.draw_line((180, 108), (180, 160), 140, "Red")
    canvas.draw_line((200, 0), (0, 300), 10, "Green")

# create frame
frame = simplegui.create_frame("Text drawing", 200, 300)

# register draw handler
frame.set_draw_handler(draw)



# start frame
frame.start()
        store = float(store / operand)
        output()
    else :
        print "DividByZero!"

def remainder():
    global store, operand
    if (operand != 0 and isinstance(store, int) and isinstance(operand, int)):
        store = store % operand
        output()
    else :
        print "is not integer!"

def enter(input_str):
    global operand
    operand = float(input_str)
    output()

frame = simplegui.create_frame("Calculator", 200, 400)

frame.add_button("Print", output, 100)
frame.add_button("Swap", swap, 100)
frame.add_button("Add", add, 100)
frame.add_button("Sub", sub, 100)
frame.add_button("Multiple",multiple, 100)
frame.add_button("Divid", divid, 100)
frame.add_button("Remainder", remainder, 100)

frame.add_input("Enter operand", enter, 100)

frame.start()
    
def remove_num(task_num):
    n = int (task_num)
    if n > 0 and n <=len(takes):
        takes.pop(n-1)
    print takes
    
def remove(task_list):
    list2 = str(task_list)
    if list2 in takes:
        takes.remove(list2)
    print takes

def clear():
    global takes
    takes = []

def draw(canvas):
    global takes
    canvas.draw_text(str(takes[0:len(takes)]),(20,80),40,"blue")#显示和坐标不确定?


frame = simplegui.create_frame("List",width,height)
frame.add_input("new",new,200)
frame.add_input("remove_num",remove_num,200)
frame.add_input("remove",remove,200)
frame.set_draw_handler(draw)
frame.add_button("Clear",clear,200)

frame.start()
Exemple #54
0
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
import random
import math
import time


frame = simplegui.create_frame("Home", 600,600)
canvas_width = 600
canvas_height = 600
ball_pos = []
ball_vel = []
ball_radius = 20
inner_track_radius = 150
outer_track_radius = 280
num_laps = 0
high_score = 0
over_half = False


def distance(pos1, pos2):
    return math.sqrt((pos1[0] - pos2[0]) ** 2 + (pos1[1] - pos2[1]) ** 2)

        
def draw(canvas):
    global over_half, num_laps, high_score
    mid = [canvas_width / 2, canvas_height / 2]
    
    canvas.draw_circle(mid, outer_track_radius, 1, "Aqua", "Black")
    canvas.draw_circle(mid, inner_track_radius, 1, "Aqua", "Green")
    canvas.draw_line((mid[0], mid[1] - inner_track_radius), (mid[0], mid[1] - outer_track_radius), 5, "White")
    canvas.draw_line((mid[0], mid[1] + inner_track_radius), (mid[0], mid[1] + outer_track_radius), 1, "White")
Exemple #55
0
    global rock_group, started
    if len(rock_group) > 12 or not started:
        return
    rock_vel = [random.random() * .6 - .3, random.random() * .6 - .3]
    rock_avel = random.random() * .2 - .1
    rock_pos = [random.randrange(0, WIDTH), random.randrange(0, HEIGHT)]
    # ensure rock_pos is at least 100px away of my_ship
    while dist(rock_pos, my_ship.pos) < 100:
        rock_pos = [random.randrange(0, WIDTH), random.randrange(0, HEIGHT)]
    # add rock to the group
    rock_group.add(Sprite(rock_pos, rock_vel, 0, rock_avel,
                          asteroid_image, asteroid_info))
 
 
# initialize stuff
frame = simplegui.create_frame("Asteroids", WIDTH, HEIGHT)
 
# initialize ship and two sprites
my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0, ship_image, ship_info)
rock_group = set()
missile_group = set()
explosion_group = set()
 
 
# register handlers
frame.set_keyup_handler(keyup)
frame.set_keydown_handler(keydown)
frame.set_mouseclick_handler(click)
frame.set_draw_handler(draw)
 
timer = simplegui.create_timer(1000.0, rock_spawner)
Exemple #56
0
def my_print(msg):
    label.set_text(msg)

def compare_print(msg):
    label_result.set_text(msg)
    
# global variable
limit_step = 0
secret_number = 0

# rang num
RANGE100 = 'range100'
RANGE1000 = 'range1000'

# create frame
f = simplegui.create_frame("猜数游戏 by free", 200, 500)

# register event handlers for control elements and start frame
f.add_input("Enter Num:\n", input_guess, 200)
f.add_button("range [0,100)", range100, 200)
f.add_button("range [0,1000)", range1000, 200)

label = f.add_label("left times")
label_result = f.add_label('compare result')

# init game
range_default()

f.start() 

    global millis;
    millis +=1;
    
    
def draw_handler(canvas):
    canvas.draw_text(format_time(millis), (300,265), 150, "White");
    canvas.draw_text("W/A", (770,100), 50, "Red");
    canvas.draw_text("Score: "+str(wins)+"/"+str(attempts),(650,50),50,"Red");
    canvas.draw_text("Stopwatch Game", (10,40), 50, "Blue");
    canvas.draw_text("W--> No. of Wins", (10,360), 30, "Red");
    canvas.draw_text("A--> No. of Attempts", (10,390), 30, "Red");
    canvas.draw_text("m m    s    s       ms", (300,115), 50, "Red");
    canvas.draw_text("____   ____      ___", (300,115), 50, "Red");
    canvas.draw_line([300, 280], [680, 280], 5, 'Green');
    canvas.draw_line([300, 280], [300, 150], 5, 'Green');
    canvas.draw_line([300, 150], [680, 150], 5, 'Green');
    canvas.draw_line([680, 150], [680, 280], 5, 'Green');
    canvas.draw_text("A--> No. of Attempts", (10,390), 30, "Red");
    canvas.draw_text("*Try to stop it at 0 ms", (610,390), 30, "Pink");
frame=simplegui.create_frame("stopwatch",900,400);


frame.add_button("Start / Stop",start_timer,150);
frame.add_button("  Reset  ",reset_timer,150);
timer = simplegui.create_timer(100, timer_handler);
frame.set_draw_handler(draw_handler);


frame.start();

Exemple #58
0
    elif not inrangetop1:
        paddle1_pos+=10
    else:
        paddle1_pos-=10
        
    if inrangetop2 and inrangebot2:
        paddle2_pos+=paddle2_vel
    elif not inrangetop2:
        paddle2_pos+=10
    else:
        paddle2_pos-=10
    if ball_vel[0]>0:
        ball_vel[0]+=0.002
    else:
        ball_vel[0]-=0.002
        
# create frame
frame = simplegui.create_frame("Pong", WIDTH, HEIGHT)
frame.set_canvas_background("blue")
frame.set_draw_handler(draw)
frame.set_keydown_handler(keydown)
frame.set_keyup_handler(keyup)
frame.add_button("Restart game",restart,100)
frame.add_label("CONTROLS: PLAYER1 : w s \nPLAYER2: up down")
timer=simplegui.create_timer(1,tick)

timer.start()
# start frame
new_game()
frame.start()