diff --git a/img/indexpy.PNG b/img/indexpy.PNG index d72a517..cdd56ef 100644 Binary files a/img/indexpy.PNG and b/img/indexpy.PNG differ diff --git a/readme.md b/readme.md index 49f9e8d..56052f0 100644 --- a/readme.md +++ b/readme.md @@ -7,8 +7,9 @@ And you can also play with it. To run this game, you can clone the repository by typing this in the command line: `git clone ` After cloning the repo, please run the **index.py** file first, otherwise it won't work.
-Now you choose between these options below:
-
+Now you choose between these options below: +
+
**y/n** (yes or no) or **cmds** for special commands. @@ -21,19 +22,14 @@ These are the **Python** modules that I used: + configparser + random + datetime -+ matplotlib (this is required to display scoreboard) ++ matplotlib + colorama + platform -#### Purposes of these modules? -+ os - checking if the *settings.ini* file exists -+ sys - to use the exit function -+ configparser - for making changes with the *settings.ini* file -+ random - randomizing actions -+ datetime - returning date and time -+ matplotlib - display scoreboard -+ colorama - colorize the terminal -+ platform - displaying system info and **Python** version +#### What *Python* modules are required to install? +These are modules are required to install before running this game: ++ matplotlib ++ colorama ## Documentation Coming Soon:) diff --git a/src/commands.py b/src/commands.py index 55455c7..05a0cf0 100644 --- a/src/commands.py +++ b/src/commands.py @@ -1,22 +1,22 @@ from os import path -from rps import play -from colorama import Fore, init, Style from configparser import ConfigParser -from platform import python_version, system +from colorama import Fore, init, Style +from rps import play +from console_colors import consolecolor init() + config = ConfigParser() -config.read('settings.ini') +config.read('./settings.ini') +# Colorama Variables -commands = ['toggle_nonstop', - 'changedatacolor', - 'currentdatacolor', - 'game', - 'changecharttype', - 'currentcharttype', - 'isitnonstop', - 'resetsettings'] +r = consolecolor +bright = Style.BRIGHT +critical = Fore.RED + bright +success = Fore.GREEN + bright +info = Fore.CYAN + bright +conf = Fore.YELLOW + bright chart_types = ['bar', 'dots', @@ -24,37 +24,38 @@ 'stem', 'step'] -# Colorama Variables - -r = Fore.RESET -bright = Style.BRIGHT -critical = Fore.RED + bright -success = Fore.GREEN + bright -info = Fore.CYAN + bright -conf = Fore.YELLOW + bright +console_colors = [ + 'red', + 'green', + 'blue', + 'cyan', + 'magenta', + 'white', + 'yellow' + ] # Commands def nonstop_toggle(): if path.exists('./settings.ini'): - print(conf + 'Turn on nonstop? (y/n)' + r) + print(conf + 'Turn on nonstop? (y/n)'+r) toggle = input().lower() if toggle == 'y': config.set('RPS', 'nonstop', 'True') with open ('settings.ini', 'w') as settingsfile: config.write(settingsfile) - print(success +'Nonstop set to True' + r) + print(success +'Nonstop set to True'+r) elif toggle == 'n': config.set('RPS', 'nonstop', 'False') with open ('settings.ini', 'w') as settingsfile: config.write(settingsfile) - print(success + 'Nonstop set to False' + r) + print(success + 'Nonstop set to False'+r) elif toggle == 'exit': return else: - print(critical + + 'Invalid option.') + print(critical + + 'Invalid option.'+r) else: - print(critical + 'Couldn\'t find settings.ini file' + r) + print(critical + 'Couldn\'t find settings.ini file'+r) def changedatacolor(): if path.exists('./settings.ini'): @@ -62,20 +63,20 @@ def changedatacolor(): if datachartcolor == "exit": return elif datachartcolor == '': - print(critical + 'Data color cannot be null.' + r) + print(critical + 'Data color cannot be null.'+r) else: config.set('Chart', 'datachartcolor', datachartcolor) with open ('settings.ini', 'w') as settingsfile: config.write(settingsfile) - print(success + 'Bar color updated successfully.' + r) + print(success + 'Bar color updated successfully.'+r) else: - print(critical + 'Couldn\'t find settings.ini file' + r) + print(critical + 'Couldn\'t find settings.ini file'+r) def currentdatacolor(): if path.exists('./settings.ini'): print(config.get('Chart', 'datachartcolor')) else: - print(critical + 'Couldn\'t find settings.ini file' + r) + print(critical + 'Couldn\'t find settings.ini file'+r) def game(): play() @@ -85,7 +86,7 @@ def currentcharttype(): if path.exists('./settings.ini'): print(config.get('Chart', 'chart_type')) else: - print(critical + 'Couldn\'t find settings.ini file' + r) + print(critical + 'Couldn\'t find settings.ini file'+r) def changecharttype(): if path.exists('./settings.ini'): @@ -93,16 +94,16 @@ def changecharttype(): if charttype == 'exit': return elif charttype not in chart_types: - print(critical + f"A chart type \"{charttype}\" doesn't exist." + r) + print(critical + f"A chart type \"{charttype}\" doesn't exist."+r) elif charttype == '': - print(critical + 'Chart type cannot be null.' + r) + print(critical + 'Chart type cannot be null.'+r) else: config.set('Chart', 'chart_type', charttype) with open('settings.ini', 'w') as settingsfile: config.write(settingsfile) - print(success + 'Chart type updated successfully.' + r) + print(success + 'Chart type updated successfully.'+r) else: - print(critical + 'Couldn\'t find settings.ini file' + r) + print(critical + 'Couldn\'t find settings.ini file'+r) def isitnonstop(): if path.exists('./settings.ini'): @@ -114,115 +115,46 @@ def isitnonstop(): else: print("Unknown") else: - print(critical + 'Couldn\'t find settings.ini file' + r) + print(critical + 'Couldn\'t find settings.ini file'+r) def resetsettings(): if path.exists('./settings.ini'): - print(conf + 'Are you sure? (y/n)' + r) + print(conf + 'Are you sure? (y/n)'+r) confirm = input() if confirm == "y" or confirm == "Y": config.set('Chart', 'chart_type', 'bar') config.set('Chart', 'datachartcolor', 'dodgerblue') config.set('RPS', 'nonstop', 'False') + config.set('Console', 'default_console_color', 'cyan') with open('settings.ini', 'w') as settingsfile: config.write(settingsfile) - print(success + 'Settings reset successfully.' + r) + print(success + 'Settings reset successfully.'+r) else: return else: - print(critical + 'Couldn\'t find settings.ini file' + r) - -# Commands with help - -def nonstop_toggle_help(): - print("Usage: rps toggle_nonstop \n") - print("Description: It prompts for turning the setting on or off. (i.e. nonstop is when the game will not prompt") - print("you to play the game again, instead it repeats the game instantly, but you can stop the game by typing \"stop\"") - - -def changedatacolor_help(): - print("Usage: rps changedatacolor \n") - print("Description: It prompts for changing the data color by hexcode or name of a color.") - print("Make sure you add the \"#\" before the hexcode, or specify an appropriate name of a color.") - - -def currentdatacolor_help(): - print("Usage: rps currentdatacolor \n") - print("Description: Returns the current data color.") - -def game_help(): - print("Usage: rps game \n") - print("Description: Plays the game.") - -def changecharttype_help(): - print("Usage: rps changecharttype \n") - print("Description: It prompts for changing the chart type.") - -def currentcharttype_help(): - print("Usage: rps currentcharttype \n") - print("Description: Returns the current chart type.") - -# Main cmd - -def cmd(): - print(""" - List of available commands: Prefix: rps - - changedatacolor - - toggle_nonstop - - currentdatacolor - - game - - changecharttype - - currentcharttype - - isitnonstop - - resetsettings - - Type \"rps \" to get started with the command. - or type \"rps usage \" to see the usage and description of a command.""") - while True: - com = input(">> ") - - if com == "exit": - break - elif com == "rps": - cmd() - elif com == 'game': - game() - elif com == 'python_version': - print(python_version()) - elif com == 'system': - print(system()) - -# Calling commands - - if com == "rps " + commands[0]: - nonstop_toggle() - elif com == "rps " + commands[1]: - changedatacolor() - elif com == "rps " + commands[2]: - currentdatacolor() - elif com == "rps " + commands[3]: - game() - elif com == "rps " + commands[4]: - changecharttype() - elif com == "rps " + commands[5]: - currentcharttype() - elif com == "rps " + commands[6]: - isitnonstop() - elif com == "rps " + commands[7]: - resetsettings() - -# Calling commands with usage argument - + print(critical + 'Couldn\'t find settings.ini file'+r) + +def changeconsolecolor(): + if path.exists('./settings.ini'): + consolecol = input("Type a color of a console (red, green, blue, white, magenta, cyan, yellow)\n").lower() + if consolecol == 'exit': + return + elif consolecol not in console_colors: + print(critical + f"Console color \"{consolecol}\" doesn't exist."+r) + elif consolecol == '': + print(critical + 'Console color cannot be null.'+r) + else: + config.set('Console', 'default_console_color', consolecol) + with open('settings.ini', 'w') as settingsfile: + config.write(settingsfile) + print(success + 'Console color updated successfully.'+r) + print("Restart to apply the changes.") - if com == "rps usage " + commands[0]: - nonstop_toggle_help() - elif com == "rps usage " + commands[1]: - changedatacolor_help() - elif com == "rps usage " + commands[2]: - currentdatacolor_help() - elif com == "rps usage " + commands[3]: - game_help() - elif com == "rps usage " + commands[4]: - changecharttype_help() - elif com == "rps usage " + commands[5]: - currentcharttype_help() \ No newline at end of file + else: + print(critical + 'Couldn\'t find settings.ini file'+r) + +def currentconsolecolor(): + if path.exists('./settings.ini'): + print(config.get('Console', 'default_console_color')) + else: + print(critical + 'Couldn\'t find settings.ini file'+r) \ No newline at end of file diff --git a/src/commands_help.py b/src/commands_help.py new file mode 100644 index 0000000..9e9bb8d --- /dev/null +++ b/src/commands_help.py @@ -0,0 +1,50 @@ +from colorama import Fore, init +from console_colors import consolecolor +init() +yel = Fore.YELLOW + +# Commands with help + +def nonstop_toggle_help(): + print("Description: It prompts for turning the setting on or off. (i.e. nonstop is when the game will not prompt") + print("you to play the game again, instead it repeats the game instantly, but you can stop the game by typing \"stop\"") + print("Alias: ns_tog") + +def changedatacolor_help(): + print("Description: It prompts for changing the data color by hexcode or name of a color.") + print("Make sure you add the \"#\" before the hexcode, or specify an appropriate name of a color.") + print("List of available named colors: "+yel+"https://matplotlib.org/stable/gallery/color/named_colors.html"+consolecolor) + print("Alias: cdc") + +def currentdatacolor_help(): + print("Description: Returns the current data color.") + print("Alias: cdc") + +def game_help(): + print("Description: Plays the game.") + print("Alias: g") + +def changecharttype_help(): + print("Description: It prompts for changing the chart type.") + print("Alias: chct") + +def currentcharttype_help(): + print("Description: Returns the current chart type.") + print("Alias: cct") + +def isitnonstop_help(): + print("Description: Returns \'Yes\' or \'No\' if the nonstop option is either enabled or disabled.") + print("Alias: isitns") + +def resetsettings_help(): + print("Description: Resets the entire settings.") + print("Alias: reset") + +def changeconsolecolor_help(): + print("Description: It prompts for changing the default console color.") + print("Alias: chcc") + +def currentconsolecolor_help(): + print("Description: Returns the current default console color.") + print("Alias: ccc") + \ No newline at end of file diff --git a/src/console_colors.py b/src/console_colors.py new file mode 100644 index 0000000..6b54408 --- /dev/null +++ b/src/console_colors.py @@ -0,0 +1,24 @@ +from configparser import ConfigParser +from colorama import Fore, init + +init() +config = ConfigParser() +config.read('./settings.ini') + + +consolecolor = config.get('Console', 'default_console_color') + +if consolecolor == 'cyan': + consolecolor = Fore.CYAN +elif consolecolor == 'yellow': + consolecolor = Fore.YELLOW +elif consolecolor == 'green': + consolecolor = Fore.GREEN +elif consolecolor == 'magenta': + consolecolor = Fore.MAGENTA +elif consolecolor == 'red': + consolecolor = Fore.RED +elif consolecolor == 'white': + consolecolor = Fore.WHITE +elif consolecolor == 'yellow': + consolecolor = Fore.YELLOW \ No newline at end of file diff --git a/src/index.py b/src/index.py index 4c6f957..479413c 100644 --- a/src/index.py +++ b/src/index.py @@ -1,11 +1,36 @@ -from commands import cmd +from rps_cli import cmd from sys import exit from rps import play +from colorama import Fore, init, Style +from platform import system +from configparser import ConfigParser +from console_colors import consolecolor # This file is the starting point of the entire game. +config = ConfigParser() +config.read('./settings.ini') +init() +sys = system() + +# Colorama Variables + +bright = Style.BRIGHT +green = Fore.GREEN + bright +reset = Fore.RESET +mag = Fore.MAGENTA + bright +yel = Fore.YELLOW + bright +red = Fore.RED + +# Main Startup + while True: - startup = input("Wanna play rock, paper, and scissors? (y/n)\nType \"cmds\" for special commands.\n").lower() + print(green+"Welcome to rps-python!\n"+yel) + print("You're using",sys,"as of now."+consolecolor) + print("Wanna play? Type \'y\' to start the game or type \'n\' if you're exiting."+mag) + print("Type \"cmds\" for special commands."+consolecolor) + startup = input().lower() + if startup == "y": play() break @@ -16,7 +41,6 @@ cmd() break else: - print("Try again.") - + print(red+"Try again.\n") -# Version v1.0.1 \ No newline at end of file +# Version v1.0.2 \ No newline at end of file diff --git a/src/rps.py b/src/rps.py index 2a2f55b..76574e2 100644 --- a/src/rps.py +++ b/src/rps.py @@ -4,14 +4,16 @@ from sys import exit from datetime import datetime from colorama import Style, Fore, init +from os import system +from console_colors import consolecolor init() def play(): # Adds parser and reads the settings file config = ConfigParser() - config.read('settings.ini') - + config.read('./settings.ini') + # Declares the user and comp's score as well as the tie and total no. of games data user_score = 0 comp_score = 0 @@ -35,7 +37,7 @@ def play(): charttype = config.get('Chart','chart_type') if nonstop == "True": - print(success + "\nYou can now stop the game by typing \'stop\' while the game plays.\n" + r) + print(success + "\nYou can now stop the game by typing \'stop\' while the game plays.\n"+consolecolor) compname = input("Enter the name of your player, or type \"none\" to skip.\nType \"cancel\" or \"exit\" to terminate this program.\n").lower() if compname == "cancel" or compname == "exit": @@ -50,13 +52,13 @@ def play(): if user_action not in possible_actions \ and not user_action == 'stop': - print(critical + "Invalid option. Try again." + r) + print(critical + "Invalid option. Try again.") continue if user_action == computer_actions: print("You choose", user_action.lower()) print(compname, "chooses", computer_actions) - print(yellow + "It's a tie" + r) + print(yellow + "It's a tie"+consolecolor) tie += 1 total_games += 1 @@ -65,13 +67,13 @@ def play(): if computer_actions == 'scissors': print("You choose paper") print(compname, "chooses", computer_actions) - print(dim + "Scissors win! You Lose." + r) + print(dim + "Scissors win! You Lose.") comp_score += 1 total_games += 1 else: print("You choose paper") print(compname, "chooses", computer_actions) - print(bright + "Paper wins! You Won." + r) + print(bright + "Paper wins! You Won.") user_score += 1 total_games += 1 @@ -80,14 +82,14 @@ def play(): if computer_actions == 'paper': print("You choose rock") print(compname, "chooses", computer_actions) - print(dim + "Paper wins! You Lose." + r) + print(dim + "Paper wins! You Lose.") comp_score += 1 total_games += 1 else: print("You choose rock") print(compname, "chooses", computer_actions) - print(bright + "Rock wins! You Won." + r) + print(bright + "Rock wins! You Won.") user_score += 1 total_games += 1 @@ -96,13 +98,13 @@ def play(): if computer_actions == 'paper': print("You choose scissors") print(compname, "chooses", computer_actions) - print(bright + "Scissors win! You Won." + r) + print(bright + "Scissors win! You Won.") user_score += 1 total_games += 1 else: print("You choose scissors") print(compname, "chooses", computer_actions) - print(dim + "Rock wins! You Lose." + r) + print(dim + "Rock wins! You Lose.") comp_score += 1 total_games += 1 @@ -115,18 +117,18 @@ def play(): if user_prompt == 'n': user_score = str(user_score) comp_score = str(comp_score) - print(success+"You scored", user_score+"."+r) - print(success+dim+compname, "scored", comp_score+"."+r) + print(success+"You scored", user_score+"."+consolecolor) + print(success+dim+compname, "scored", comp_score+"."+consolecolor) if tie == 1: - print(yellow+"Drawn",tie,"time.n"+r) - elif tie >= 2 or tie < 1: - print(yellow+"Drawn",tie,"times.\n"+r) + print(yellow+"Drawn",tie,"time.\n"+consolecolor) + elif tie >= 2 or tie == 0: + print(yellow+"Drawn",tie,"times.\n"+consolecolor) if total_games == 1: - print(white+"You played",total_games,"game.\n"+r) - elif total_games >= 2 or total_games < 1: - print(white+"You played",total_games,"games.\n"+r) + print(white+"You played",total_games,"game.\n"+consolecolor) + elif total_games >= 2 or total_games == 0: + print(white+"You played",total_games,"games.\n"+consolecolor) while True: scview = input('Do you want to view your scoreboard chart? (y/n)\n').lower() @@ -153,7 +155,7 @@ def play(): exit() elif charttype == 'dots': - mtp.scatter(userscores, compscores, color=datacolor, s=[140,70,100]) + mtp.scatter(userscores, compscores, color=datacolor, s=[280,140,200]) mtp.title('Your RPS Scoreboard') print("\nAs of", dateasstr) mtp.show() @@ -190,18 +192,18 @@ def play(): if user_action == 'stop': user_score = str(user_score) comp_score = str(comp_score) - print(success+"You scored", user_score+"."+r) - print(success+dim+compname, "scored", comp_score+"."+r) + print(success+"You scored", user_score+"."+consolecolor) + print(success+dim+compname, "scored", comp_score+"."+consolecolor) if tie == 1: - print(yellow + "Drawn",tie,"time.\n" +r) - elif tie >= 2 or tie < 1: - print(yellow + "Drawn",tie,"times.n" +r) + print(yellow + "Drawn",tie,"time.\n" +consolecolor) + elif tie >= 2 or tie == 1: + print(yellow + "Drawn",tie,"times.\n" +consolecolor) if total_games == 1: - print(white+"You played",total_games,"game.\n"+r) - elif total_games >= 2 or total_games < 1: - print(white+"You played",total_games,"games.\n"+r) + print(white+"You played",total_games,"game.\n"+consolecolor) + elif total_games >= 2 or total_games == 1: + print(white+"You played",total_games,"games.\n"+consolecolor) while True: scview = input('Do you want to view your scoreboard chart? (y/n)\n').lower() @@ -228,7 +230,7 @@ def play(): exit() elif charttype == 'dots': - mtp.scatter(userscores, compscores, color=datacolor, sizes=(20,)) + mtp.scatter(userscores, compscores, color=datacolor, s=[280,140,200]) mtp.title('Your RPS Scoreboard') print("\nAs of", dateasstr) mtp.show() diff --git a/src/rps_cli.py b/src/rps_cli.py new file mode 100644 index 0000000..eca793a --- /dev/null +++ b/src/rps_cli.py @@ -0,0 +1,95 @@ +from platform import python_version, system +from commands import * +from commands_help import * + +commands = ['toggle_nonstop', + 'changedatacolor', + 'currentdatacolor', + 'game', + 'changecharttype', + 'currentcharttype', + 'isitnonstop', + 'resetsettings', + 'changeconsolecolor', + 'currentconsolecolor'] + +# Main cmd + +def cmd(): + print(""" + List of available commands: + - changedatacolor + - toggle_nonstop + - currentdatacolor + - game + - changecharttype + - currentcharttype + - isitnonstop + - resetsettings + - changeconsolecolor + - currentconsolecolor + + Other commands: + - python_version + - system + + Type \"\" to get started with the command. + or type \"help \" to see the usage and description of a command.""") + while True: + com = input(">> ") + + if com == "exit": + break + elif com == "rps": + cmd() + elif com == 'python_version': + print(python_version()) + elif com == 'system': + print(system()) + +# Calling commands + + if com == commands[0] or com == 'ns_tog': + nonstop_toggle() + elif com == commands[1] or com == 'chdc': + changedatacolor() + elif com == commands[2] or com == 'cdc': + currentdatacolor() + elif com == commands[3] or com == 'g': + game() + elif com == commands[4] or com == 'chct': + changecharttype() + elif com == commands[5] or com == 'cct': + currentcharttype() + elif com == commands[6] or com == 'isitns': + isitnonstop() + elif com == commands[7] or com == 'reset': + resetsettings() + elif com == commands[8] or com == 'chcc': + changeconsolecolor() + elif com == commands[9] or com == 'ccc': + currentconsolecolor() + +# Calling commands with usage argument + + + if com == "help " + commands[0]: + nonstop_toggle_help() + elif com == "help " + commands[1]: + changedatacolor_help() + elif com == "help " + commands[2]: + currentdatacolor_help() + elif com == "help " + commands[3]: + game_help() + elif com == "help " + commands[4]: + changecharttype_help() + elif com == "help " + commands[5]: + currentcharttype_help() + elif com == "help " + commands[6]: + isitnonstop_help() + elif com == "help " + commands[7]: + resetsettings_help() + elif com == "help " + commands[8]: + changeconsolecolor_help() + elif com == "help " + commands[9]: + currentconsolecolor_help() \ No newline at end of file diff --git a/src/settings.ini b/src/settings.ini index 6492652..71d372f 100644 --- a/src/settings.ini +++ b/src/settings.ini @@ -5,3 +5,5 @@ chart_type = bar [RPS] nonstop = False +[Console] +default_console_color = cyan