Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
John Clark committed Feb 15, 2022
1 parent ce43cef commit 5eabb76
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 178 deletions.
Binary file modified img/indexpy.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 8 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <this-repository>`

After cloning the repo, please run the **index.py** file first, otherwise it won't work. <br>
Now you choose between these options below: <br>
<img src="/img/indexpy.PNG" /> <br>
Now you choose between these options below:
<br>
<img src="./img/indexpy.PNG" /> <br>

**y/n** (yes or no) or **cmds** for special commands.

Expand All @@ -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:)
196 changes: 64 additions & 132 deletions src/commands.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,82 @@
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',
'plot',
'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'):
datachartcolor = input("Type a name of color or hex code of a color.\n")
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()
Expand All @@ -85,24 +86,24 @@ 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'):
charttype = input("Type a chart type (bar, plot, dots, step, stem)\n")
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'):
Expand All @@ -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 <command>\" to get started with the command.
or type \"rps usage <command>\" 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()
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)
50 changes: 50 additions & 0 deletions src/commands_help.py
Original file line number Diff line number Diff line change
@@ -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")

Loading

0 comments on commit 5eabb76

Please sign in to comment.