Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import Tk, Canvas
- from itertools import product
- from Game import game
- import os
- import sqlite3
- import random
- from itertools import product
- #These are the functions I made to delete unwanted screens at given moments
- def delete():
- screen.destroy()
- def delete2():
- screen2.destroy()
- screen3.destroy()
- screen4.destroy()
- def delete3():
- screen10.destroy()
- def delete4():
- screen11.destroy()
- def delete5():
- screen9.destroy()
- def delete6():
- screen13.destroy()
- def delete7():
- screen7.destroy()
- def delete8():
- screen2.destroy()
- screen14.destroy()
- screen7.destroy()
- def back():
- screen2.destroy()
- def logout():
- screen2.destroy()
- screen5.destroy()
- def retry():
- screen6.destroy()
- #This is my main screen menu where all the screens will be created from this one
- def main_screen():
- global screen
- screen = Tk()
- screen.title("Main Menu")
- screen.geometry("300x250")
- Label(text = "Learning Race", bg = "cornflowerblue", width = "300", height = "2", font = ("Comic Sans MS", 15)).pack()
- Label(text = "").pack()
- Button(text = "Log in", height = "2", width = "30", command = login).pack()
- Label(text = "").pack()
- Button(text = "Register", height = "2", width = "30", command = register).pack()
- Label(text = "").pack()
- Button(text = "Quit", height = "1", width = "10", command = delete).pack()
- screen.mainloop()
- #This is the menu where you can choose the type of login student or teacher
- def login():
- global screen2
- screen2 = Toplevel(screen)
- screen2.title("Log in")
- screen2.geometry("300x250")
- Label(screen2, text = "Please select what you want to log in as:").pack()
- Button(screen2, text = "Student", width = 30, height = 2, command = login_student).pack()
- Label(screen2,text = "").pack()
- Button(screen2, text = "Teacher", width = 30, height = 2, command = login_teacher).pack()
- Label(screen2,text = "").pack()
- Button(screen2, text = "Back", width = 10, height = 1, command = back).pack()
- #This is the student log in screen where the user enters the data and is then checked
- def login_student():
- global screen3
- screen3 = Toplevel(screen)
- screen3.title("Log in as a Student")
- screen3.geometry("300x250")
- Label(screen3, text = "Please enter details below to log in as a Student").pack()
- global username_verify
- global password_verify
- username_verify = StringVar()
- password_verify = StringVar()
- global username_entry1
- global password_entry1
- Label(screen3, text = "Username * ").pack()
- username_entry1 = Entry (screen3, textvariable = username_verify)
- username_entry1.pack()
- Label(screen3, text = "").pack()
- Label(screen3, text = "Password * ").pack()
- password_entry1 = Entry(screen3, show="*", textvariable = password_verify)
- password_entry1.pack()
- Label(screen3, text = "").pack()
- Button(screen3, text = "Log in", width = 10, height = 1, command = login_verify).pack()
- #The main menu once you log in as a student
- def session():
- global screen5
- screen5 = Toplevel(screen)
- screen5.title("Game")
- screen5.geometry("400x300")
- Label(screen5, text = "Welcome to the game").pack()
- Label(screen5, text = "").pack()
- Button(screen5, text = "Play", height = "2", width = "30", command = play).pack()
- Label(screen5, text = "").pack()
- Button(screen5, text = "Profile", height = "2", width = "30", command = profile).pack()
- Label(screen5, text = "").pack()
- Button(screen5, text = "Log out", height = "1", width = "10",command = logout).pack()
- #This is the teacher log in screen where the user enters the data and is then checked
- def login_teacher():
- global screen7
- screen7 = Toplevel(screen)
- screen7.title("Log in as a Teacher")
- screen7.geometry("300x250")
- Label(screen7, text = "Please enter details below to log in as a Teacher").pack()
- global username_verify2
- global password_verify2
- username_verify2 = StringVar()
- password_verify2 = StringVar()
- global username_entry2
- global password_entry2
- global code_entry2
- Label(screen7, text = "Username * ").pack()
- username_entry2 = Entry (screen7, textvariable = username_verify2)
- username_entry2.pack()
- Label(screen7, text = "Password * ").pack()
- password_entry2 = Entry(screen7, show="*", textvariable = password_verify2)
- password_entry2.pack()
- Label(screen7, text = "Class Code * ").pack()
- code_entry2 = Entry(screen7)
- code_entry2.pack()
- Label(screen7, text = "").pack()
- Button(screen7, text = "Log in", width = 10, height = 1, command = login_verify2).pack()
- #The main menu once you log in as a teacher
- def session2():
- global screen15
- screen15 = Toplevel(screen)
- screen15.title("Menu")
- screen15.geometry("400x300")
- Label(screen15, text = "Welcome to the teacher area!").pack()
- Label(screen15, text = "").pack()
- Button(screen15, text = "See x ", height = "2", width = "30", command = play).pack()
- Label(screen15, text = "").pack()
- Button(screen15, text = "Profile", height = "2", width = "30", command = profile).pack()
- Label(screen15, text = "").pack()
- Button(screen15, text = "Log out", height = "1", width = "10",command = logout).pack()
- #This the screen is where students can register a new account
- def register():
- global screen1
- screen1 = Toplevel(screen)
- screen1.title("Register")
- screen1.geometry("300x250")
- global username
- global password
- global password1
- global code
- global username_entry
- global password_entry
- global password_entry0
- global code_entry
- username = StringVar()
- password = StringVar()
- password1 = StringVar()
- code = StringVar()
- Label(screen1, text = "Please enter details below").pack()
- Label(screen1, text = "").pack()
- Label(screen1, text = "Username * ").pack()
- username_entry = Entry(screen1, textvariable = username)
- username_entry.pack()
- Label(screen1, text = "Password * ").pack()
- password_entry = Entry(screen1, show="*", textvariable = password)
- password_entry.pack()
- Label(screen1, text = "Re-enter password * ").pack()
- password_entry0 = Entry(screen1, show="*", textvariable = password1)
- password_entry0.pack()
- Label(screen1, text = "Class code * ").pack()
- code_entry = Entry(screen1, textvariable = code)
- code_entry.pack()
- Button(screen1, text = "Register", width = 10, height = 1, command = register_user).pack()
- #This is where the student´s login data is checked to the saved data in the file
- def login_verify():
- global username1
- username1 = username_verify.get()
- password1 = password_verify.get()
- username_entry1.delete(0, END)
- password_entry1.delete(0, END)
- list_of_files = os.listdir()
- #The apropiate file acording to the username is searched in the OS
- if username1 in list_of_files:
- #The file is opened as a read
- file1 = open(username1, "r")
- verify = file1.read().splitlines()
- #First it is checked to see if it is the correct type of account as in Student not Teacher
- if verify[0][0] == "S":
- #This is a message to say you have loged in successfully
- if password1 in verify:
- login_success()
- #This is an error message to say the password is incorrect
- else:
- password_not_recognised()
- #This is an error message to say the account is a teacher account not a student one
- else:
- incorrect_login()
- #This is an error message to say that the user doesn´t exist
- else:
- user_not_found()
- #This is where the teacher´s login data is checked to the saved data in the file
- def login_verify2():
- global username2
- username2 = username_verify2.get()
- password2 = password_verify2.get()
- username_entry2.delete(0, END)
- password_entry2.delete(0, END)
- code_entry2.delete(0, END)
- list_of_files = os.listdir()
- #The apropiate file acording to the username is searched in the OS
- if username2 in list_of_files:
- #The file is opened as a read
- file2 = open(username2, "r")
- verify2 = file2.read().splitlines()
- #First it is checked to see if it is the correct type of account as in Teacher not Student
- if verify2[0][0] == "T":
- if password2 in verify2:
- #This is a message to say you have loged in successfully
- login_success2()
- #This is an error message to say the password is incorrect
- else:
- password_not_recognised()
- #This is an error message to say the account is a student account not a teacher one
- else:
- incorrect_login()
- #This is an error message to say that the user doesn´t exist
- else:
- user_not_found()
- #This is an error message screen
- def password_not_recognised():
- global screen10
- screen10 = Toplevel(screen)
- screen10.title("Error")
- screen10.geometry("150x100")
- Label(screen10, text = "Password Error").pack()
- Button(screen10, text = "OK", command = delete3).pack()
- #This is an error message screen
- def user_not_found():
- global screen11
- screen11 = Toplevel(screen)
- screen11.title("Error")
- screen11.geometry("150x100")
- Label(screen11, text = "User not found").pack()
- Button(screen11, text = "OK", command = delete4).pack()
- #This is an error message screen
- def incorrect_login():
- global screen13
- screen13 = Toplevel(screen)
- screen13.title("Error")
- screen13.geometry("550x80")
- Label(screen13, text = "User not a Teacher/Student, choose the appropiate login and try again").pack()
- Button(screen13, text = "OK", command = delete6).pack()
- #This is a login success screen for students
- def login_success():
- global screen4
- screen4 = Toplevel(screen)
- screen4.title("Success")
- screen4.geometry("150x100")
- Label(screen4, text = "Login Success").pack()
- Button(screen4, text = "OK", command = delete2).pack()
- session()
- #This is a login success screen for teachers
- def login_success2():
- global screen14
- screen14 = Toplevel(screen)
- screen14.title("Success")
- screen14.geometry("150x100")
- Label(screen14, text = "Login Success").pack()
- Button(screen14, text = "OK", command = delete8).pack()
- session2()
- #This is where the student is registered
- def register_user():
- p1=password.get()
- p2=password1.get()
- if p1 == p2:
- username_info = username.get()
- password_info = password.get()
- code_info = code.get()
- #A new file named like the username is created and the password and classcode are written to the file
- file = open(username_info, "w")
- file.write("S" + username_info + "\n")
- file.write(password_info + "\n")
- file.write(code_info)
- file.close
- username_entry.delete(0, END)
- password_entry.delete(0, END)
- password_entry0.delete(0, END)
- code_entry.delete(0, END)
- Label(screen1, text = "Registration Success", fg = "green", font = ("calibri", 11)).pack()
- #If passwords aren´t equal, then it will give an error message
- else:
- global screen6
- screen6 = Toplevel(screen)
- screen6.title("Error")
- screen6.geometry("150x100")
- Label(screen6, text = "Passwords aren´t equal").pack()
- Button(screen6, text = "Ok", width = 10, height = 1, command = retry).pack()
- username_entry.delete(0, END)
- password_entry.delete(0, END)
- password_entry0.delete(0, END)
- code_entry.delete(0, END)
- #Play button starts game
- def play():
- screen5.destroy()
- dice()
- game()
- #Profile button gives a screen with info on the user
- def profile():
- global screen8
- screen8 = Toplevel(screen)
- screen8.title("Profile")
- screen8.geometry("400x400")
- Label(screen8, text = "Username: " + username1, bg = "light green", width = "300", height = "2", font = ("calibri", 14)).pack()
- Label(screen8, text = "Level: " + userLevel).pack()
- Label(screen8, text = "Number of games played: " + number_of_games).pack()
- Label(screen8, text = "Number of games won: " + games_won).pack()
- Label(screen8, text = "Number of wrong answers for Spelling: " + number_wrong_spelling).pack()
- Label(screen8, text = "Number of wrong answers for Translation: " + number_wrong_translation).pack()
- Label(screen8, text = "Number of wrong answers for Synonyms: " + number_wrong_syn).pack()
- #Also, here you can change the password
- Button(screen8, text = "Change password", command = change_password).pack()
- #This is a screen where the new password is entered
- def change_password():
- global screen9
- screen9 = Toplevel(screen)
- screen9.title("Change Password")
- screen9.geometry("300x250")
- global password3
- global password4
- global password_entry3
- global password_entry4
- password3 = StringVar()
- password4 = StringVar()
- Label(screen9, text = "Current password *").pack()
- password_entry3 = Entry(screen9, show = "*", textvariable = password3).pack()
- Label(screen9, text = "New password *").pack()
- password_entry4 = Entry(screen9, show = "*", textvariable = password4).pack()
- Button(screen9, text = "Change", command = change_password1).pack()
- #This is where the password is changed
- def change_password1():
- p3 = password3.get()
- p4 = password4.get()
- if p3 != "" or p4 != "":
- #This is done by rewritting the password in the file
- with open(username1, "r") as file1:
- data = file1.readlines()
- data[1] = str(p4) + "\n"
- with open(username1, "w") as file1:
- file1.writelines( data )
- Label(screen9, text = "Password changed", fg = "green", font = ("calibri", 11)).pack()
- Button(screen9, text = "OK", command = delete5).pack()
- else:
- Label(screen9, text = "Error, password not changed", fg = "red", font = ("calibri", 11)).pack()
- main_screen()
- def delete_1():
- dice_result.destroy()
- board.destroy()
- def delete_2():
- dice.destroy()
- dice()
- def game():
- class Board(Tk):
- def __init__(self, width, height, cellsize):
- Tk.__init__(self)
- self.cellsize = cellsize
- self.canvas = Canvas(self, width=width, height=height)
- self.canvas.pack()
- def draw_rectangle(self, x1, y1, x2, y2, color):
- self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline="black")
- def draw_circle(self, x1, y1, x2, y2, color):
- self.canvas.create_oval(x1, y1, x2, y2, fill=color, outline="black")
- def coordinates(self, event):
- i = int(event.x / self.cellsize)
- j = int(event.y / self.cellsize)
- global i
- global j
- size = 80
- global board
- board = Board(675, 675, size)
- board.title("Board")
- logicBoard = [[0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0]]
- for (i, j) in product(range(8), range(8)):
- coordX1 = (i * size)
- coordY1 = (j * size)
- coordX2 = coordX1 + size
- coordY2 = coordY1 + size
- if coordX1==0 and coordY1==0 and coordX2==80 and coordY2==80 or coordX1==0 and coordY1==560 and coordX2==80 and coordY2==640:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "blue")
- else:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "white")
- cell = logicBoard[i][j]
- pawnColor = "red"
- global current_pos_x1
- global current_pos_x2
- current_pos_x1 = 0
- current_pos_x2 = 40
- board.draw_circle(current_pos_x1, 560, current_pos_x2, 600, pawnColor)
- board.mainloop()
- def dice():
- global dice
- dice = Tk()
- dice.title("Dice")
- dice.geometry("300x250")
- Label(text = "Click the button to throw the dice").pack()
- Button(text = "Throw", height = "2", width = "30", command = dice_throw).pack()
- Label(text = "").pack()
- def dice_throw():
- global dice_result
- dice_result = Toplevel(dice)
- dice_result.geometry("150x100")
- roll=True
- random_number(roll)
- Label(dice_result, text = random_numb, font = ("Comic Sans MS", 15)).pack()
- Label(dice_result, text = "").pack()
- Button(dice_result, text = "Ok", height = "1", width = "10", command = move_counter).pack()
- Label(dice_result, text = "").pack()
- def random_number(roll):
- global random_numb
- global counter
- counter = 0
- while roll==True:
- random_numb = random.randint(1,6)
- roll=False
- def move_counter():
- delete_1()
- if counter!=7:
- class Board(Tk):
- def __init__(self, width, height, cellsize):
- Tk.__init__(self)
- self.cellsize = cellsize
- self.canvas = Canvas(self, width=width, height=height)
- self.canvas.pack()
- def draw_rectangle(self, x1, y1, x2, y2, color):
- self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline="black")
- def draw_circle(self, x1, y1, x2, y2, color):
- self.canvas.create_oval(x1, y1, x2, y2, fill=color, outline="black")
- def coordinates(self, event):
- i = int(event.x / self.cellsize)
- j = int(event.y / self.cellsize)
- global i
- global j
- size = 80
- global board
- board = Board(675, 675, size)
- board.title("Board")
- logicBoard = [[0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0]]
- for (i, j) in product(range(8), range(8)):
- coordX1 = (i * size)
- coordY1 = (j * size)
- coordX2 = coordX1 + size
- coordY2 = coordY1 + size
- if coordX1==0 and coordY1==0 and coordX2==80 and coordY2==80 or coordX1==0 and coordY1==560 and coordX2==80 and coordY2==640:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "blue")
- else:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "white")
- cell = logicBoard[i][j]
- pawnColor = "red"
- global current_pos_x1
- global current_pos_x2
- current_pos_x1= random_numb*80 + current_pos_x1
- current_pos_x2= (random_numb*80) + current_pos_x2
- board.draw_circle((current_pos_x1), 560, (current_pos_x2), 600, pawnColor)
- board.mainloop()
- delete_2()
- def game():
- class Board(Tk):
- def __init__(self, width, height, cellsize):
- Tk.__init__(self)
- self.cellsize = cellsize
- self.canvas = Canvas(self, width=width, height=height)
- self.canvas.pack()
- def draw_rectangle(self, x1, y1, x2, y2, color):
- self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline="black")
- def draw_circle(self, x1, y1, x2, y2, color):
- self.canvas.create_oval(x1, y1, x2, y2, fill=color, outline="black")
- def coordinates(self, event):
- i = int(event.x / self.cellsize)
- j = int(event.y / self.cellsize)
- global i
- global j
- size = 80
- global board
- board = Board(675, 675, size)
- board.title("Board")
- logicBoard = [[0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0]]
- for (i, j) in product(range(8), range(8)):
- coordX1 = (i * size)
- coordY1 = (j * size)
- coordX2 = coordX1 + size
- coordY2 = coordY1 + size
- if coordX1==0 and coordY1==0 and coordX2==80 and coordY2==80 or coordX1==0 and coordY1==560 and coordX2==80 and coordY2==640:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "blue")
- else:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "white")
- cell = logicBoard[i][j]
- pawnColor = "red"
- global current_pos_x1
- global current_pos_x2
- current_pos_x1 = 0
- current_pos_x2 = 40
- board.draw_circle(current_pos_x1, 40, current_pos_x2, 0, pawnColor)
- board.mainloop()
- def end():
- global winner
- winner = Tk()
- winner.title("Winner")
- winner.geometry("300x250")
- Label(winner, text = "YOU HAVE WON", font = ("Comic Sans MS", 15)).pack()
- Label(winner, text = "").pack()
- Label(winner, text = "JAMES", font = ("Comic Sans MS", 10)).pack()
- Label(winner, text = "").pack()
- Label(winner, text = "You are now level: 2").pack()
- Label(winner, text = "").pack()
- Label(winner, text = "You have won : 1 game").pack()
- Label(winner, text = "").pack()
- Button(winner, text = "Exit", height = "2", width = "30", command = quit).pack()
- Label(winner, text = "").pack()
- def quit():
- dice.destroy()
- winner.destroy()
- board.destroy()
- def extra():
- print("2")
- def extra1():
- screen_2.destroy()
- dice()
- def session():
- global screen_1
- screen_1 = Tk()
- screen_1.title("Game")
- screen_1.geometry("400x300")
- Label(screen_1, text = "Welcome to the game").pack()
- Label(screen_1, text = "").pack()
- Button(screen_1, text = "Play", height = "2", width = "30", command = play).pack()
- Label(screen_1, text = "").pack()
- Button(screen_1, text = "Profile", height = "2", width = "30", command = extra).pack()
- Label(screen_1, text = "").pack()
- Button(screen_1, text = "Log out", height = "1", width = "10",command = extra).pack()
- screen_1.mainloop()
- def play():
- screen_1.destroy()
- global screen_2
- screen_2 = Tk()
- screen_2.title("Game")
- screen_2.geometry("400x300")
- Label(screen_2, text = "Choose the number of players:").pack()
- Label(screen_2, text = "").pack()
- Button(screen_2, text = "1 - player", height = "2", width = "30", command = extra).pack()
- Label(screen_2, text = "").pack()
- Button(screen_2, text = "2 - players", height = "2", width = "30", command = game).pack()
- Label(screen_2, text = "").pack()
- def delete_1():
- dice_result.destroy()
- board.destroy()
- def delete_2():
- dice.destroy()
- dice()
- def game():
- extra1()
- class Board(Tk):
- def __init__(self, width, height, cellsize):
- Tk.__init__(self)
- self.cellsize = cellsize
- self.canvas = Canvas(self, width=width, height=height)
- self.canvas.pack()
- def draw_rectangle(self, x1, y1, x2, y2, color):
- self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline="black")
- def draw_circle(self, x1, y1, x2, y2, color):
- self.canvas.create_oval(x1, y1, x2, y2, fill=color, outline="black")
- def coordinates(self, event):
- i = int(event.x / self.cellsize)
- j = int(event.y / self.cellsize)
- global i
- global j
- size = 80
- global board
- board = Board(675, 675, size)
- board.title("Board")
- logicBoard = [[0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0]]
- for (i, j) in product(range(8), range(8)):
- coordX1 = (i * size)
- coordY1 = (j * size)
- coordX2 = coordX1 + size
- coordY2 = coordY1 + size
- if coordX1==0 and coordY1==0 and coordX2==80 and coordY2==80 or coordX1==0 and coordY1==560 and coordX2==80 and coordY2==640:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "blue")
- else:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "white")
- cell = logicBoard[i][j]
- pawnColor = "red"
- global current_pos_x1
- global current_pos_x2
- current_pos_x1 = 0
- current_pos_x2 = 40
- board.draw_circle(current_pos_x1, 560, current_pos_x2, 600, pawnColor)
- board.draw_circle(current_pos_x1+40, 600, current_pos_x2+40, 640, pawnColor)
- board.mainloop()
- def dice():
- global dice
- dice = Tk()
- dice.title("Dice")
- dice.geometry("300x250")
- Label(text = "It´s James´s turn!").pack()
- Label(text = "Click the button to throw the dice").pack()
- Button(text = "Throw", height = "2", width = "30", command = dice_throw).pack()
- Label(text = "").pack()
- def dice_throw():
- counter=1
- if counter==1:
- global dice_result
- dice_result = Toplevel(dice)
- dice_result.geometry("150x100")
- roll=True
- counter=counter+1
- random_number(roll)
- Label(dice_result, text = random_numb, font = ("Comic Sans MS", 15)).pack()
- Label(dice_result, text = "").pack()
- Button(dice_result, text = "Ok", height = "1", width = "10", command = move_counter).pack()
- Label(dice_result, text = "").pack()
- def dice_throw2():
- dice_result2 = Toplevel(dice)
- dice_result2.geometry("150x100")
- roll=True
- counter=counter+1
- random_number(roll)
- Label(dice_result2, text = random_numb, font = ("Comic Sans MS", 15)).pack()
- Label(dice_result2, text = "").pack()
- Button(dice_result2, text = "Ok", height = "1", width = "10", command = move_counter2).pack()
- Label(dice_result2, text = "").pack()
- def move_counter():
- delete_1()
- class Board(Tk):
- def __init__(self, width, height, cellsize):
- Tk.__init__(self)
- self.cellsize = cellsize
- self.canvas = Canvas(self, width=width, height=height)
- self.canvas.pack()
- def draw_rectangle(self, x1, y1, x2, y2, color):
- self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline="black")
- def draw_circle(self, x1, y1, x2, y2, color):
- self.canvas.create_oval(x1, y1, x2, y2, fill=color, outline="black")
- def coordinates(self, event):
- i = int(event.x / self.cellsize)
- j = int(event.y / self.cellsize)
- global i
- global j
- size = 80
- global board
- board = Board(675, 675, size)
- board.title("Board")
- logicBoard = [[0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0]]
- for (i, j) in product(range(8), range(8)):
- coordX1 = (i * size)
- coordY1 = (j * size)
- coordX2 = coordX1 + size
- coordY2 = coordY1 + size
- if coordX1==0 and coordY1==0 and coordX2==80 and coordY2==80 or coordX1==0 and coordY1==560 and coordX2==80 and coordY2==640:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "blue")
- else:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "white")
- cell = logicBoard[i][j]
- pawnColor = "red"
- board.draw_circle((random_numb*80 + current_pos_x1), 560, ((random_numb*80) + current_pos_x2), 600, pawnColor)
- board.draw_circle(current_pos_x1+40, 600, current_pos_x2+40, 640, pawnColor)
- board.mainloop()
- delete_2()
- def move_counter2():
- delete_1()
- class Board(Tk):
- def __init__(self, width, height, cellsize):
- Tk.__init__(self)
- self.cellsize = cellsize
- self.canvas = Canvas(self, width=width, height=height)
- self.canvas.pack()
- def draw_rectangle(self, x1, y1, x2, y2, color):
- self.canvas.create_rectangle(x1, y1, x2, y2, fill=color, outline="black")
- def draw_circle(self, x1, y1, x2, y2, color):
- self.canvas.create_oval(x1, y1, x2, y2, fill=color, outline="black")
- def coordinates(self, event):
- i = int(event.x / self.cellsize)
- j = int(event.y / self.cellsize)
- global i
- global j
- size = 80
- global board
- board = Board(675, 675, size)
- board.title("Board")
- logicBoard = [[0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0]]
- for (i, j) in product(range(8), range(8)):
- coordX1 = (i * size)
- coordY1 = (j * size)
- coordX2 = coordX1 + size
- coordY2 = coordY1 + size
- if coordX1==0 and coordY1==0 and coordX2==80 and coordY2==80 or coordX1==0 and coordY1==560 and coordX2==80 and coordY2==640:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "blue")
- else:
- board.draw_rectangle(coordX1, coordY1, coordX2, coordY2, "white")
- cell = logicBoard[i][j]
- pawnColor = "red"
- global current_pos_x1
- global current_pos_x2
- board.draw_circle((current_pos_x1), 560, (current_pos_x2), 600, pawnColor)
- board.draw_circle((random_numb*80 + current_pos_x1)+40, 600, ((random_numb*80) + current_pos_x2)+40, 640, pawnColor)
- board.mainloop()
- delete_2()
- session()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement