diff --git a/.DS_Store b/.DS_Store index e7cb634..33ddf2c 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/chooseLevel.py b/chooseLevel.py deleted file mode 100644 index b86c16c..0000000 --- a/chooseLevel.py +++ /dev/null @@ -1,72 +0,0 @@ -import pygame - -BLACK = (0, 0, 0) -WHITE = (255, 255, 255) -GREEN = (0, 255, 0) -L_GREEN = (150, 255, 150) -RED = (255, 0, 0) -L_RED = (255, 204, 203) -GRAY = (80, 80, 80) -YELLOW = (255, 255, 0) -# -pygame.init() -X = 300 -Y = 200 -size = (X, Y) -window = pygame.display.set_mode(size) -font = pygame.font.Font('freesansbold.ttf', 25) - - - -def drawButton(left, top, color, textInButton): - rectSize = pygame.Rect(left, top, 60, 30) - pygame.draw.rect(window, color, rectSize) # left, top, width, height - pygame.draw.rect(window, BLACK, rectSize, 3) - fontButton = pygame.font.Font('freesansbold.ttf', 20) - textButton = fontButton.render(textInButton, True, BLACK, ) - textRectButton = textButton.get_rect() - textRectButton.center = (left + 30, top + 15) - window.blit(textButton, textRectButton) - - -def chooseLevel(): - level = 0 - text = font.render('choose difficulty level', True, BLACK, WHITE) - textRect = text.get_rect() - textRect.center = (X // 2, Y // 2 - 40) - - pygame.display.set_caption("Sudoku King") - - done = True - while done: - window.fill(WHITE) - window.blit(text, textRect) - drawButton(40, 100, GRAY, "1") - drawButton(120, 100, GRAY, "2") - drawButton(200, 100, GRAY, "3") - pos = pygame.mouse.get_pos() - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - # deactivates the pygame library - pygame.quit() - # quit the program. - quit() - if event.type == pygame.MOUSEBUTTONDOWN: - # print("Click ", pos) - if (40 <= pos[0] <= 100) and (100 <= pos[1] <= 130): - level = 1 - if (120 <= pos[0] <= 180) and (100 <= pos[1] <= 130): - level = 2 - if (200 <= pos[0] <= 260) and (100 <= pos[1] <= 130): - level = 3 - if level != 0: - # print(level) - pygame.quit() - return level - - # Draws the surface object to the screen. - pygame.display.update() - - -# chooseLevel() diff --git a/data/.DS_Store b/data/.DS_Store new file mode 100644 index 0000000..4f5efd7 Binary files /dev/null and b/data/.DS_Store differ diff --git a/data/Highscore.txt b/data/Highscore.txt new file mode 100644 index 0000000..e69de29 diff --git a/data/audios/.DS_Store b/data/audios/.DS_Store new file mode 100644 index 0000000..e06e2bb Binary files /dev/null and b/data/audios/.DS_Store differ diff --git a/data/audios/Crash.mp3 b/data/audios/Crash.mp3 new file mode 100644 index 0000000..b94cf51 Binary files /dev/null and b/data/audios/Crash.mp3 differ diff --git a/data/audios/game.mp3 b/data/audios/game.mp3 new file mode 100644 index 0000000..2b04fbc Binary files /dev/null and b/data/audios/game.mp3 differ diff --git a/data/audios/rtn.mp3 b/data/audios/rtn.mp3 new file mode 100644 index 0000000..94dcb7f Binary files /dev/null and b/data/audios/rtn.mp3 differ diff --git a/data/images/.DS_Store b/data/images/.DS_Store new file mode 100644 index 0000000..a0fd77d Binary files /dev/null and b/data/images/.DS_Store differ diff --git a/data/images/Background.png b/data/images/Background.png new file mode 100644 index 0000000..3ed5060 Binary files /dev/null and b/data/images/Background.png differ diff --git a/data/images/Car.png b/data/images/Car.png new file mode 100644 index 0000000..e747827 Binary files /dev/null and b/data/images/Car.png differ diff --git a/data/images/Coming Cars/CC1.png b/data/images/Coming Cars/CC1.png new file mode 100644 index 0000000..d4bcb4b Binary files /dev/null and b/data/images/Coming Cars/CC1.png differ diff --git a/data/images/Coming Cars/CC2.png b/data/images/Coming Cars/CC2.png new file mode 100644 index 0000000..552dcf4 Binary files /dev/null and b/data/images/Coming Cars/CC2.png differ diff --git a/data/images/Coming Cars/CC3.png b/data/images/Coming Cars/CC3.png new file mode 100644 index 0000000..c556452 Binary files /dev/null and b/data/images/Coming Cars/CC3.png differ diff --git a/data/images/Coming Cars/CC4.png b/data/images/Coming Cars/CC4.png new file mode 100644 index 0000000..4761af9 Binary files /dev/null and b/data/images/Coming Cars/CC4.png differ diff --git a/data/images/Coming Cars/CC5.png b/data/images/Coming Cars/CC5.png new file mode 100644 index 0000000..2f7334f Binary files /dev/null and b/data/images/Coming Cars/CC5.png differ diff --git a/data/images/Coming Cars/CC6.png b/data/images/Coming Cars/CC6.png new file mode 100644 index 0000000..6d5dcbe Binary files /dev/null and b/data/images/Coming Cars/CC6.png differ diff --git a/data/images/Coming Cars/CC7.png b/data/images/Coming Cars/CC7.png new file mode 100644 index 0000000..3fefdbf Binary files /dev/null and b/data/images/Coming Cars/CC7.png differ diff --git a/data/images/Coming Cars/CC8.png b/data/images/Coming Cars/CC8.png new file mode 100644 index 0000000..6c690ad Binary files /dev/null and b/data/images/Coming Cars/CC8.png differ diff --git a/data/images/Coming Cars/CC9.png b/data/images/Coming Cars/CC9.png new file mode 100644 index 0000000..d9a0e9b Binary files /dev/null and b/data/images/Coming Cars/CC9.png differ diff --git a/data/images/Explosion.png b/data/images/Explosion.png new file mode 100644 index 0000000..05ff1d4 Binary files /dev/null and b/data/images/Explosion.png differ diff --git a/data/images/Fuel.png b/data/images/Fuel.png new file mode 100644 index 0000000..b285bec Binary files /dev/null and b/data/images/Fuel.png differ diff --git a/data/images/GameOver.png b/data/images/GameOver.png new file mode 100644 index 0000000..0dbbcb0 Binary files /dev/null and b/data/images/GameOver.png differ diff --git a/data/images/Going Cars/GC1.png b/data/images/Going Cars/GC1.png new file mode 100644 index 0000000..e4e9af1 Binary files /dev/null and b/data/images/Going Cars/GC1.png differ diff --git a/data/images/Going Cars/GC2.png b/data/images/Going Cars/GC2.png new file mode 100644 index 0000000..5da0299 Binary files /dev/null and b/data/images/Going Cars/GC2.png differ diff --git a/data/images/Going Cars/GC3.png b/data/images/Going Cars/GC3.png new file mode 100644 index 0000000..9ea6b61 Binary files /dev/null and b/data/images/Going Cars/GC3.png differ diff --git a/data/images/Going Cars/GC4.png b/data/images/Going Cars/GC4.png new file mode 100644 index 0000000..a437d5e Binary files /dev/null and b/data/images/Going Cars/GC4.png differ diff --git a/data/images/Going Cars/GC5.png b/data/images/Going Cars/GC5.png new file mode 100644 index 0000000..090dacb Binary files /dev/null and b/data/images/Going Cars/GC5.png differ diff --git a/data/images/Going Cars/GC6.png b/data/images/Going Cars/GC6.png new file mode 100644 index 0000000..f8cf0fb Binary files /dev/null and b/data/images/Going Cars/GC6.png differ diff --git a/data/images/Going Cars/GC7.png b/data/images/Going Cars/GC7.png new file mode 100644 index 0000000..6279978 Binary files /dev/null and b/data/images/Going Cars/GC7.png differ diff --git a/data/images/Going Cars/GC8.png b/data/images/Going Cars/GC8.png new file mode 100644 index 0000000..401de16 Binary files /dev/null and b/data/images/Going Cars/GC8.png differ diff --git a/data/images/Going Cars/GC9.png b/data/images/Going Cars/GC9.png new file mode 100644 index 0000000..3a4a03f Binary files /dev/null and b/data/images/Going Cars/GC9.png differ diff --git a/data/images/LeftDisplay.png b/data/images/LeftDisplay.png new file mode 100644 index 0000000..ff30950 Binary files /dev/null and b/data/images/LeftDisplay.png differ diff --git a/data/images/RightDisplay.png b/data/images/RightDisplay.png new file mode 100644 index 0000000..48f0828 Binary files /dev/null and b/data/images/RightDisplay.png differ diff --git a/data/images/Road.png b/data/images/Road.png new file mode 100644 index 0000000..1820217 Binary files /dev/null and b/data/images/Road.png differ diff --git a/data/images/Sand.jpg b/data/images/Sand.jpg new file mode 100644 index 0000000..b6f640e Binary files /dev/null and b/data/images/Sand.jpg differ diff --git a/data/images/Strip.png b/data/images/Strip.png new file mode 100644 index 0000000..fad42aa Binary files /dev/null and b/data/images/Strip.png differ diff --git a/data/images/Tree.png b/data/images/Tree.png new file mode 100644 index 0000000..4aa382c Binary files /dev/null and b/data/images/Tree.png differ diff --git a/generator.py b/generator.py deleted file mode 100644 index 3bcfa99..0000000 --- a/generator.py +++ /dev/null @@ -1,100 +0,0 @@ -import random -import copy - -# firstBoard = [ -# [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, 0, 0, 0, 0, 0, 0, 0, 0], -# [0, 0, 0, 0, 0, 0, 0, 0, 0] -# ] - - -def printBoard(board): - for i in range(len(board)): - if i % 3 == 0 and i != 0: - print("- - - - - - - - - - - -") - for j in range(len(board[0])): - if j % 3 == 0 and j != 0: - print(" | ", end="") - if j == 8: # end of the row - print(board[i][j]) - else: - print(str(board[i][j]) + " ", end="") - - -def findEmpty(board): - for y in range(len(board)): - for x in range(len(board[0])): - if board[y][x] == 0: - return y, x # y = row , x = column - # if we got here it mean that we finish the sudoku, so return none - return None - - -def validCheck(board, number, coordinates): - # checking row - for x in range(len(board[0])): - if number == board[coordinates[0]][x] and coordinates[1] != x: # coordinates[0]= row - return False - - # checking column - for y in range(len(board)): - if number == board[y][coordinates[1]] and coordinates[0] != y: - return False - - # checking the box - box_x = coordinates[1] // 3 - box_y = coordinates[0] // 3 - - for y in range(box_y * 3, box_y * 3 + 3): - for x in range(box_x * 3, box_x * 3 + 3): - if number == board[y][x] and (y, x) != coordinates: - return False - - return True - - -def generateRandomBoard(board): - # end condition:- getting to the end of the board - the function findEmpty return NONE - find = findEmpty(board) - if find is None: # if find != False - return True - else: - row, col = find - for number in range(1, 10): - randomNumber = random.randint(1, 9) # TODO: need to work on the algorithm a bit more - - # TODO: to not rand the same number over and over again - if validCheck(board, randomNumber, (row, col)): - board[row][col] = randomNumber - if generateRandomBoard(board): - return True - - board[row][col] = 0 - return False - - -def deleteCells(firstBoard,number): - while number: - row = random.randint(0, 8) - col = random.randint(0, 8) - if firstBoard[row][col] != 0: - firstBoard[row][col] = 0 - number = number - 1 - - -def sudokuGenerate(firstBoard, level): - - # printBoard(firstBoard) - generateRandomBoard(firstBoard) - # printBoard(firstBoard) - if level == 1: - deleteCells(firstBoard,30) - if level == 2: - deleteCells(firstBoard,40) - if level == 3: - deleteCells(firstBoard,50) diff --git a/gifs/playing the game.gif b/gifs/playing the game.gif deleted file mode 100644 index 81f9aac..0000000 Binary files a/gifs/playing the game.gif and /dev/null differ diff --git a/gifs/start the game.gif b/gifs/start the game.gif deleted file mode 100644 index b21b4a9..0000000 Binary files a/gifs/start the game.gif and /dev/null differ diff --git a/gui.py b/gui.py deleted file mode 100644 index 295813f..0000000 --- a/gui.py +++ /dev/null @@ -1,199 +0,0 @@ -import pygame -from sudokuSolver import * -from chooseLevel import * -import time - -# Define some colors -BLACK = (0, 0, 0) -WHITE = (255, 255, 255) -GREEN = (0, 255, 0) -L_GREEN = (150, 255, 150) -RED = (255, 0, 0) -L_RED = (255, 204, 203) -GRAY = (60, 60, 60) -L_GRAY = (220, 220, 220) -YELLOW = (255, 255, 0) - -# This sets the WIDTH and HEIGHT of each grid location -WIDTH = HEIGHT = 50 - -# This sets the margin between each cell -MARGIN = 5 -numbers_1to9 = [pygame.K_1, pygame.K_2, pygame.K_3, pygame.K_4, pygame.K_5, pygame.K_6, pygame.K_7, pygame.K_8, - pygame.K_9] - -# Set the width and height of the screen [width, height] -size = (500, 500) -# screen = pygame.display.set_mode(size) -pygame.init() -font = pygame.font.Font('freesansbold.ttf', 32) - -# pygame.display.set_caption("Sudoku King") - -# Loop until the user clicks the close button. -done = False - - -def cheatingAllTheWay(): - for row in range(len(Board)): - for column in range(len(Board[row])): - Board[row][column] = solvedBoard[row][column] - addNumToBoard(Board[row][column], row, column, L_GREEN) - time.sleep(0.05) - pygame.display.flip() - finish() - - -def addNumToBoard(number, row, column, color): - addNewRect(row, column, WHITE, 5) - addNewRect(row, column, color, None) - font = pygame.font.Font('freesansbold.ttf', 32) - text = font.render(str(number), True, BLACK, ) - textRect = text.get_rect() # get_rect() -> Returns a new rectangle covering the entire surface. - textRect.center = ((MARGIN + WIDTH) * column + MARGIN + WIDTH / 2, (MARGIN + HEIGHT) * row + MARGIN + WIDTH / 2) - screen.blit(text, textRect) - drawTheBorder() - - -def finish(): - if solvedBoard == Board: - print("good") - else: - print("not good") - - -def addNewRect(row, col, color, width): - rectSize = pygame.Rect((MARGIN + WIDTH) * col + MARGIN, (MARGIN + HEIGHT) * row + MARGIN, WIDTH, - HEIGHT) - if width is not None: - pygame.draw.rect(screen, color, rectSize, width) # coloring only the border - else: - pygame.draw.rect(screen, color, rectSize) # coloring the whole rectangle - - -def flickering(timeFlickering, color): # flickering with color on-off - addNewRect(row, column, color, 5) - pygame.display.flip() - time.sleep(timeFlickering) - addNewRect(row, column, WHITE, 5) - pygame.display.flip() - time.sleep(timeFlickering) - addNewRect(row, column, color, 5) - pygame.display.flip() - time.sleep(timeFlickering) - addNewRect(row, column, WHITE, 5) - pygame.display.flip() - - -def drawTheBorder(): - dif = 500 // 9 - for i in range(10): - thick = 5 - pygame.draw.line(screen, GRAY, (0, i * dif + 2), (500, i * dif + 2), thick) - pygame.draw.line(screen, GRAY, (i * dif + 2, 0), (i * dif + 2, 500), thick) - for i in range(10): - if i % 3 == 0: - thick = 8 - pygame.draw.line(screen, BLACK, (0, i * dif), (500, i * dif), thick) - pygame.draw.line(screen, BLACK, (i * dif, 0), (i * dif, 500), thick) - - -def drawInitBoard(): - # printBoard(solvedBoard) - for row in range(len(Board)): - for column in range(len(Board[row])): - color = L_GRAY - if Board[row][column] == 0: # if we want to change to background of the empty cells - color = WHITE - # ----- drawing the rect ------ - pygame.draw.rect(screen, color, - [(MARGIN + WIDTH) * column + MARGIN, (MARGIN + HEIGHT) * row + MARGIN, WIDTH, HEIGHT]) - # show nothing if the number is 0 - font = pygame.font.Font('freesansbold.ttf', 32) - if Board[row][column] == 0: - text = font.render(" ", True, BLACK, ) # render(text, anti-alias[True], color, background=None) - else: - text = font.render(str(Board[row][column]), True, BLACK, ) - - textRect = text.get_rect() # get_rect() -> Returns a new rectangle covering the entire surface. - textRect.center = ( - (MARGIN + WIDTH) * column + MARGIN + WIDTH / 2, (MARGIN + HEIGHT) * row + MARGIN + WIDTH / 2) - screen.blit(text, textRect) - drawTheBorder() - - -# -------- Main Program Loop ----------- -if __name__ == "__main__": - flag1 = True - - while flag1: - level = chooseLevel() - if level == 1 or level == 2 or level == 3: - print(level) - flag1 = False - pygame.display.set_caption("Sudoku King1") - screen = pygame.display.set_mode(size) - - sol = mainSolver(level) # first at all the script solve the sudoku by itself - - print("solveBoard") - printBoard(sol) - - # ------ draw the board ------ - pygame.init() - screen.fill(BLACK) - drawInitBoard() - readyForInput = False - key = None - while not done: - # --- Main event loop - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - done = True - if event.type == pygame.KEYDOWN: - if event.key in numbers_1to9: - key = chr(event.key) - if event.key == pygame.K_RETURN: - finish() - if event.key == pygame.K_c: - cheatingAllTheWay() - if event.type == pygame.MOUSEBUTTONDOWN: - # ------ if clicked on a cell get his row and column ------ - if readyForInput is True: - addNewRect(row, column, WHITE, None) - drawTheBorder() - readyForInput = False - - pos = pygame.mouse.get_pos() - column = pos[0] // (WIDTH + MARGIN) - row = pos[1] // (WIDTH + MARGIN) - # ------ checking if it is a empty (0 inside) ------ - if Board[row][column] == 0: - # ------ coloring the border of the clicked cell ----- #TODO YELLOW - - addNewRect(row, column, YELLOW, 5) - readyForInput = True - # ------ now only wait for input from the user ----- - - if readyForInput and key is not None: - # ------ checking if the key is good at it's place ------ - if int(key) == sol[row][column]: - Board[row][column] = key - flickering(0.1, GREEN) # flickering at a 0.2 seconds with the color green - addNumToBoard(key, row, column, L_GREEN) - else: - flickering(0.1, RED) # flickering at a 0.2 seconds with the color red - addNumToBoard(key, row, column, L_RED) - - # ----------------------------------------------- - drawTheBorder() - readyForInput = False - - key = None - pygame.display.flip() - pygame.display.update() - - -# Close the window and quit. -pygame.quit() diff --git a/images/choosing difficulty level.PNG b/images/choosing difficulty level.PNG deleted file mode 100644 index f6cbf34..0000000 Binary files a/images/choosing difficulty level.PNG and /dev/null differ diff --git a/images/gaming.PNG b/images/gaming.PNG deleted file mode 100644 index 5a457cd..0000000 Binary files a/images/gaming.PNG and /dev/null differ diff --git a/images/playing the game.PNG b/images/playing the game.PNG deleted file mode 100644 index a52e39e..0000000 Binary files a/images/playing the game.PNG and /dev/null differ diff --git a/speed.py b/speed.py new file mode 100644 index 0000000..b797d61 --- /dev/null +++ b/speed.py @@ -0,0 +1,395 @@ +import pygame +import time +import random +import os + +pygame.init() +pygame.mixer.init() + +gameWindow = pygame.display.set_mode((1200,700)) +pygame.display.set_caption("Speed Racer") + +clock = pygame.time.Clock() +fps = 60 + +font1 = pygame.font.SysFont("Franklin Gothic Demi Cond",50) + +car = pygame.image.load("data/images/Car.png") +car = pygame.transform.scale(car,(150,150)).convert_alpha() + +road = pygame.image.load("data/images/Road.png") +road = pygame.transform.scale(road,(400,700)).convert_alpha() + +sand = pygame.image.load("data/images/Sand.jpg") +sand = pygame.transform.scale(sand,(150,700)).convert_alpha() + +leftDisp = pygame.image.load("data/images/LeftDisplay.png") +leftDisp = pygame.transform.scale(leftDisp,(250,700)).convert_alpha() + +rightDisp = pygame.image.load("data/images/RightDisplay.png") +rightDisp = pygame.transform.scale(rightDisp,(250,700)).convert_alpha() + +tree = pygame.image.load("data/images/Tree.png") +tree = pygame.transform.scale(tree,(185,168)).convert_alpha() +treeLXY = [[290,0],[290,152.5],[290,305],[290,457.5],[290,610]] +treeRXY = [[760,0],[760,152.5],[760,305],[760,457.5],[760,610]] + +strip = pygame.image.load("data/images/Strip.png") +strip = pygame.transform.scale(strip,(25,90)).convert_alpha() +stripXY = [[593,0],[593,152.5],[593,305],[593,457.5],[593,610]] + +explosion = pygame.image.load("data/images/Explosion.png") +explosion = pygame.transform.scale(explosion,(290,164)).convert_alpha() + +fuel = pygame.image.load("data/images/Fuel.png") +fuel = pygame.transform.scale(fuel,(98,104)).convert_alpha() + +comingCars,goingCars = [],[] +speedCC = [13,14,15,14,14,15,13,14,15] +speedGC = [8,6,7,5,8,7,8,6,8] + +for i in range(1,10): + CCi = pygame.image.load("data/images/Coming Cars/"+"CC"+str(i)+".png") + CCi = pygame.transform.scale(CCi, (75, 158)).convert_alpha() + comingCars.append([CCi,speedCC[i-1]]) + GCi = pygame.image.load("data/images/Going Cars/"+"GC"+str(i)+".png").convert_alpha() + GCi = pygame.transform.scale(GCi,(75,158)).convert_alpha() + goingCars.append([GCi,speedGC[i-1]]) + +def distance(carX,obstX,carY,obstY,isFuel = False): + + if not isFuel: + carX += 75 # 75,75,37,79,55,130 + carY += 75 + obstX += 37 + obstY += 79 + + return abs(carX - obstX) < 55 and abs(carY - obstY) < 130 + else: + carX += 75 + carY += 75 + obstX += 98 + obstY += 104 + + return abs(carX - obstX) < 70 and abs(carY - obstY) < 80 + +def textOnScreen(text,color,x,y,font): + screenText = font.render(text,True,color) + gameWindow.blit(screenText,[x,y]) + +def slowDown(carX,carY,dist,highscore): + + stripXY_ = [[593, 0], [593, 152.5], [593, 305], [593, 457.5], [593, 610]] + exitScreen = False + + stripSpeed = 2 + + start = time.time() + while not exitScreen: + if time.time() - start > 3: + stripSpeed = 1 + if time.time() - start > 6: + exitScreen = True + for event in pygame.event.get(): + if event.type == pygame.QUIT: + exitScreen = True + + gameWindow.fill((0,0,0)) + gameWindow.blit(leftDisp, (0, 0)) + textOnScreen("DISTANCE", (255, 255, 0), 27, 388, font1) + textOnScreen(str(dist) + " Kms", (255, 0, 0), 56, 480, font1) + textOnScreen("FUEL", (255, 255, 0), 73, 90, font1) + textOnScreen(str(0.00) + ' %', (255, 0, 0), 75, 184, font1) + gameWindow.blit(rightDisp, (950, 0)) + textOnScreen("HIGHSCORE", (255, 255, 0), 958, 236, font1) + if(highscore < 10): + disp = str(0) + str(highscore) + else: + disp = str(highscore) + textOnScreen(disp + " Kms", (255, 0, 0), 1005, 342, font1) + gameWindow.blit(road, (400, 0)) + gameWindow.blit(sand,(250,0)) + gameWindow.blit(sand,(800,0)) + + for i in range(len(stripXY_)): + stripXY_[i][1] += stripSpeed + if stripXY_[i][1] > 700: + stripXY_[i] = [593, -60] + for i in range(len(treeLXY)): + treeLXY[i][1] += stripSpeed + if treeLXY[i][1] > 700: + treeLXY[i] = [290,-60] + for i in range(len(treeRXY)): + treeRXY[i][1] += stripSpeed + if treeRXY[i][1] > 700: + treeRXY[i] = [760,-60] + + for X,Y in stripXY_: + gameWindow.blit(strip,(X,Y)) + for treeX,treeY in treeLXY: + gameWindow.blit(tree,(treeX,treeY)) + for treeX,treeY in treeRXY: + gameWindow.blit(tree,(treeX,treeY)) + + gameWindow.blit(car,(carX,carY)) + pygame.display.update() + +def gameLoop(): + + pygame.mixer.music.load("data/audios/game.mp3") + pygame.mixer.music.play() + + time.sleep(1) + + carX,carY = 625,540 + drift = 4 + carSpeedX = 0 + + obstacleXY = [[460,-10],[710,-300]] + c1,c2 = random.randint(0,8),random.randint(0,8) + if(c1 == c2): + c1 = random.randint(0,8) + + obstacleSpeed = [comingCars[c1][1],goingCars[c2][1]] + obstacles = [comingCars[c1][0],goingCars[c2][0]] + + stripSpeed = 9 + + exitGame = False + gameOver = False + explode = False + + fuelCount = 50 + fuelX,fuelY = random.randint(420,620),-1000 + fuelSpeed = 8 + dist = 0 + + with open("data/Highscore.txt","r") as f: + highscore = int(f.read()) + + slow = False + plotFuel = True + + start1 = time.time() + start = [start1,start1] + start2 = start1 + start3 = start1 + start4 = start1 + arrival = [2,3.5] + + while not exitGame: + if gameOver: + + if slow: + slowDown(carX,carY,dist,highscore) + time.sleep(2) + + pygame.mixer.music.stop() + pygame.mixer.music.load("data/audios/rtn.mp3") + pygame.mixer.music.play() + + exitScreen = False + go = pygame.image.load("data/images/GameOver.png") + go = pygame.transform.scale(go,(1239,752)).convert_alpha() + + with open("data/Highscore.txt","w") as f: + f.write(str(highscore)) + + while not exitScreen: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + exitScreen = True + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_RETURN: + pygame.mixer.music.stop() + homeScreen() + gameWindow.fill((0,0,0)) + gameWindow.blit(go,(0,0)) + if(dist < 10): + disp = str(0) + str(dist) + else: + disp = str(dist) + textOnScreen(disp,(255,0,0),540,429,font1) + pygame.display.update() + clock.tick(fps) + + pygame.quit() + quit() + else: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + exitGame = True + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_RIGHT: + carSpeedX = drift + elif event.key == pygame.K_LEFT: + carSpeedX = -drift + elif event.key == pygame.K_a: + obstacleXY[0][0] -= 20 + elif event.key == pygame.K_d: + obstacleXY[1][0] += 20 + + carX += carSpeedX + fuelY += fuelSpeed + + if time.time() - start4 >= 2: + dist += 1 + if dist > highscore: + highscore = dist + start4 = time.time() + + if time.time() - start2 >= 3: + fuelCount -= 5 + start2 = time.time() + + if distance(carX,fuelX,carY,fuelY,True) and plotFuel: + plotFuel = False + fuelCount += 20 + + for i in range(len(obstacleXY)): + obstacleXY[i][1] += obstacleSpeed[i] + + fuelper = fuelCount/50 + if fuelper >= 1: + fuelper = 1 + + gameWindow.fill((0,0,0)) + gameWindow.blit(leftDisp,(0,0)) + textOnScreen("DISTANCE", (255, 255, 0),27,388,font1) + if(dist < 10): + disp = str(0) + str(dist) + else: + disp = str(dist) + textOnScreen(disp + " Kms",(255,0,0),56,480,font1) + textOnScreen("FUEL",(255,255,0),73,90,font1) + textOnScreen(str(fuelper*100) + ' %',(255,0,0),60,184,font1) + gameWindow.blit(rightDisp, (950, 0)) + textOnScreen("HIGHSCORE",(255,255,0),958,236,font1) + if(highscore < 10): + disp = str(0) + str(highscore) + else: + disp = str(highscore) + textOnScreen(disp + " Kms",(255,0,0),1005,342,font1) + gameWindow.blit(road,(400,0)) + gameWindow.blit(sand, (250, 0)) + gameWindow.blit(sand, (800, 0)) + + if fuelCount == 0: + gameOver = True + slow = True + + if carX > 720 or carX < 330: + pygame.mixer.music.load("data/audios/Crash.mp3") + pygame.mixer.music.play() + gameOver = True + explode = True + + for i in range(len(obstacleXY)): + if distance(carX,obstacleXY[i][0],carY,obstacleXY[i][1]): + pygame.mixer.music.load("data/audios/Crash.mp3") + pygame.mixer.music.play() + gameOver = True + explode = True + break + for i in range(len(stripXY)): + stripXY[i][1] += stripSpeed + if stripXY[i][1] > 700: + stripXY[i] = [593,-60] + for i in range(len(treeLXY)): + treeLXY[i][1] += stripSpeed + if treeLXY[i][1] > 700: + treeLXY[i] = [290, -60] + for i in range(len(treeRXY)): + treeRXY[i][1] += stripSpeed + if treeRXY[i][1] > 700: + treeRXY[i] = [760, -60] + + for stripX,stripY in stripXY: + gameWindow.blit(strip,(stripX,stripY)) + + if fuelY < 750: + if plotFuel: + gameWindow.blit(fuel,(fuelX,fuelY)) + + gameWindow.blit(car,(carX,carY)) + + for i in range(len(obstacleXY)): + if obstacleXY[i][1] < 750: + gameWindow.blit(obstacles[i],(obstacleXY[i][0], obstacleXY[i][1])) + + for treeX, treeY in treeLXY: + gameWindow.blit(tree, (treeX, treeY)) + for treeX, treeY in treeRXY: + gameWindow.blit(tree, (treeX, treeY)) + + if time.time() - start[0] >= arrival[0]: + x = random.randint(430,530) + x+=3 + obstacleXY[0] = [x,-10] + c1 = random.randint(0,8) + obstacles[0] = comingCars[c1][0] + obstacleSpeed[0] = comingCars[c1][1] + start[0] = time.time() + if time.time() - start[1] >= arrival[1]: + x = random.randint(620,710) + x-=3 + obstacleXY[1] = [x,-10] + c2 = random.randint(0,8) + obstacles[1] = goingCars[c2][0] + obstacleSpeed[1] = goingCars[c2][1] + start[1] = time.time() + if time.time() - start3 >= 15: + fuelX,fuelY = random.randint(420,710),-500 + plotFuel = True + start3 = time.time() + if explode: + gameWindow.blit(explosion,(carX - 63,carY)) + + pygame.display.update() + clock.tick(fps) + + + pygame.quit() + quit() + +def homeScreen(): + + pygame.mixer.music.load("data/audios/rtn.mp3") + pygame.mixer.music.play() + + if not os.path.exists("data/Highscore.txt"): + with open("data/Highscore.txt","w") as f: + f.write("0") + highscore = 0 + else: + with open("data/Highscore.txt","r") as f: + highscore = int(f.read()) + + + background = pygame.image.load("data/images/Background.png") + background = pygame.transform.scale(background,(1213,760)).convert_alpha() + + exitScreen = False + while not exitScreen: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + exitScreen = True + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_RETURN: + pygame.mixer.music.stop() + gameLoop() + + gameWindow.blit(background,(-6,-32)) + if(highscore < 10): + disp = str(0) + str(highscore) + else: + disp = str(highscore) + textOnScreen(disp,(255,0,0),980,9,font1) + pygame.display.update() + clock.tick(fps) + + pygame.quit() + quit() + + +homeScreen() diff --git a/sudokuSolver.py b/sudokuSolver.py deleted file mode 100644 index b0970e9..0000000 --- a/sudokuSolver.py +++ /dev/null @@ -1,45 +0,0 @@ -import copy -from generator import * - -# -------- Global board ---------------- - -Board = [ - [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, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0] - ] - -solvedBoard = copy.deepcopy(Board) - -def solve(board): - # end condition:- getting to the end of the board - the function findEmpty return NONE - find = findEmpty(board) - if find is None: # if find != False - return True - else: - row, col = find - for number in range(1, 10): - if validCheck(board, number, (row, col)): - board[row][col] = number - # TODO: need to show it on the GUI - - if solve(board): - return True - - board[row][col] = 0 - # TODO: delete the number in the GUI - return False - - -def mainSolver(level): - sudokuGenerate(Board, level) - solvedBoard = copy.deepcopy(Board) - solve(solvedBoard) - return solvedBoard - \ No newline at end of file