예제 #1
0
def click():
    while True:
        stddraw.show(0)
        if stddraw.mousePressed():
            mx1 = stddraw.mouseX()
            my1 = stddraw.mouseY()
            return [mx1, my1]
예제 #2
0
def select_second(game_array_select):
    global turns
    global moves
    row1 = first_position[0]
    column1 = first_position[1]
    if turns == 2:
        turns = 1
        x = stddraw.mouseX()
        y = stddraw.mouseY()
        for i in range(9):
            for j in range(7):
                if x > j and x < j + 1 and y > i and y < i + 1:
                    if i == row1 and j == column1:
                        stddraw.setPenColor(stddraw.WHITE)
                        stddraw.square(first_position[1] + 0.5,
                                       first_position[0] + 0.5, 0.5)
                        juweimodule.draw_new_things(game_board, score)
                    else:
                        if i == row1 and j != column1:
                            if j - 1 == column1 or j + 1 == column1:
                                swap = game_board[i][j]
                                game_board[i][j] = game_board[row1][column1]
                                game_board[row1][column1] = swap
                                scan_for_same()
                                if display() == 1:
                                    moves -= 1
                                    juweimodule.draw_new_things(
                                        game_board, score)
                                else:
                                    swap = game_board[i][j]
                                    game_board[i][j] = game_board[row1][
                                        column1]
                                    game_board[row1][column1] = swap
                                    reminding_not_matching()

                            else:
                                reminding_faulse_move()

                        elif j == first_position[1] and i != first_position[0]:
                            if i - 1 == row1 or i + 1 == row1:
                                swap = game_board[i][j]
                                game_board[i][j] = game_board[row1][column1]
                                game_board[row1][column1] = swap
                                scan_for_same()
                                if display() == 1:
                                    moves -= 1
                                    juweimodule.draw_new_things(
                                        game_board, score)
                                else:
                                    swap = game_board[i][j]
                                    game_board[i][j] = game_board[row1][
                                        column1]
                                    game_board[row1][column1] = swap
                                    reminding_not_matching()
                            else:
                                reminding_faulse_move()
                        else:
                            reminding_faulse_move()

    return game_array_select
예제 #3
0
def player_one_draw(game_array_in_def):
    x = stddraw.mouseX()
    y = stddraw.mouseY()
    for j in range(3):
        for k in range(3):
            if x >= j and x <= j + 1 and y >= k and y <= k + 1:
                stddraw.circle(j + 0.5, k + 0.5, 0.3)
                game_array_in_def[j][k] = 1

    return game_array_in_def
예제 #4
0
def master_function():
    win = False
    level = 0
    background = 0
    while win == False:
        background += 1
        level += 1
        x = random.randrange(7, 15)
        y = random.randrange(9, 17)
        lent = 0.5
        clicklocal = clicklocation(x, y, lent)
        playing_field = gridmaker(x, y)
        count = 0
        finalscore = (x * y * 10)
        totalscore = 0
        clickcoords = []
        attempts = random.randrange(12, 16)
        for i in range(100):
            temp = connectsearch(playing_field, x, y, totalscore)
            playing_field = temp[0]
            playing_field = gravity(playing_field, x, y)
            playing_field = reset(playing_field, x, y)

        while stddraw.mousePressed() == False:
            display(playing_field, x, y, lent, totalscore, finalscore,
                    clickcoords, clicklocal, attempts, level, background, win)
            temp = connectsearch(playing_field, x, y, totalscore)
            playing_field = temp[0]
            totalscore = temp[1]
            playing_field = gravity(playing_field, x, y)
            playing_field = reset(playing_field, x, y)
            if attempts == 0 or totalscore >= finalscore:
                win = display(playing_field, x, y, lent, totalscore,
                              finalscore, clickcoords, clicklocal, attempts,
                              level, background, win)
                print('AA')
                break
            elif stddraw.mousePressed() == True:
                count += 1
                clickcoords.append(stddraw.mouseX())
                clickcoords.append(stddraw.mouseY())
                if count == 2:
                    playing_field = checker(playing_field, x, y, clickcoords,
                                            clicklocal)
                    test = connectcheck(playing_field, x, y)
                    if test == True:
                        attempts = attempts - 1
                        temp = connectsearch(playing_field, x, y, totalscore)
                        playing_field = temp[0]
                        totalscore = temp[1]
                    if test == False:
                        playing_field = checker(playing_field, x, y,
                                                clickcoords, clicklocal)
                    count = 0
                    clickcoords = []
예제 #5
0
def player_two_draw(game_array_in_def):
    x = stddraw.mouseX()
    y = stddraw.mouseY()
    for j in range(3):
        for k in range(3):
            if x >= j and x <= j + 1 and y >= k and y <= k + 1:
                stddraw.line(j + 0.3, k + 0.7, j + 0.7, k + 0.3)
                stddraw.line(j + 0.3, k + 0.3, j + 0.7, k + 0.7)
                game_array_in_def[j][k] = 2

    return game_array_in_def
예제 #6
0
def select_first(game_array_select):
    global turns
    global moves
    if turns == 1:
        turns = 2
        x = stddraw.mouseX()
        y = stddraw.mouseY()
        for i in range(7):
            for j in range(9):
                if x > i and x < i + 1 and y > j and y < j + 1:
                    stddraw.setPenColor(stddraw.RED)
                    stddraw.square(i + 0.5, j + 0.5, 0.5)
                    game_array_select[j][i] = 1
    return game_array_select
예제 #7
0
def select(score, time):
    while True: 
        stddraw.show(100) #pause for .1 second
        drawTop(score, time) #draw this each time to update time

        if time != 9999:
            time += .1
            if checkScoreTime(time): #if times out then stop waiting for input
                return [0,0], score, time

        if stddraw.mousePressed() and stddraw.mouseY() < 9: #you press on the board
            mx = stddraw.mouseX()
            my = stddraw.mouseY()
            return [int(mx), int(my)], score, time
예제 #8
0
def main_menu_click():
    global Clicked
    while not Clicked:
        if stddraw.mousePressed():
            mx = stddraw.mouseX()
            my = stddraw.mouseY()
            # determines where and what to print
            if 446 > mx > 54 and 539 > my > 301:
                stddraw.picture(images.gameBackground,250,400)
                stddraw.picture(images.scoreOverlay,327,725)
                stddraw.setFontSize(25)
                stddraw.setPenColor(color.WHITE)
                stddraw.text(327,725, '0')
                Clicked = True
        stddraw.show(0.0)
예제 #9
0
def getMove(board, columns, rows):
    """
    Returns x and y coordinates where the user has clicked
    """
    while True:

        mouseClicked = sd.mousePressed()
        if mouseClicked:
            x = sd.mouseX()
            y = sd.mouseY()
            for i in range(columns):
                for j in range(rows):
                    if i < x < i + 1 and j < y < j + 1:
                        piece = [i, j]
                        return piece
        sd.show(0.05)
예제 #10
0
def clickToValue():
    row = 9
    col = 9
    while (row == 9 or col == 9):
        waitForClick()
        y = stddraw.mouseY()
        x = stddraw.mouseX()

        if (y < 450 and y > 350):
            row = 0
        elif (y < 350 and y > 250):
            row = 1
        elif (y < 250 and y > 150):
            row = 2
        elif (y < 150 and y > 50):
            row = 3
        elif (y < 50 and y > -50):
            row = 4
        elif (y < -50 and y > -150):
            row = 5
        elif (y < -150 and y > -250):
            row = 6
        elif (y < -250 and y > -350):
            row = 7
        elif (y < -350 and y > -450):
            row = 8
        else:
            row = 9

        if (x < 350 and x > 250):
            col = 6
        elif (x < 250 and x > 150):
            col = 5
        elif (x < 150 and x > 50):
            col = 4
        elif (x < 50 and x > -50):
            col = 3
        elif (x < -50 and x > -150):
            col = 2
        elif (x < -150 and x > -250):
            col = 1
        elif (x < -250 and x > -350):
            col = 0
        else:
            col = 9

    return row, col
예제 #11
0
def display_game_over(grid_height, grid_width):
    background_color = Color(42, 69, 99)
    button_color = Color(25, 255, 228)
    text_color = Color(31, 160, 239)
    # clear the background canvas to background_color
    stddraw.clear(background_color)

    # get the directory in which this python code file is placed
    current_dir = os.path.dirname(os.path.realpath(__file__))
    # path of the image file
    img_file = current_dir + "/menu_image.png"
    # center coordinates to display the image
    img_center_x, img_center_y = (grid_width - 1) / 2, grid_height - 7
    # image is represented using the Picture class
    image_to_display = Picture(img_file)
    # display the image
    stddraw.picture(image_to_display, img_center_x, img_center_y)
    # dimensions of the start game button
    button_w, button_h = grid_width - 1.5, 2
    # coordinates of the bottom left corner of the start game button
    button_blc_x, button_blc_y = img_center_x - button_w / 2, 4
    # display the start game button as a filled rectangle
    stddraw.setPenColor(button_color)
    stddraw.filledRectangle(button_blc_x, button_blc_y, button_w, button_h)
    # display the text on the start game button
    stddraw.setFontFamily("Arial")
    stddraw.setFontSize(25)
    stddraw.setPenColor(text_color)
    text_to_display = "Game Over"
    stddraw.text(img_center_x, 5.5, text_to_display)
    stddraw.text(img_center_x, 4.5, "Score : " + str(grid.total_score))
    # menu interaction loop
    while True:
        # display the menu and wait for a short time (50 ms)
        stddraw.show(50)
        # check if the mouse has been left-clicked
        if stddraw.mousePressed():
            # get the x and y coordinates of the location at which the mouse has
            # most recently been left-clicked
            mouse_x, mouse_y = stddraw.mouseX(), stddraw.mouseY()
            if mouse_x >= button_blc_x and mouse_x <= button_blc_x + button_w:
                if mouse_y >= button_blc_y and mouse_y <= button_blc_y + button_h:
                    return True
예제 #12
0
def click(a):
    click_row = False
    click_row = False
    first_click = False
    while first_click is False:
        stddraw.show(0.0)
        if stddraw.mousePressed():
            mx = stddraw.mouseX()
            my = stddraw.mouseY()
            if 5 < mx < 488 and 5 < my < 635:
                for i in range(9):
                    for j in range(7):
                        if (5 + 70 * j) < mx < (5 + 70 * (j + 1)) and (
                                635 - 70 * i) > my > (635 - 70 * (i + 1)):
                            click_row = i
                            click_column = j

                break

    return click_row, click_column
예제 #13
0
    def check_events(self):
        if stddraw.mousePressed():
            x = stddraw.mouseX()
            y = stddraw.mouseY()
            localized = self._localize_click(x, y)
            if localized:
                avenue = localized[0]
                street = localized[1]
                location = localized[2]
                if constants.NORTH <= location <= constants.WEST:
                    self._toggle_wall(avenue, street, location)
                elif location == TOP:
                    self._toggle_beeper(avenue, street, 1)
                elif location == BOTTOM:
                    self._toggle_beeper(avenue, street, -1)

        if stddraw.hasNextKeyTyped():
            key = stddraw.nextKeyTyped()
            if key == 'p':
                print(self._world)
            elif key == 's':
                with open(self._filename, 'w') as file:
                    file.write(str(self._world))
                print('Saved Karel world to file:', self._filename)
import richardnorman_p2_taffy

game_over = False
first_taffy_selected = False

richardnorman_p2_drawing.draw_score()

first_taffy = richardnorman_p2_taffy.Taffy
second_taffy = richardnorman_p2_taffy.Taffy

while not game_over:
    stddraw.show(350)
    if not first_taffy_selected:
        if stddraw.mousePressed():
            first_taffy = richardnorman_p2_drawing.clicked_handler(
                stddraw.mouseX(), stddraw.mouseY(), True)
            first_taffy_selected = True
    else:
        if stddraw.mousePressed():
            second_taffy = richardnorman_p2_drawing.clicked_handler(
                stddraw.mouseX(), stddraw.mouseY(), False)
            #check if valid swap
            valid_swap = richardnorman_p2_drawing.check_if_valid_swap(
                first_taffy, second_taffy)
            if not valid_swap:
                print(
                    "The taffy swap is not valid, try selecting another taffy")
            else:
                #swap is valid, commence taffy swap
                print("Swapping...")
                richardnorman_p2_drawing.swap(first_taffy, second_taffy)
예제 #15
0
    def Game(self):
        turn = 0
        turnCounter = 15
        turnCondition = True
        key = True
        while turnCondition:
            stddraw.show(0)
            Graphics.drawTurnCounter(turnCounter)
            Graphics.drawWinThing()
            if turn == 0:
                if stddraw.mousePressed():
                    mx = stddraw.mouseX()
                    my = stddraw.mouseY()

                    if mx < 4.69 and my >= 1 and my < 10:
                        Graphics.clickHelp()
                        for i in range(self.x):
                            if mx > i / 1.5 and mx < i / 1.5 + (2 / 3):
                                mDrawX1 = i / 1.5
                                mEmojiX1 = i + 1

                        for i in range(self.y + 1):
                            if my > i and my < i + 1:
                                mDrawY1 = i
                                mEmojiY1 = i + 1 / 2

                        for i in range(self.y):
                            for j in range(self.x):
                                if self.board[i][
                                        j].x == mEmojiX1 and self.board[i][
                                            j].y == mEmojiY1:
                                    e1emoji = self.board[i][j].emoji
                                    e1i, e1j = i, j

                        Graphics.tileSelected(mDrawX1, mDrawY1)
                        turn = 1

            if turn == 1:
                if stddraw.mousePressed():
                    mx = stddraw.mouseX()
                    my = stddraw.mouseY()

                    if mx < 4.69 and my >= 1 and my < 10:

                        for i in range(self.x):
                            if mx > i / 1.5 and mx < i / 1.5 + (2 / 3):
                                mEmojiX2 = i + 1

                        for i in range(self.y + 1):
                            if my > i and my < i + 1:
                                mEmojiY2 = i + 1 / 2

                        for i in range(self.y):
                            for j in range(self.x):
                                if self.board[i][
                                        j].x == mEmojiX2 and self.board[i][
                                            j].y == mEmojiY2:
                                    e2emoji = self.board[i][j].emoji
                                    e2i, e2j = i, j

                        #Swapping the emojis
                        """
                        NOTE THAT THE X POSITIONS ETC HAVE STILL NOT BEEN FIXED
                        11/18/2018 12:14 AM
                        Conversion system new: when x == 1, emoji true position is 1/3, x == 2, 1,
                        x == 3, 5/3
                        """

                        if mEmojiX2 == mEmojiX1 + 1 and mEmojiY2 == mEmojiY1 or mEmojiX2 == mEmojiX1 - 1 and mEmojiY2 == mEmojiY1 or mEmojiY2 == mEmojiY1 + 1 and mEmojiX2 == mEmojiX1 or mEmojiY2 == mEmojiY1 - 1 and mEmojiX2 == mEmojiX1:

                            Graphics.clickHelpClear()
                            self.board[e1i][e1j].emoji = e2emoji
                            self.board[e2i][e2j].emoji = e1emoji

                            counter = 0

                            while test.check(self.board) != 0:
                                self.checkDraw(mDrawX1, mDrawY1)

                                #Erase Vertical
                                if test.getD() == 0:
                                    counter = 0
                                    marker = self.board[test.getY()][
                                        test.getX()].emoji
                                    while marker != 0:
                                        if test.getY() + counter != 9:

                                            if marker == self.board[test.getY(
                                            ) + counter][test.getX()].emoji:
                                                self.board[test.getY() +
                                                           counter][test.getX(
                                                           )].emoji = 0
                                                Score.score += 1
                                                counter += 1
                                            else:
                                                marker = 0
                                        else:
                                            marker = 0

                                    self.checkDraw(mDrawX1, mDrawY1)

                                    #Vertical Drop
                                    count = 0

                                    for j in range(9):
                                        if test.getY() + count + counter < 9:
                                            self.board[
                                                test.getY() + count][test.getX(
                                                )].emoji = self.board[
                                                    test.getY() + count +
                                                    counter][test.getX()].emoji
                                            self.board[
                                                test.getY() + count +
                                                counter][test.getX()].emoji = 0

                                            count += 1

                                    self.checkDraw(mDrawX1, mDrawY1)

                                    temp = 9 - counter

                                    for i in range(counter):
                                        self.board[temp][
                                            test.getX()].emoji = self.ranNum()
                                        temp += 1

                                    self.checkDraw(mDrawX1, mDrawY1)

                                #Erase Horizontal
                                else:
                                    counter = 0
                                    marker = self.board[test.getY()][
                                        test.getX()].emoji
                                    while marker != 0:
                                        if test.getX() + counter != 7:

                                            if marker == self.board[test.getY(
                                            )][test.getX() + counter].emoji:
                                                self.board[test.getY()][
                                                    test.getX() +
                                                    counter].emoji = 0
                                                Score.score += 1
                                                counter += 1
                                            else:
                                                marker = 0
                                        else:
                                            marker = 0

                                    self.checkDraw(mDrawX1, mDrawY1)

                                    #Horizontal Drop
                                    count = 0
                                    for i in range(counter):
                                        count = 0
                                        for j in range(9):
                                            if test.getY() + count < 8:
                                                temp = count + 1
                                                self.board[
                                                    test.getY() + count][
                                                        test.getX() +
                                                        i].emoji = self.board[
                                                            test.getY() +
                                                            temp][test.getX() +
                                                                  i].emoji
                                                self.board[test.getY() +
                                                           temp][test.getX() +
                                                                 i].emoji = 0

                                            count += 1
                                    self.checkDraw(mDrawX1, mDrawY1)

                                    for i in range(counter):
                                        self.board[8][test.getX() +
                                                      i].emoji = self.ranNum()
                                    self.checkDraw(mDrawX1, mDrawY1)

                                turn = 0

                            #For when it is not a match 3
                            if counter == 0:
                                self.board[e1i][e1j].emoji = e1emoji
                                self.board[e2i][e2j].emoji = e2emoji
                                Graphics.clickHelpClear()
                                Graphics.drawInvalidMatch3()
                                Graphics.clearInvalidSwitch()
                                Graphics.tileSelectedClear(mDrawX1, mDrawY1)
                                turn = 0
                            else:
                                turnCounter -= 1

                        #For when you want to select the tile again
                        elif mEmojiX1 == mEmojiX2 and mEmojiY1 == mEmojiY2:
                            Graphics.clickHelpClear()
                            Graphics.tileSelectedClear(mDrawX1, mDrawY1)
                            turn = 0

                        #For when there is an invaid switch
                        else:
                            Graphics.clickHelpClear()
                            Graphics.tileSelectedClear(mDrawX1, mDrawY1)
                            Graphics.drawInvalidSwitch()
                            Graphics.clearInvalidSwitch()
                            turn = 0

                    else:
                        turn = 1

                #Note, mouse does not need to be pressed in order for this CheckWin
                if turnCounter == 0 and Score.score >= 75:
                    Graphics.drawTurnCounter(turnCounter)
                    turnCondition = False
                    while key:
                        Graphics.drawWinCondition()
                        if stddraw.mousePressed():
                            key = False
                elif turnCounter == 0 and Score.score <= 75:
                    Graphics.drawTurnCounter(turnCounter)
                    turnCondition = False
                    while key:
                        Graphics.drawLossCondition()
                        if stddraw.mousePressed():
                            key = False
예제 #16
0
score = 0
update()
no_more_moves()
first_click = True
second_click = True
channel1.play(bgm, loops=-1)
mx1 = 0
my1 = 0
my2 = 0
mx2 = 0
while end == False and score < 700 and number_of_moves > 0:
    combo = -1
    stddraw.show(0.0)
    while first_click:
        stddraw.show(0.0)
        if stddraw.mousePressed() and stddraw.mouseY() < 9 and stddraw.mouseX(
        ) > 0.5 and stddraw.mouseX() < 8.5:
            channel0.play(meow)
            if stddraw.mouseX() < 1.4:
                mx1 = 0
            elif stddraw.mouseX() < 2.289:
                mx1 = 1
            elif stddraw.mouseX() < 3.17777:
                mx1 = 2
            elif stddraw.mouseX() < 4.0666:
                mx1 = 3
            elif stddraw.mouseX() < 4.9555:
                mx1 = 4
            elif stddraw.mouseX() < 5.8444:
                mx1 = 5
            elif stddraw.mouseX() < 6.7333:
                mx1 = 6
예제 #17
0
def mouse_coordinates():
    mx = stddraw.mouseX()
    my = stddraw.mouseY()
    return mx, my
        #diagonal from bottom left to top right has all X
        game_won = True
    if global_variables_p1.marker_array [2][0] == 2 and global_variables_p1.marker_array [1][1] == 2 and global_variables_p1.marker_array [0][2] == 2:
        #diagonal from bottom left to top right has all O
        game_won = True

    if game_won:
        richardnorman_p1_drawing.draw_win(turn_number)

global_variables_p1.init()

turn_number = 1
richardnorman_p1_drawing.draw_board()
game_won = False

richardnorman_p1_drawing.draw_turn(turn_number)

while not game_won:
    if stddraw.mousePressed():
        valid_placement = richardnorman_p1_drawing.draw_piece(stddraw.mouseX(),stddraw.mouseY(),turn_number)
        if not valid_placement:
            continue
        check_if_player_won(turn_number)
        if game_won:
            break
        is_tie = check_if_tie()
        if is_tie:
            break
        turn_number += 1
        richardnorman_p1_drawing.draw_turn(turn_number)
    stddraw.show(0.0)
예제 #19
0
count = 1
stddraw.setFontSize(20)

stddraw.setPenColor(stddraw.BLACK)
stddraw.text(-0.8, 0.9, " Player 1 : O")
stddraw.text(-0.8, 0.8, " Player 2 : X")

stddraw.setPenColor(stddraw.WHITE)

array = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

while key:

    if stddraw.mousePressed():

        mx = stddraw.mouseX()
        my = stddraw.mouseY()
        stddraw.setFontSize(28)
        stddraw.setPenColor(stddraw.WHITE)
        stddraw.filledRectangle(0.0, 0.7, 0.9, 0.2)

        if count % 2 == 0:

            stddraw.setPenColor(stddraw.BLACK)
            if x == 1 or x == 2:
                stddraw.text(0.5, 0.8, " GAME OVER")
            stddraw.text(0.5, 0.8, " Player 2's Turn")
            stddraw.setFontSize(46)
            stddraw.setPenColor(stddraw.RED)
            #B1
            if (mx < -0.2 and mx > -0.6):
예제 #20
0
turn = 0
selection = 0
click = 0
taffyTangle_logic.fixMatrix()
taffyTangle_draw.setScales()
while True:
    if taffyTangle_logic.SCORE < 100 and taffyTangle_logic.MOVES < 25:
        if turn == 0:
            taffyTangle_draw.instructions()
            stddraw.show(1250)
            turn = 1
        taffyTangle_draw.clear()
        taffyTangle_draw.drawCanvas()
        taffyTangle_draw.showPlayerScore(taffyTangle_logic.SCORE)
        if stddraw.mousePressed():
            x = int(stddraw.mouseX())
            y = int(stddraw.mouseY())
            click += 1
        if click % 2 != 0 and click > 0:
            selection = 0
            taffyTangle_draw.selection(x, y, selection)
        elif click > 0:
            selection = 1
            if taffyTangle_logic.checkIfClickAdjacent(taffyTangle_draw.X,
                                                      taffyTangle_draw.Y, x,
                                                      y):
                taffyTangle_draw.selection(x, y, selection)
                taffyTangle_logic.swap(8 - taffyTangle_draw.Y,
                                       taffyTangle_draw.X, 8 - y, x)
                lmao()
                if taffyTangle_logic.checkIfThree() == False:
예제 #21
0
    print(array)
    draw_blanks()
    stddraw.show(1000)
    fill_holes()
    stddraw.show(1000)
    looking_for_board = False

while not looking_for_board:
    taffydraw.draw_clock(game_start)
    #if time runs out then game ends
    taffydraw.score(score)
    taffydraw.goal()
    if stddraw.mousePressed():
        click *= -1
        if click == -1:
            x = stddraw.mouseX()
            y = stddraw.mouseY()
            #get x and y coords from first mouse click
            if x <= 7:
                taffydraw.box(int(x) + .5, int(y) - .5)
                #draws selection box
                get_index(x, y)
                #gets index of click
        if click == 1:
            #second click
            x2 = int(stddraw.mouseX())
            y2 = int(stddraw.mouseY())
            get_index(x2, y2)
            adjacent = int(abs((x - x2) + (y - y2)))
            yes_a = True
            if adjacent == 1:
예제 #22
0
import tictactoe_draw
import tictactoe_logic
import stddraw

turn = 0
tictactoe_draw.setScales()
while True:
    if not tictactoe_logic.checkIfWon() and turn < 9:
        tictactoe_draw.drawCanvas()
        if stddraw.mousePressed():
            posX = stddraw.mouseX()
            posY = stddraw.mouseY()
            quadrant = tictactoe_logic.checkQuadrant(posX,posY)
            if tictactoe_logic.checkIfQuadrantFilled(quadrant):
                turn += 1
                tictactoe_draw.turnStatement(turn)
            if turn % 2 == 0 and tictactoe_logic.checkIfQuadrantFilled(quadrant):
                tictactoe_draw.drawO(tictactoe_logic.centerX,tictactoe_logic.centerY)
                tictactoe_logic.fillQuadrant(quadrant,'O')
            elif tictactoe_logic.checkIfQuadrantFilled(quadrant):
                tictactoe_draw.drawX(tictactoe_logic.centerX,tictactoe_logic.centerY)
                tictactoe_logic.fillQuadrant(quadrant,'X')

    elif turn >= 9:
        tictactoe_draw.win(tictactoe_logic.winner,turn)
    else:
        tictactoe_draw.win(tictactoe_logic.winner,turn)
    tictactoe_draw.show(10)
예제 #23
0
stddraw.setPenColor(stddraw.DARK_BLUE)
stddraw.text(3.5, 9.5, "How do you")
stddraw.text(3.5, 8.5, "want to play?")

stddraw.filledRectangle(1, 5, 5, 2)
stddraw.filledRectangle(1, 2, 5, 2)

stddraw.setPenColor(stddraw.WHITE)
stddraw.text(3.5, 6, "Timed")
stddraw.text(3.5, 3, "Perfection")

while True: 
    stddraw.show(0.0) #pause for .1 second

    if stddraw.mousePressed():
        if 5 < stddraw.mouseY() < 7 and 1 < stddraw.mouseX() < 6: #Timed
            time = 0
            break
        if 2 < stddraw.mouseY() < 4 and 1 < stddraw.mouseX() < 6: #Perfection
            time = 9999
            break

score = 0
board = generateBoard(time)

gameOver = False
while not gameOver:

    validMove = False
    while not validMove: #wait until you make a possible move
        stddraw.clear()