Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tyler Hobson - Year 13
- # A2 Computer Science coursework final program
- # BASIC CAR TUNING SIMULATOR ---- COURSEWORK A2 COMPUTER SCIENCE
- # ------------------------
- # Imports tkinter module
- from tkinter import *
- from tkinter.font import Font
- from tkinter import messagebox
- # Imports pymysql for database
- import pymysql.cursors
- class Database():
- db_hostname = 'localhost'
- db_user = 'root'
- db_port = 3306
- db_password = 'f1lmstar'
- db_name = 'Tuner_db'
- def __init__(self, model):
- self.model = model
- self.create_db_and_table()
- self.add_db_content()
- def create_db_and_table(self):
- # Create the database and tables
- connection = pymysql.connect(host=Database.db_hostname,
- user=Database.db_user,
- port=Database.db_port,
- password=Database.db_password)
- try:
- with connection.cursor() as cursor:
- cursor.execute('CREATE DATABASE IF NOT EXISTS Tuner_db')
- finally:
- connection.close()
- # Create a table
- connection = pymysql.connect(host=Database.db_hostname,
- user=Database.db_user,
- port=Database.db_port,
- password=Database.db_password,
- db=Database.db_name,
- cursorclass=pymysql.cursors.DictCursor
- )
- try:
- with connection.cursor() as cursor:
- sqlQuery = 'CREATE TABLE IF NOT EXISTS car_details(car_ID INT not null auto_increment, car_name VARCHAR(50) UNIQUE, gear1 INT(3), gear2 INT(3), gear3 INT(3), gear4 INT(3),gear5 INT(3), gear6 INT(3), gear_final INT(3), drag_length_selection INT(1), road_surface_selection INT(1), tyre_selection INT(1), drive_selection INT(1), kerb_weight INT(5), horsepower INT(5), width DECIMAL(18, 2), height DECIMAL(18, 2), primary key (car_ID))'
- cursor.execute(sqlQuery)
- finally:
- connection.close()
- def add_db_content(self):
- # Set up the database content
- cars_default = [self.model.default_settings_string, 50, 50, 50, 50, 50, 50, 50, 1, 1, 2, 1, 800, 2000, 1.9, 1.2], \
- ['Alfa Romeo 4C Gr.3.', 50, 80, 50, 50, 50, 50, 50, 1, 2, 1, 2, 1043, 2000, 1.9, 1.2], \
- ['Aston Martin Vulcan', 50, 50, 50, 80, 50, 50, 50, 1, 2, 1, 2, 800, 2000, 1.9, 1.2], \
- ['Audi TT cup', 10, 20, 30, 40, 50, 60, 70, 1, 2, 1, 2, 1043, 2000, 1.9, 1.2], \
- ['BMW i3', 80, 20, 80, 20, 80, 20, 80, 1, 2, 1, 2, 800, 2000, 1.9, 1.2], \
- ['Citroen DS3 Racing', 50, 50, 50, 80, 50, 50, 50, 1, 2, 1, 4, 1500, 2000, 1.9, 1.2], \
- ['Dodge Charger SRT Hellcat', 50, 80, 50, 50, 50, 50, 50, 1, 2, 1, 2, 1500, 2000, 1.9, 1.2], \
- ['Ford Focus ST', 50, 50, 50, 50, 50, 50, 80, 1, 2, 1, 2, 1043, 2000, 1.9, 1.2]\
- # Store values in table
- connection = pymysql.connect(host=Database.db_hostname,
- user=Database.db_user,
- port=Database.db_port,
- password=Database.db_password,
- db=Database.db_name,
- cursorclass=pymysql.cursors.DictCursor
- )
- try:
- with connection.cursor() as cursor:
- # check whether car name exists in database
- sqlQueryCheck = 'SELECT car_ID FROM car_details WHERE car_name = %s'
- sqlQueryDelete = 'DELETE FROM car_details WHERE car_ID = %s'
- sqlQueryInsert = 'INSERT INTO car_details(`car_name`, `gear1`, `gear2`, `gear3`, `gear4`, `gear5`, `gear6`, `gear_final`, `drag_length_selection`, `road_surface_selection`, `tyre_selection`, `drive_selection`, `kerb_weight`, `horsepower`, `width`, `height`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
- # UNCOMMENT TO DELETE ALL TABLES FROM DATABASE WHEN NEEDED
- # sqlQueryDeleteAll = 'TRUNCATE TABLE car_details'
- # cursor.execute(sqlQueryDeleteAll)
- # iterate through car list and add to database if not already present
- for row in cars_default:
- # test whether all 16 details are in list for each car
- if len(row) == 16:
- cursor.execute(sqlQueryCheck, row[0])
- result = cursor.fetchone()
- if not result:
- # if the car doesn't already exist in the database, add it
- cursor.execute(sqlQueryInsert,
- [row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8],
- row[9], row[10], row[11], row[12], row[13], row[14], row[15]])
- connection.commit()
- else:
- # if the car exists in the database, delete it and insert a new entry e.g. update data
- cursor.execute(sqlQueryDelete, result['car_ID'])
- cursor.execute(sqlQueryInsert,
- [row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8],
- row[9], row[10], row[11], row[12], row[13], row[14], row[15]])
- connection.commit()
- else:
- print("details for car " + row[0] + " are incomplete - not added to database")
- finally:
- connection.close()
- def get_simulation_details_for_car_query(self, car_name):
- # get the simulation details for the car choice
- connection = pymysql.connect(host=Database.db_hostname,
- user=Database.db_user,
- port=Database.db_port,
- password=Database.db_password,
- db=Database.db_name,
- cursorclass=pymysql.cursors.DictCursor
- )
- try:
- with connection.cursor() as cursor:
- sqlQueryCheck = 'SELECT * FROM car_details WHERE car_name = %s'
- cursor.execute(sqlQueryCheck, car_name)
- result = cursor.fetchone()
- if not result:
- print("no car in database with name", car_name)
- else:
- print(car_name)
- print(result)
- finally:
- connection.close()
- def db_car_names_for_dropdown_query(self):
- # get the names of the cars in the database
- connection = pymysql.connect(host=Database.db_hostname,
- user=Database.db_user,
- port=Database.db_port,
- password=Database.db_password,
- db=Database.db_name,
- cursorclass=pymysql.cursors.DictCursor
- )
- try:
- with connection.cursor() as cursor:
- sqlQueryCheck = 'SELECT car_name FROM car_details'
- cursor.execute(sqlQueryCheck)
- result = cursor.fetchall()
- if not result:
- print("no cars in the database")
- else:
- # create list to hold car names from database
- car_list = []
- for row in result:
- car_list.append(row['car_name'])
- self.model.car_dropdown_options = car_list.copy()
- finally:
- connection.close()
- def load_sim_settings(self, selected_car_name):
- # Get the "default car" details from the database and create a dictionary
- connection = pymysql.connect(host=Database.db_hostname,
- user=Database.db_user,
- port=Database.db_port,
- password=Database.db_password,
- db=Database.db_name,
- cursorclass=pymysql.cursors.DictCursor
- )
- try:
- with connection.cursor() as cursor:
- sqlQueryGetDefault = 'SELECT * FROM car_details WHERE car_name = %s'
- default_settings_db_name = selected_car_name
- print ("default_settings_db_name ", default_settings_db_name)
- cursor.execute(sqlQueryGetDefault, default_settings_db_name)
- result = cursor.fetchone()
- if not result:
- print("no DEFAULT SETTINGS in database with name")
- exit()
- else:
- print(result)
- finally:
- connection.close()
- sim_settings_dict = {'car_name': result['car_name'],
- 'gear1': result['gear1'],
- 'gear2': result['gear2'],
- 'gear3': result['gear3'],
- 'gear4': result['gear4'],
- 'gear5': result['gear5'],
- 'gear6': result['gear6'],
- 'gear_final': result['gear_final'],
- 'drag_length_selection': result['drag_length_selection'],
- 'road_surface_selection': result['road_surface_selection'],
- 'tyre_selection': result['tyre_selection'],
- 'drive_selection': result['drive_selection'],
- 'kerb_weight': result['kerb_weight'],
- 'horsepower': result['horsepower'],
- 'width': result['width'],
- 'height': result['height']
- }
- return sim_settings_dict
- class Model:
- def __init__(self):
- self.user = None
- self.sim_settings_dict = {}
- self.default_settings_string = "Default Settings"
- self.results_dict = {'0_60': None,
- '0_100': None,
- 'top_speed': None,
- 'final_speed': None
- }
- self.current_car = self.default_settings_string
- self.car_dropdown_options = []
- self.trace_variable = ""
- class Controller:
- main_menu_needed = True
- simulator_settings_first_run = True
- def __init__(self, parent, model):
- self.parent = parent
- self.model = model
- # run the database setup - create tables
- self.database = Database(self.model)
- # create the login frame
- self.login_frame = LoginFrame(self, self.parent)
- self.main_menu_frame = None
- self.simulation_frame = None
- def car_dropdown_option_changed(self, *args):
- self.model.current_car = self.model.trace_variable.get()
- print("the user chose the value ", self.model.current_car)
- self.database.get_simulation_details_for_car_query(self.model.current_car)
- self.create_simulator_settings_frame()
- def login_successful(self):
- self.login_frame.destroy()
- if Controller.main_menu_needed:
- self.main_menu_frame = MainMenuFrame(self, self.parent, self.model)
- else:
- self.create_simulator_settings_frame()
- def save_username_password(self, username_entered, password_entered):
- self.model.user = username_entered
- # Save username and password to database / text file
- print("Username to store", self.model.user)
- print("Password to store", password_entered)
- # Test whether username and password have been saved successfully
- save_successful = 1
- if save_successful == 1:
- messagebox.showinfo("Info", "Username and password saved")
- self.login_successful()
- else:
- messagebox.showerror("Error", "Cannot store username / password")
- def check_username_password(self, username_entered, password_entered):
- print("check username and password in database / text file")
- # Check username and password to database / text file
- # opens the textfile in which the username and password is stored
- file = open("Username.txt", "r")
- data = file.read().split(",")
- # Reads the textfile and splits the data
- username_stored, password_stored = data[0], data[1]
- print("USERNAME:", username_stored)
- print("PASSWORD", password_stored)
- print(username_stored, password_stored)
- # Checks of the user input matches the username and password in the text file
- if username_entered == username_stored:
- if password_entered == password_stored:
- messagebox.showinfo("Login info", "Welcome " + username_entered)
- self.model.user = username_entered
- self.login_successful()
- else:
- messagebox.showerror("Login error", "Incorrect password")
- else:
- messagebox.showerror("Login error", "Incorrect username")
- def login_btn_clicked(self, checkbox_state, entry_1, entry_2):
- # Retrieves the variables name and password
- username_entered = entry_1
- password_entered = entry_2
- checkbox_value = checkbox_state
- print("USERNAME ENTERED:", username_entered)
- print("PASSWORD ENTERED", password_entered)
- print("CHECKBOX VALUE", checkbox_value)
- if checkbox_state == 1:
- # if new user
- self.save_username_password(username_entered, password_entered)
- else:
- # if existing user
- self.check_username_password(username_entered, password_entered)
- def sim_settings_to_console(self):
- print("gear ratio 1 is ", self.model.sim_settings_dict['gear1'])
- print("gear ratio 2 is ", self.model.sim_settings_dict['gear2'])
- print("gear ratio 3 is ", self.model.sim_settings_dict['gear3'])
- print("gear ratio 4 is ", self.model.sim_settings_dict['gear4'])
- print("gear ratio 5 is ", self.model.sim_settings_dict['gear5'])
- print("gear ratio 6 is ", self.model.sim_settings_dict['gear6'])
- print("gear ratio Final is ", self.model.sim_settings_dict['gear_final'])
- print("drag_length_selection", self.model.sim_settings_dict['drag_length_selection'])
- print("road_surface_selection", self.model.sim_settings_dict['road_surface_selection'])
- print("tyre_selection", self.model.sim_settings_dict['tyre_selection'])
- print("drive_selection", self.model.sim_settings_dict['drive_selection'])
- print("kerb_weight", self.model.sim_settings_dict['kerb_weight'])
- print("horsepower", self.model.sim_settings_dict['horsepower'])
- print("width", self.model.sim_settings_dict['width'])
- print("height", self.model.sim_settings_dict['height'])
- def sim_results_to_console(self):
- print("\nFinal results:")
- print("Top speed = ", self.model.results_dict['top_speed'])
- print("Final Car Speed = ", self.model.results_dict['final_speed'])
- print('zeroToSixtyMPH = ', self.model.results_dict['0_60'])
- print('zeroToOneHundredMPH = ', self.model.results_dict['0_100'])
- def create_simulator_settings_frame(self):
- if Controller.simulator_settings_first_run:
- # create Simulator settings frame for the first time
- Controller.simulator_settings_first_run = False
- if Controller.main_menu_needed:
- self.main_menu_frame.destroy()
- # load the simulator settings into the model
- self.model.current_car = self.model.default_settings_string
- self.model.sim_settings_dict = self.database.load_sim_settings(self.model.current_car)
- else:
- # create Simulator settings frame with choice from the dropdown menu
- self.simulation_frame.destroy()
- # load the simulator settings into the model
- print ("self.model.car_dropdown_variable is ", self.model.current_car)
- self.model.sim_settings_dict = self.database.load_sim_settings(self.model.current_car)
- # get the dropdown menu options for the simulator
- self.database.db_car_names_for_dropdown_query()
- # run the simulation frame with the model settings
- self.simulation_frame = SimulationFrame(self, self.parent)
- def start_simulation_btn_clicked(self):
- # store the simulation settings in the model
- self.model.sim_settings_dict['gear1'] = self.simulation_frame.sim_settings_frame.gear1RatioScale.get()
- self.model.sim_settings_dict['gear2'] = self.simulation_frame.sim_settings_frame.gear2RatioScale.get()
- self.model.sim_settings_dict['gear3'] = self.simulation_frame.sim_settings_frame.gear3RatioScale.get()
- self.model.sim_settings_dict['gear4'] = self.simulation_frame.sim_settings_frame.gear4RatioScale.get()
- self.model.sim_settings_dict['gear5'] = self.simulation_frame.sim_settings_frame.gear5RatioScale.get()
- self.model.sim_settings_dict['gear6'] = self.simulation_frame.sim_settings_frame.gear6RatioScale.get()
- self.model.sim_settings_dict['gear_final'] = self.simulation_frame.sim_settings_frame.gearFinalDriveScale.get()
- self.model.sim_settings_dict['drag_length_selection'] = self.simulation_frame.sim_settings_frame.drag_length_selection.get()
- self.model.sim_settings_dict['road_surface_selection'] = self.simulation_frame.sim_settings_frame.road_surface_selection.get()
- self.model.sim_settings_dict['tyre_selection'] = self.simulation_frame.sim_settings_frame.tyre_selection.get()
- self.model.sim_settings_dict['drive_selection'] = self.simulation_frame.sim_settings_frame.drive_selection.get()
- self.model.sim_settings_dict['kerb_weight'] = self.simulation_frame.sim_settings_frame.kerbWeightEntry.get()
- self.model.sim_settings_dict['horsepower'] = self.simulation_frame.sim_settings_frame.horsepowerEntry.get()
- self.model.sim_settings_dict['width'] = self.simulation_frame.sim_settings_frame.widthEntry.get()
- self.model.sim_settings_dict['height'] = self.simulation_frame.sim_settings_frame.heightEntry.get()
- # Show settings in console
- self.sim_settings_to_console()
- # Run simulation
- Simulator(self.model)
- # Show results of simulation
- self.sim_results_to_console()
- self.simulation_frame.results_frame.show_results(self.model.results_dict['top_speed'], self.model.results_dict['final_speed'], self.model.results_dict['0_60'], self.model.results_dict['0_100'])
- def load_statistics(self):
- print("load statistics")
- def create_car_upgrades_tuning(self):
- print("load car upgrades")
- def exit(self):
- print("exit")
- class SimulationFrame(Frame):
- def __init__(self, controller, parent):
- Frame.__init__(self, parent)
- self.parent = parent
- self.controller = controller
- self.sim_settings_frame = Frame
- self.results_frame = Frame
- self.grid()
- self.make_widgets()
- def make_widgets(self):
- #left side
- self.sim_settings_frame = SimSettingsFrame(self, self.controller, self.controller.model)
- self.sim_settings_frame.grid(row=0, column=0)
- #right side
- self.results_frame = ResultsFrame(self)
- self.results_frame.grid(row=0, column=1)
- class LoginFrame(Frame):
- def __init__(self, controller, parent):
- Frame.__init__(self, parent)
- self.parent = parent
- self.controller = controller
- self.logbtn = Button(self)
- self.grid(padx=(0, 100), pady=(20, 100))
- self.make_widgets()
- def make_widgets(self):
- # Creates label displaying: "Car Simulator V_1.00"
- Label(self, text="Car Simulator V_1.00", font=largeFont).grid(row=0, columnspan=2, pady=(10, 30))
- # Creates label displaying: "Username"
- Label(self, text="Username", font=mediumFont).grid(row=1, column=0, padx=100, pady=(0, 10))
- # Creates entry box for the user to enter username
- entry_1 = Entry(self, font=mediumFont)
- entry_1.grid(row=1, column=1, sticky=W, pady=(0, 10))
- # Creates label displaying: "Password"
- Label(self, text="Password", font=mediumFont).grid(row=2, column=0, pady=(0, 10))
- # Creates entry box for the user to enter password
- entry_2 = Entry(self, show="*", font=mediumFont)
- entry_2.grid(row=2, column=1, sticky=W, pady=(0, 10))
- # creates tickbox for new users
- checkbox_state = IntVar()
- checkbox_state.set(0)
- checkbox = Checkbutton(self, text="New User?", onvalue=1, offvalue=0, variable=checkbox_state, font=mediumFont)
- checkbox.grid(pady=10, columnspan=2)
- # Places button to log into the system
- self.logbtn.configure(text="Login",
- command=lambda: self.controller.login_btn_clicked(checkbox_state.get(), entry_1.get(), entry_2.get()), bg="light grey", font=mediumFont)
- self.logbtn.grid(pady=(0, 10), columnspan=2)
- class MainMenuFrame(Frame):
- def __init__(self, controller, parent, model):
- Frame.__init__(self, parent)
- self.parent = parent
- self.model = model
- self.controller = controller
- self.grid()
- self.make_widgets()
- def make_widgets(self):
- # Create label: "USERNAME"
- Label(self, text="Welcome " + self.model.user, font=superSmallFont).grid(row=0, pady=20)
- # Creates main title: "CAR SIMULATOR V_1.00"
- Label(self, text="CAR SIMULATOR V_1.00", font=largeFont).grid(row=1, pady=(0,20), padx=100)
- # Creates SubTitle: "MAIN - MENU"
- Label(self, text="Main Menu", font=mediumFont).grid(row=2, pady=(0,20))
- # Creates button that takes you to the simulation part of the program
- btnSimulation = Button(self, bg="yellow", activebackground="yellow", text="Simulation", font=mediumFont, command=self.controller.create_simulator_settings_frame)
- btnSimulation.grid(row=4, column=0)
- # Creates button that takes you to the Load Simulation part of the program
- btnLoad = Button(self, bg="green", activebackground="green", text="Load - Statistics", font=mediumFont, command=self.controller.load_statistics)
- btnLoad.grid(row=5)
- # Creates button that takes you to the Car Upgrades -- Tuning part of the program
- btnUpgrades = Button(self, bg="turquoise1", activebackground="turquoise1", text="Car Upgrades -- Tuning", font=mediumFont, command=self.controller.create_car_upgrades_tuning)
- btnUpgrades.grid(row=6, pady=(0, 50))
- # Creates a button that close all parts of the program except the menu
- btnExit = Button(self, bg="white", activebackground="white", text="Exit", font=mediumFont, command=self.controller.exit)
- btnExit.grid(row=7, pady=(0, 50))
- class ResultsFrame(Frame):
- def __init__(self, parent):
- Frame.__init__(self, parent)
- self.parent = parent
- self.grid()
- self.results_pane = None
- self.results_contents_pane = None
- self.make_widgets()
- def make_widgets(self):
- self.results_pane = Frame(self)
- self.results_pane.grid(row=0, column=0)
- Label(self.results_pane, text="Simulation Results", font=largeFont).grid(row=0, column=0, padx=60, sticky=W+N)
- # creates frame for results to be displayed
- self.results_contents_pane = Frame(self.results_pane)
- self.results_contents_pane.grid(row=1, column=0)
- # creates tooltip in results_contents_pane
- Label(self.results_contents_pane, text="Set the simulation parameters on the left and press Start Simulation.", font=smallFont).grid(row=0, column=0, padx=65)
- def show_results(self, top_speed, final_speed, to_sixty, to_hundred):
- self.results_contents_pane.destroy()
- self.results_contents_pane = Frame(self.results_pane)
- self.results_contents_pane.grid(row=1, column=0, padx=60)
- top_speed_label_text = "Top speed = " + str(top_speed) + "mph"
- final_speed_label_text = "Final speed = " + str(final_speed) + "mph"
- to_sixty_label_text = "0 - 60 = " + str(to_sixty) + " seconds"
- to_hundred_label_text = "0 - 100 = " + str(to_hundred) + " seconds"
- Label(self.results_contents_pane, text=top_speed_label_text, font=mediumFont).grid(sticky=W)
- Label(self.results_contents_pane, text=final_speed_label_text, font=mediumFont).grid(sticky=W)
- Label(self.results_contents_pane, text=to_sixty_label_text, font=mediumFont).grid(sticky=W)
- Label(self.results_contents_pane, text=to_hundred_label_text, font=mediumFont).grid(sticky=W)
- class SimSettingsFrame(Frame):
- def __init__(self, parent, controller, model):
- Frame.__init__(self, parent)
- self.parent = parent
- self.model = model
- self.controller = controller
- self.grid()
- self.gear1RatioScale = Scale
- self.gear2RatioScale = Scale
- self.gear3RatioScale = Scale
- self.gear4RatioScale = Scale
- self.gear5RatioScale = Scale
- self.gear6RatioScale = Scale
- self.gearFinalDriveScale = Scale
- self.kerbWeightEntry = Entry
- self.horsepowerEntry = Entry
- self.widthEntry = Entry
- self.heightEntry = Entry
- self.drag_length_selection = StringVar
- self.road_surface_selection = StringVar
- self.drive_selection = StringVar
- self.tyre_selection = StringVar
- self.make_widgets()
- def make_widgets(self):
- # TOP LEFT FRAME
- frame_left = Frame(self, highlightbackground="gray", highlightcolor="gray", highlightthickness=1)
- frame_left.grid(row=1, column=0, sticky=W+E)
- # creates title and subtitle
- row0Frame=Frame(frame_left)
- row0Frame.grid(row=0, column=0, sticky=W+E)
- Label(row0Frame, text="Simulation Settings", font=largeFont).grid(row=0, column=0, sticky=W)
- Label(row0Frame, text="Set Gear Ratios", font=mediumFont).grid(row=1, column=0, sticky=W)
- Label(row0Frame, text="0 = Short gear change, 100 = Long gear change", font=smallFont).grid(row=2, column=0, sticky=W)
- # creates Scale widgets
- row1Frame = Frame(frame_left)
- row1Frame.grid(row=1)
- # creates "GEAR 1 : :", then creates a scale to choose gear ratio number
- self.gear1RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300, tickinterval=25)
- self.gear1RatioScale.set(self.model.sim_settings_dict['gear1'])
- self.gear1RatioScale.grid(row=0, column=0, padx=15)
- # creates "GEAR 2 : :", then creates a scale to choose gear ratio number
- self.gear2RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
- self.gear2RatioScale.set(self.model.sim_settings_dict['gear2'])
- self.gear2RatioScale.grid(row=0, column=1, padx=15)
- # creates "GEAR 3 : :", then creates a scale to choose gear ratio number
- self.gear3RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL,font=superSmallFont, length=300)
- self.gear3RatioScale.set(self.model.sim_settings_dict['gear3'])
- self.gear3RatioScale.grid(row=0, column=2, padx=15)
- # creates "GEAR 4 : :", then creates a scale to choose gear ratio number
- self.gear4RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
- self.gear4RatioScale.set(self.model.sim_settings_dict['gear4'])
- self.gear4RatioScale.grid(row=0, column=3, padx=15)
- # creates "GEAR 5 : :", then creates a scale to choose gear ratio number
- self.gear5RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
- self.gear5RatioScale.set(self.model.sim_settings_dict['gear5'])
- self.gear5RatioScale.grid(row=0, column=4, padx=15)
- # creates "GEAR 6 : :", then creates a scale to choose gear ratio number
- self.gear6RatioScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300)
- self.gear6RatioScale.set(self.model.sim_settings_dict['gear6'])
- self.gear6RatioScale.grid(row=0, column=5, padx=15)
- # creates "FINAL DRIVE", then creates a scale to choose gear ratio number
- self.gearFinalDriveScale = Scale(row1Frame, from_=100, to=0, orient=VERTICAL, font=superSmallFont, length=300, tickinterval=25, width=30)
- self.gearFinalDriveScale.set(self.model.sim_settings_dict['gear_final'])
- self.gearFinalDriveScale.grid(row=0, column=6)
- Label(row1Frame, text="Gear 1", font=smallFont).grid(row=1, column=0, padx=(10, 0))
- Label(row1Frame, text="2", font=smallFont).grid(row=1, column=1, padx=(22, 0))
- Label(row1Frame, text="3", font=smallFont).grid(row=1, column=2, padx=(22, 0))
- Label(row1Frame, text="4", font=smallFont).grid(row=1, column=3, padx=(22, 0))
- Label(row1Frame, text="5", font=smallFont).grid(row=1, column=4, padx=(22, 0))
- Label(row1Frame, text="6", font=smallFont).grid(row=1, column=5, padx=(22, 0))
- Label(row1Frame, text="FINAL DRIVE", font=smallFont).grid(row=1, column=6, padx=(22, 0))
- # ROW 2 FRAME
- row2Frame = Frame(frame_left, highlightbackground="gray", highlightcolor="gray", highlightthickness=1, width=750, height=100)
- row2Frame.grid(row=2, column=0, stick=W+E)
- row_count = 0
- Label(row2Frame, text="Select Options", font=mediumFont).grid(row=row_count, column=0, sticky=W)
- # DRAG STRIP LENGTH RADIO BUTTONS
- # Creates a label to display options, then a text box to allow user to enter a selection
- row_count += 1
- Label(row2Frame, text="Drag Strip Length", font=smallFont).grid(row=row_count, column=0, sticky=W)
- track_choices = {
- "1/4 mile": 1,
- "1/2 mile": 2,
- "1 mile": 3
- }
- i = 1
- self.drag_length_selection = StringVar()
- for distance, val in track_choices.items():
- print("val = ", val)
- print("distance = ", distance)
- radio_button = Radiobutton(row2Frame, variable=self.drag_length_selection, value=val, text=distance, command=lambda:self.ShowChoice(self.drag_length_selection.get()))
- radio_button.grid(row=row_count, column=i, sticky=W)
- i += 1
- self.drag_length_selection.set(self.model.sim_settings_dict['drag_length_selection'])
- # ROAD SURFACE RADIO BUTTONS
- row_count += 1
- # Creates a label to display options, then a text box to allow user to enter a selection
- Label(row2Frame, text="Road Surface", font=smallFont).grid(row=row_count, column=0, sticky=W)
- surface_choices = {
- "Dirt Track": 1,
- "Smooth": 2,
- "Icy": 3,
- "Grass & Turf": 4
- }
- i = 1
- self.road_surface_selection = StringVar()
- for surface, val in surface_choices.items():
- print("val = ", val)
- print("Surface = ", surface)
- radio_button = Radiobutton(row2Frame, variable=self.road_surface_selection, value=val, text=surface, command=lambda:self.ShowChoice(self.road_surface_selection.get()))
- radio_button.grid(row=row_count, column=i, sticky=W)
- i += 1
- self.road_surface_selection.set(self.model.sim_settings_dict['road_surface_selection'])
- # TYRE CHOICE RADIO BUTTONS
- row_count += 1
- # Creates a label to display options, then a text box to allow user to enter a selection
- Label(row2Frame, text="Tyre Selection", font=smallFont).grid(row=row_count, column=0, sticky=W)
- tyre_choices = {
- "Drag tyres": 1,
- "Ultrasofts": 2,
- "Road legal": 3,
- "Offroad treads": 4,
- "Chain tyres": 5
- }
- i = 1
- self.tyre_selection = StringVar()
- for tyre_choice, val in tyre_choices.items():
- print("val = ", val)
- print("Tyre choice = ", tyre_choice)
- radio_button = Radiobutton(row2Frame, variable=self.tyre_selection, value=val, text=tyre_choice, command=lambda:self.ShowChoice(self.tyre_selection.get()))
- radio_button.grid(row=row_count, column=i, sticky=W)
- i += 1
- self.tyre_selection.set(self.model.sim_settings_dict['tyre_selection'])
- # DRIVE RADIO BUTTONS
- row_count += 1
- # Creates a label to display options, then a text box to allow user to enter a selection
- Label(row2Frame, text="Drive Selection", font=smallFont).grid(row=row_count, column=0, sticky=W)
- drive_choices = {
- "Front wheel drive": 1,
- "Rear wheel drive": 2,
- "All wheel drive": 3
- }
- i = 1
- self.drive_selection = StringVar()
- for drive_choice, val in drive_choices.items():
- radio_button = Radiobutton(row2Frame, variable=self.drive_selection, value=val, text=drive_choice, command=lambda:self.ShowChoice(self.drive_selection.get()))
- radio_button.grid(row=row_count, column=i)
- i += 1
- self.drive_selection.set(self.model.sim_settings_dict['drive_selection'])
- # ROW 3 FRAME
- row_count = 0
- row3Frame = Frame(frame_left, highlightbackground="gray", highlightcolor="gray", highlightthickness=1)
- row3Frame.grid(row=3, column=0, stick=W+E)
- Label(row3Frame, text="Car Details", font=mediumFont).grid(row=row_count, column=0, sticky=W, padx=(0, 20))
- # creates a label for instructions on what to enter into the entry box
- Label(row3Frame, text="Kerb Weight (Kg)",font=smallFont).grid(row=row_count, column=1, sticky=W)
- self.kerbWeightEntry = Entry(row3Frame, font=smallFont)
- self.kerbWeightEntry.insert(0, self.model.sim_settings_dict['kerb_weight'])
- self.kerbWeightEntry.grid(row=0, column=2)
- row_count += 1
- # creates a label for instructions on what to enter into the entry box
- Label(row3Frame, text="Horsepower (hp)", font=smallFont).grid(row=row_count, column=1, sticky=W)
- self.horsepowerEntry = Entry(row3Frame, font=smallFont)
- self.horsepowerEntry.insert(0, self.model.sim_settings_dict['horsepower'])
- self.horsepowerEntry.grid(row=row_count, column=2)
- row_count += 1
- # creates a label for instructions on what to enter into the entry box
- Label(row3Frame, text="Width (m)", font=smallFont).grid(row=row_count, column=1, sticky=W)
- self.widthEntry = Entry(row3Frame, font=smallFont)
- self.widthEntry.insert(0, self.model.sim_settings_dict['width'])
- self.widthEntry.grid(row=row_count, column=2)
- row_count += 1
- # creates a label for instructions on what to enter into the entry box
- Label(row3Frame, text="Height (m)",font=smallFont).grid(row=row_count, column=1, sticky=W)
- self.heightEntry = Entry(row3Frame, font=smallFont)
- self.heightEntry.insert(0, self.model.sim_settings_dict['height'])
- self.heightEntry.grid(row=row_count, column=2)
- # creates a button to submit all data to the system
- submitButton = Button(row3Frame, text="Start Simulation", font=mediumFont,
- command= self.controller.start_simulation_btn_clicked)
- submitButton.grid(row=1, column=3, sticky=E+W, padx=20)
- # Create dropdown and and check for change. Refresh of simulation settings
- self.model.trace_variable = StringVar()
- self.model.trace_variable.set(self.model.current_car)
- print("self.model.current_car is ", self.model.current_car)
- print("self.model.trace_variable is ", self.model.trace_variable.get())
- self.model.trace_variable.trace("w", self.controller.car_dropdown_option_changed)
- option_list = self.model.car_dropdown_options
- w = OptionMenu(row3Frame, self.model.trace_variable, *option_list)
- w.grid(row=2, column=3, sticky=E + W, padx=20)
- def ShowChoice(self, track_dist_var):
- print("")
- # DO NOT DELETE THIS METHOD
- class Simulator:
- def __init__(self, model):
- self.model = model
- self.startSimulation()
- def startSimulation(self):
- # get variables
- drag_length = self.model.sim_settings_dict['drag_length_selection']
- gear1RatioNumber = self.model.sim_settings_dict['gear1']
- gear2RatioNumber = self.model.sim_settings_dict['gear2']
- gear3RatioNumber = self.model.sim_settings_dict['gear3']
- gear4RatioNumber = self.model.sim_settings_dict['gear4']
- gear5RatioNumber = self.model.sim_settings_dict['gear5']
- gear6RatioNumber = self.model.sim_settings_dict['gear6']
- print('gear1RatioNumber ', gear1RatioNumber)
- print('gear2RatioNumber ', gear2RatioNumber)
- print('gear3RatioNumber ', gear3RatioNumber)
- print('gear4RatioNumber ', gear4RatioNumber)
- print('gear5RatioNumber ', gear5RatioNumber)
- # Gets the gear ratios to use for further algorithms
- gear_final_drive_number = (2 * self.model.sim_settings_dict['gear_final'])
- print('gear_final_drive_number ', gear_final_drive_number)
- TotalGears = (
- gear1RatioNumber + gear2RatioNumber + gear3RatioNumber + gear4RatioNumber + gear5RatioNumber + gear6RatioNumber + gear_final_drive_number)
- average_ratio = (TotalGears / 8)
- # Calculates mean average of gear ratios
- print("average_ratio = ", average_ratio)
- # Creates integer value for drag length
- drag_length = int(drag_length)
- print("drag length = ", drag_length)
- # runs if statement to determine which drag length the user has selected
- if drag_length == 1:
- # runs if statement to determine what the average gear ratio length the user has selected
- if average_ratio < 20 and average_ratio > 0:
- car_Speed = 10
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 20 and average_ratio < 40:
- car_Speed = 8
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 40 and average_ratio < 60:
- car_Speed = 5
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 60 and average_ratio < 80:
- car_Speed = 3
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 80 and average_ratio < 100:
- car_Speed = 2
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if drag_length == 2:
- if average_ratio < 20 and average_ratio > 0:
- car_Speed = 5
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 20 and average_ratio < 40:
- car_Speed = 10
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 40 and average_ratio < 60:
- car_Speed = 8
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 60 and average_ratio < 80:
- car_Speed = 3
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 80 and average_ratio < 100:
- car_Speed = 2
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if drag_length == 3:
- if average_ratio < 20 and average_ratio > 0:
- car_Speed = 2
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 20 and average_ratio < 40:
- car_Speed = 3
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 40 and average_ratio < 60:
- car_Speed = 8
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 60 and average_ratio < 80:
- car_Speed = 10
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- if average_ratio > 80 and average_ratio < 100:
- car_Speed = 5
- print(car_Speed)
- # determines the intial car speed to then be used in further algorithms
- # converts the car speed into a string
- car_speedPT1 = str(car_Speed)
- print('car speed', car_speedPT1)
- trackEntry_Number = self.model.sim_settings_dict['road_surface_selection']
- print("Track = " + trackEntry_Number)
- # retrieves and prints Track number
- tyreEntry_Number = self.model.sim_settings_dict['tyre_selection']
- print("Tyre = " + tyreEntry_Number)
- # retrieves and prints Tyre number
- driveEntry_Number = self.model.sim_settings_dict['drive_selection']
- print("Drive = " + driveEntry_Number)
- # retrieves and prints Drive number
- car_Speed_Final1 = car_speedPT1
- print("Speed = " + car_Speed_Final1)
- # retrieves and prints Car Speed rack number
- # Track change
- # Track is Dirt Track
- trackEntry_Number, tyreEntry_Number, driveEntry_Number, car_Speed_Final1 = int(
- trackEntry_Number), int(tyreEntry_Number), int(driveEntry_Number), float(car_Speed_Final1)
- kerbWeightEntryNumber = self.model.sim_settings_dict['kerb_weight']
- print("Curb Weight = " + kerbWeightEntryNumber)
- # retrieves and prints kerbWeight number
- horsePowerEntryNumber = self.model.sim_settings_dict['horsepower']
- print("Horsepower = " + horsePowerEntryNumber)
- # retrieves and prints horsepower number
- widthOfCar = self.model.sim_settings_dict['width']
- print("Width = " + widthOfCar)
- # retrieves and prints widthOfCar number
- heightOfCar = self.model.sim_settings_dict['height']
- print("Width = " + heightOfCar)
- # retrieves and prints heightOfCar number
- horsePowerEntryNumber, kerbWeightEntryNumber, widthOfCar, heightOfCar = float(horsePowerEntryNumber), float(
- kerbWeightEntryNumber), float(widthOfCar), float(heightOfCar)
- area = (widthOfCar / 1000) * (heightOfCar / 1000)
- power = horsePowerEntryNumber * 745.7
- speedMS = (2 * power / (0.35 * 1.25 * area)) ** (1 / 3)
- topSpeedMPH = speedMS * 2.23694
- topSpeedMPH = topSpeedMPH * 1.06680660592
- topSpeedMPH = round(topSpeedMPH, 2)
- topSpeedMPH = str(topSpeedMPH)
- zeroToSixtyMPH = kerbWeightEntryNumber / horsePowerEntryNumber
- # print("Top Speed = " + topSpeedMPH)
- # print(zeroToSixtyMPH)
- # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- car_Speed_Final3 = 0
- if trackEntry_Number == 1 and tyreEntry_Number == 4:
- car_Speed_Final2 = car_Speed_Final1 + 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.8
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print(car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.8
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.3
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 1 and tyreEntry_Number == 1:
- car_Speed_Final2 = car_Speed_Final1 - 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.8
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 1 and tyreEntry_Number == 2:
- car_Speed_Final2 = car_Speed_Final1 - 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.8
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.6
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.8
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 1 and tyreEntry_Number == 3:
- car_Speed_Final2 = car_Speed_Final1 - 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.9
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.5
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 1 and tyreEntry_Number == 5:
- car_Speed_Final2 = car_Speed_Final1 + 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.6
- # Puts original value checks the inputs then calculates final car speed
- # Track Changes
- # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- # Track is smooth tarmac
- if trackEntry_Number == 2 and tyreEntry_Number == 1:
- car_Speed_Final2 = car_Speed_Final1 + 5
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 + 0
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.85
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.75
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.70
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 2 and tyreEntry_Number == 2:
- car_Speed_Final2 = car_Speed_Final1 + 4
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 + 0
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.90
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.80
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.75
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 2 and tyreEntry_Number == 3:
- car_Speed_Final2 = car_Speed_Final1 + 2
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 + 0
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.9
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 0.8
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 2 and tyreEntry_Number == 4:
- car_Speed_Final2 = car_Speed_Final1 + 0
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 + 0
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.6
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.5
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.4
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 2 and tyreEntry_Number == 5:
- car_Speed_Final2 = car_Speed_Final1 - 4
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 + 0
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 5
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 5
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 4.5
- # Puts original value checks the inputs then calculates final car speed
- # Track Change
- # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- # Track is icy road
- if trackEntry_Number == 3 and tyreEntry_Number == 5:
- car_Speed_Final2 = car_Speed_Final1 + 2
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.8
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.5
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 3 and tyreEntry_Number == 1:
- car_Speed_Final2 = car_Speed_Final1 - 2
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 7
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 6
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 5
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 3 and tyreEntry_Number == 2:
- car_Speed_Final2 = car_Speed_Final1 - 2
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 6
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 5
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 4
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 3 and tyreEntry_Number == 3:
- car_Speed_Final2 = car_Speed_Final1 - 3
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 5
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 4
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3.2
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 3 and tyreEntry_Number == 4:
- car_Speed_Final2 = car_Speed_Final1 + 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 4
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 1
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3.5
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3
- # Puts original value checks the inputs then calculates final car speed
- # Track Change
- # --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- # Track Changes to Grass and Turf
- if trackEntry_Number == 4 and tyreEntry_Number == 4:
- car_Speed_Final2 = car_Speed_Final1 + 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.6
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 4 and tyreEntry_Number == 1:
- car_Speed_Final2 = car_Speed_Final1 - 3
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3.2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.4
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 4 and tyreEntry_Number == 2:
- car_Speed_Final2 = car_Speed_Final1 - 3
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 3
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.8
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.9
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 4 and tyreEntry_Number == 3:
- car_Speed_Final2 = car_Speed_Final1 - 1
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.1
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.7
- # Puts original value checks the inputs then calculates final car speed
- if trackEntry_Number == 4 and tyreEntry_Number == 5:
- car_Speed_Final2 = car_Speed_Final1 + 0
- if driveEntry_Number == 1:
- car_Speed_Final3 = car_Speed_Final2 - 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.4
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 2:
- car_Speed_Final3 = car_Speed_Final2 - 2
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 2.2
- # Puts original value checks the inputs then calculates final car speed
- if driveEntry_Number == 3:
- car_Speed_Final3 = car_Speed_Final2 + 3
- print("Speed = ", car_Speed_Final3)
- zeroToSixtyMPH = zeroToSixtyMPH * 1.8
- # Puts original value checks the inputs then calculates final car speed
- zeroToOneHundredMPH = zeroToSixtyMPH * 2.435
- zeroToOneHundredMPH = round(zeroToOneHundredMPH, 2)
- zeroToOneHundredMPH = str(zeroToOneHundredMPH)
- zeroToSixtyMPH = round(zeroToSixtyMPH, 2)
- zeroToSixtyMPH = str(zeroToSixtyMPH)
- self.model.results_dict['top_speed'] = topSpeedMPH
- self.model.results_dict['0_60'] = zeroToSixtyMPH
- self.model.results_dict['0_100'] = zeroToOneHundredMPH
- self.model.results_dict['final_speed'] = car_Speed_Final3
- print("Top speed = ", topSpeedMPH)
- print("Final Car Speed = ", car_Speed_Final3)
- print ('zeroToSixtyMPH = ', zeroToSixtyMPH)
- print('zeroToOneHundredMPH = ', zeroToOneHundredMPH)
- # -----------------------
- root = Tk()
- root.grid()
- # Set the font and size
- text = Text(root)
- superSmallFont = Font(family="Raleway", size=12)
- smallFont = Font(family="Raleway", size=16)
- mediumFont = Font(family="Raleway", size=20)
- largeFont = Font(family="Raleway", size=30)
- root.winfo_toplevel().title("CAR SIMULATOR V_1.00")
- myModel = Model()
- myApp = Controller(root, myModel)
- root.mainloop()
- # To do
- # Remove menu screen?
- # Save car stats
- # User login details to database
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement