diff --git a/CHANGELOG.txt b/CHANGELOG.txt deleted file mode 100644 index 3f2c71b..0000000 --- a/CHANGELOG.txt +++ /dev/null @@ -1,113 +0,0 @@ -V1.0 -Original Release - -V1.0.1 -Bug fix for turtle shut down when at 20 score - -V1.1 -Maroon bg, score changes by 1, save high score, new packaging - -V1.1.1 -New color and shape options for food, manual kill dev tool press "r" - -V1.1.2 -Added and removed colors for food, removed "classic" shape for food, changed bg color, added arrow key functionality, small performance optimizations - -V1.1.3 -Food sort of snaps to places where snake can go, fixed bug where snake doesn't work with wsad when caps log is on, hot fix for snake game crashing on some computers - -V1.1.4 -Changed background color and food colors, various bug fixes - -V1.2 -Added ability to configure background and food colors with snakeconfig.py, bug fixes, added SOUNDS! - -V1.2.1 -Packaging changes - -V1.2.2 -Can choose shape in configurator - -V1.2.3 -Optimizations and bug fixes - -V1.2.4 -Preview of 1.3, no new features - -V1.2.5 -Minor bug fixes and improvements - -V1.3 -Finally added smoothness and framerate - -V1.3.1 -More framerate and fixed bug where high score is not written properly -Known bug: Head of snake gets partially covered by segments when appended - -V1.4.0 -Added second food! This re-writes almost all of food generation. I will make it possible to have the second optional and maybe more later! - -V1.4.1 -Packaging changes - -V1.5.0 -API (data) added - -V1.5.1 -More precision added to recorded data - -V1.6.0 -fix bug where snake length doesnt reset when killed with running into self. Second food is now optional. - -V1.6.1 -Fix bug where game crashes when api turned on - -V1.7.0 - bug fixes and Data rework -Fixed 2 minor bugs -Moved API to a second thread to avoid slowing down the game on older computers - -V1.7.1 -Fix data.txt - -V1.7.2 -Fix bug where API not working because it does not recognize 2 foods option - -V1.8.0 -Add option to recolor/customize the snake head and tail. Press 8 to open the configurator! - -V1.8r2 -If error in snakeprefs.txt, will now reset to default values. - -V1.9.0 -Added/implemented sounds and ability to mute - -V1.9.1 -Fixed toggling mute - -V1.9.2 -Last muted or not is now saved - -V1.10.0 -Implemented json saving for the high score. Background and other options are coming to json swell in the near future (hopefully). - -V1.10.1 -Added more things to prefs.json, modified configuartor - -V1.10.2 -Added snake preferences to prefs.json and modified configurator - -V1.10.3 -Cleaned up some things and added wininstall.sh - -V1.11.0 -check for python version compatibility -Windows installation script and update Mac OS version - -V1.12.0 -Add window close on escape key -Optimize startup process -Fix devtoolreset -Ability to toggle api as opposed to only able to be turned on -Add smash sound when snake hits self - -THIS DOCUMENT IS NO LONGER USED AS OF 1.13.0, REFER TO GITHUB FOR CHANGELOG diff --git a/README.md b/README.md index cf43dba..9b0ef1f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# Snake Game +# Snake Game v2 ## Instructions ### Requirements #### Python -Version 3.6 or newer, (Python 2 does not work, same as python 3 earlier than 3.6). +Version 3.6 or newer, (Python 2 does not work, same as Python 3 earlier than 3.6). #### Tested versions: 3.5.10 (not working) @@ -22,12 +22,12 @@ Version 3.6 or newer, (Python 2 does not work, same as python 3 earlier than 3.6 3.11a5+ #### OS -Tested on Mac OS and Windows 10 only. +Tested on Mac OS and Windows 10 and 11 only. ### Launching Game To run game: MACOS: Open launcher -Windows: Open turtlesnake.py with python +Windows: Open launch-win.exe ### Configuring prefrences @@ -49,7 +49,4 @@ curl https://raw.githubusercontent.com/AviationSFO/SnakeGame/master/install.sh | ``` ## Windows -Copy and paste the following code into the windows terminal to install -```shell -curl https://raw.githubusercontent.com/AviationSFO/SnakeGame/master/wininstall.sh | bash -``` \ No newline at end of file +Download source code from latest release \ No newline at end of file diff --git a/launch-win.cpp b/launch-win.cpp new file mode 100644 index 0000000..2e307ad --- /dev/null +++ b/launch-win.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main() +{ + system("python turtlesnake.py"); + return 0; +} \ No newline at end of file diff --git a/launch-win.exe b/launch-win.exe new file mode 100644 index 0000000..f73f9dc Binary files /dev/null and b/launch-win.exe differ diff --git a/prefs.json b/prefs.json index c97e96b..e86ac08 100644 --- a/prefs.json +++ b/prefs.json @@ -1,10 +1 @@ -{ - "highscore": 0, - "bgcolor": "dark green", - "foodcolor": "navy", - "foodshape": "square", - "foodnum": 2, - "mutesound": true, - "headcolor": "white", - "tailcolor": "blue" -} \ No newline at end of file +{"highscore": 0, "bgcolor": "dark green", "foodcolor": "dark red", "foodshape": "circle", "foodnum": 2, "mutesound": true, "headcolor": "white", "tailcolor": "#13325e"} \ No newline at end of file diff --git a/snakeconfig.py b/snakeconfig.py index 4aa403a..4b3f28a 100644 --- a/snakeconfig.py +++ b/snakeconfig.py @@ -1,26 +1,16 @@ -#Turtle Snake Game color and shape congigurator for 1.10.1 and newer on 2-8-2022 By Steven Weinstein -import json +#Turtle Snake Game color and shape congigurator for 2.0.0 and newer on 8-8-2022 By Steven Weinstein -def config(): - import os +def config(script_path): import json - prefs = { - "highscore": 0, - "bgcolor": "dark green", - "foodcolor": "navy", - "foodshape": "square", - "foodnum": 2, - "mutesound": True -} + prefs = {"highscore": 0, "bgcolor": "dark green", "foodcolor": "dark red", "foodshape": "circle", "foodnum": 2, "mutesound": True, "headcolor": "white", "tailcolor": "#13325e"} print('''Color Configurator enter a hex code or an accepted color name from this list: https://trinket.io/docs/colors NO RGB VALUES''') prefs["bgcolor"] = input("What color would you like the background: ") prefs["foodcolor"] = input("What color would you like the food: ") prefs["foodshape"] = input("Food shape: circle square triange or turtle: ") prefs["foodnum"] = input("Would you like to have 1 or 2 foods: ") - with open(os.path.expanduser( - "~/Desktop/SnakeGame/prefs.json"), "w") as write_file: + with open(script_path.joinpath("prefs.json"), "w") as write_file: json.dump(prefs, write_file) # writing to text document print("Succesfuly configured!\nYou will have to restart the game for changes to take effect.") @@ -28,23 +18,14 @@ def config(): changedcolor = True return -def snakecolor(): - import os +def snakecolor(script_path): import json - prefs = { - "highscore": 0, - "bgcolor": "dark green", - "foodcolor": "navy", - "foodshape": "square", - "foodnum": 2, - "mutesound": True - } + prefs = {"highscore": 0, "bgcolor": "dark green", "foodcolor": "dark red", "foodshape": "circle", "foodnum": 2, "mutesound": True, "headcolor": "white", "tailcolor": "#13325e"} print('''Color Configurator enter a hex code or an accepted color name from this list: https://trinket.io/docs/colors NO RGB VALUES''') prefs["headcolor"] = input("What color would you like the snake head: ") prefs["tailcolor"] = input("What color would you like the snake tail: ") - with open(os.path.expanduser( - "~/Desktop/SnakeGame/prefs.json"), "w") as write_file: + with open(script_path.joinpath("prefs.json"), "w") as write_file: json.dump(prefs, write_file) # writing to text document print("Succesfuly configured!\nYou will have to restart the game for changes to take effect.") @@ -52,11 +33,9 @@ def snakecolor(): changedcolor = True return -def snakereset(): - import os +def snakereset(script_path): print("\n\n\tvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nThere was an error in the snake color file.\nReseting the document...\n\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n") - file = open(os.path.expanduser( - "~/Desktop/SnakeGame/snakeprefs.txt"), "w") + file = open(script_path.joinpath("snakeprefs.txt"), "w") colorhd = "white" colortl = "blue" file.write(f"{colorhd}\n{colortl}") \ No newline at end of file diff --git a/snakeprefs.txt b/snakeprefs.txt deleted file mode 100644 index 58b9112..0000000 --- a/snakeprefs.txt +++ /dev/null @@ -1,2 +0,0 @@ -white -blue \ No newline at end of file diff --git a/turtlesnake.py b/turtlesnake.py index 086a5da..5b47103 100644 --- a/turtlesnake.py +++ b/turtlesnake.py @@ -1,14 +1,15 @@ -# Python Snake Game by Steven Weinstein on 7-17-2022. Version available in version.txt +# Python Snake Game by Steven Weinstein on 8-8-2022. Version available in version.txt # import required modules TK_SILENCE_DEPRECATION = 1 from platform import python_version import json import threading as thr import snakeconfig -from os import path from random import randint, choice from time import sleep import turtle +from pathlib import Path +script_path = Path(__file__, '..').resolve() # checking if python version is compatible pyversion = python_version() print("Your python version is:") @@ -18,8 +19,8 @@ "3.7" in pyversion or "3.8" in pyversion or "3.9" in pyversion or - "3.10" in pyversion # or - # "3.11" in pyversion: + "3.10" in pyversion or + "3.11" in pyversion ): print("Python version check pass") else: @@ -42,13 +43,14 @@ "tailcolor": "blue" } try: - from playsound import playsound + from pygame import mixer noplaysound = False + mixer.init() except: noplaysound = True global high_score global mutesound -with open("prefs.json", "r") as read_file: +with open(script_path.joinpath("prefs.json"), "r") as read_file: prefs = json.load(read_file) high_score = prefs["highscore"] bgcolor = prefs["bgcolor"] @@ -65,7 +67,7 @@ score = 0 APIon = False # opening files -datadoc = open("data.txt", "a") +datadoc = open(script_path.joinpath("data.txt"), "a") foodnum = int(foodnum) if foodnum == 2: @@ -81,7 +83,7 @@ print("Error: last highscore is not an integer.") wn = turtle.Screen() -wn.title("Snake Game Project v1.13.1") +wn.title("Snake Game Project v2.0.0") wn.bgcolor(bgcolor) # the width and height can be put as user's choice wn.setup(width=600, height=600) @@ -178,8 +180,7 @@ def DEVTOOLRESET(): prefs = { "highscore": 0, } - with open(path.expanduser( - "~/Desktop/SnakeGame/prefs.json"), "w") as write_file: + with open(script_path.joinpath("prefs.json"), "w") as write_file: json.dump(prefs, write_file) quit() @@ -219,7 +220,14 @@ def APIproc(): def playswallow(): if not noplaysound: - playsound(path.expanduser("~/Desktop/SnakeGame/extrafiles/swallow.mp3")) + mixer.music.load(script_path.joinpath("extrafiles/swallow.mp3")) + mixer.music.play() + + +def playsmash(): + if not noplaysound: + mixer.music.load(script_path.joinpath("extrafiles/smash.mp3")) + mixer.music.play() def togglemute(): @@ -245,8 +253,7 @@ def config(): prefs["foodcolor"] = input("What color would you like the food: ") prefs["foodshape"] = input("Food shape: circle square triange or turtle: ") prefs["foodnum"] = input("Would you like to have 1 or 2 foods: ") - with open(path.expanduser( - "~/Desktop/SnakeGame/prefs.json"), "w") as write_file: + with open(script_path.joinpath("prefs.json"), "w") as write_file: json.dump(prefs, write_file) # writing to text document print("Succesfuly configured!\nYou will have to restart the game for changes to take effect.") @@ -268,8 +275,7 @@ def snakecolor(): enter a hex code or an accepted color name from this list: https://trinket.io/docs/colors NO RGB VALUES''') prefs["headcolor"] = input("What color would you like the snake head: ") prefs["tailcolor"] = input("What color would you like the snake tail: ") - with open(path.expanduser( - "~/Desktop/SnakeGame/prefs.json"), "w") as write_file: + with open(script_path.joinpath("prefs.json"), "w") as write_file: json.dump(prefs, write_file) # writing to text document print("Succesfuly configured!\nYou will have to restart the game for changes to take effect.") @@ -312,6 +318,8 @@ def exit(): while True: wn.update() if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290: + if not mutesound: + playsmash() sleep(1) head.goto(0, 0) head.direction = "Stop" @@ -340,7 +348,7 @@ def exit(): try: new_segment.color(tailcolor) except: - snakeconfig.snakereset() + snakeconfig.snakereset(script_path) quit() new_segment.penup() segments.append(new_segment) @@ -358,10 +366,7 @@ def exit(): x2 = round(randint(-270, 270), 24) y2 = round(randint(-270, 270), 24) if mutesound == False: - if __name__ == '__main__': - # creating thread - soundt = thr.Thread(target=playswallow, args=()) - soundt.start() + playswallow() food2.goto(x2, y2) # Adding segment @@ -396,9 +401,8 @@ def exit(): move() for segment in segments: if segment.distance(head) < movepertick: - if not noplaysound: - playsound(path.expanduser( - "~/Desktop/SnakeGame/extrafiles/smash.mp3")) + if mutesound == False: + playsmash() head.goto(0, 600) sleep(delay) sleep(1) @@ -434,7 +438,7 @@ def exit(): } if changedcolor == False: - with open("prefs.json", "w") as write_file: + with open(script_path.joinpath("prefs.json"), "w") as write_file: json.dump(prefs, write_file) else: quit() diff --git a/version.txt b/version.txt index 2a82924..6eaf894 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -Version STABLE v1.13.1 \ No newline at end of file +v2.0.0 \ No newline at end of file