# ==============================================================================
"""SCORES : demo for using INI files to store high scores for games"""
# ==============================================================================
__author__  = "Christophe Schlick modified by Philippe Blasi"
__version__ = "1.0"
__date__    = "2022-11-12"
__usage__   = """
Simply press <ENTER> at each pause""" 
# ==============================================================================
from ezCLI import *

# read and parse the INI file 'scores.ini'
scores = read_ini('scores.ini')
pause(f">>> read and parse 'scores.ini':\n{scores}")

# each section in 'scores.ini' corresponds to a specific game configuration
# [rows,cols,goals]
for key in scores:
  print(f"found game configuration = '{key}'")

# get high score dictionary for specific game configuration [12,12,4]
config = '12,12,4'; hscores = scores[config]
pause(f">>> show current high score list for config '{config}':\n{hscores}")

# insert a new 'score = name' couple at the end of dictionary
hscores['587'] = 'tata'
pause(f">>> show new high score list for config '{config}':\n{hscores}")

# write 'scores+.ini' to store modified high scores
write_ini('scores+.ini', scores)

# WARNING : 'score = name' lines in INI files are always sorted alphabetically,
# and not numerically, so wrong sorting may be obtained. The usual solution is
# to pad with zeros: for instance, '123' < '32' but '032' < '123' as expected
# 
# ==============================================================================
