From 5eabb763c3054829ffa6f60fe30b98d005bf2bfa Mon Sep 17 00:00:00 2001 From: John Clark Date: Tue, 15 Feb 2022 22:57:41 +0800 Subject: [PATCH] v1.0.2 --- img/indexpy.PNG | Bin 3662 -> 6317 bytes readme.md | 20 ++--- src/commands.py | 196 ++++++++++++++---------------------------- src/commands_help.py | 50 +++++++++++ src/console_colors.py | 24 ++++++ src/index.py | 34 ++++++-- src/rps.py | 60 ++++++------- src/rps_cli.py | 95 ++++++++++++++++++++ src/settings.ini | 2 + 9 files changed, 303 insertions(+), 178 deletions(-) create mode 100644 src/commands_help.py create mode 100644 src/console_colors.py create mode 100644 src/rps_cli.py diff --git a/img/indexpy.PNG b/img/indexpy.PNG index d72a5174132fc8ce3ad94c46d625c5ff516cee0c..cdd56ef75f9567b9bb376dac60360c84a865afbe 100644 GIT binary patch literal 6317 zcmb_hdpy(q+b4&L~c#VdOA(Xk-rEY(pnyEJ=>pL@B3*P`5I= z%N)i~4kMx_H4+PDV{e zOiWDftkdaBVq)7YMenzFNQ>^L70+K6J;b9fIi3`&>eiSO36gNA3sg+38Yj#5mlDZ4 zBb>aV#Kd<0vvrA+5pM#;#8gh6Jq>k_^IgjS6+L+jdrz~_;=^f;Z{NmY*(s+Y^}rs~ z=M72{doG^8eSZ0`zv%h5G9<;HNbawjnZf`J49VBm7i-q45>S;Ys}>-7^VU+f6p7f6 zCyYb36j67)dqkqyH1h*t%Z@S?3Ei^G>6}R3vNOvjOQmfojB)>agT{T92w4#9&d9Yf z7|FLu$&1Li!&CTVoPaWpNtj$BJ#yUew7CJ;ap;ORe+j{jn5@rilLQ$X69lF~HDEcQ z;ix6PQ=G1S_9MaOIsIx+;%7Epk^4x%qW~Tvr=om;%RMVkj*RZ7-FZB65D&GLJ>+FS zag&3ZZH)mm`B@)3dx9g`DXI9;ehl;WjjYf=*DjOkk!!SHr(0 z<=cG=&mvh9ATJ5MtFX=)&Qu}W*1|&Qd!No%@?QcV+eoiy@}kHrQY#7m_7!_fd1+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;)3ytcGuj;5<$c@zPYgfCq*PGlJ)yyF} zxS>=M#=pFE4vE3uT?^IH7Y?Nzh+YAW#rnSdn&5zh@H}h!PRyfkVoS15YD>jeN@__U zu0^J4Pt>sUTDyQTQ3u5gokla#f;i<}HuaQp;fEtX`5v5uMnNXw*WzL{av7bU=Z%wt zU$^*4T#l=^G%%0kT6-6Kf^zR_DRug2v9beF{bt{F=Zs3tJ>ASVngs5G^a}C+okJz& z!yC^~v#o*TMwL^iSjmHwBHG?Tnk&`HqMu;Kx;RKd(G1KZHmlcvohDOW-gMTIYzORE xX|h5tZfiU8@qbAFzY^;Ith`KEW1SM2T)cB${u99*zy|;T 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