#################################################
# hw6.py
#
# Your name:
# Your andrew id:
# This assignment is SOLO!
#################################################

import cs112_f22_week6_linter
import math, copy, random

from cmu_112_graphics import *

#################################################
# Helper functions
#################################################

def almostEqual(d1, d2, epsilon=10**-7):
    # note: use math.isclose() outside 15-112 with Python version 3.5 or later
    return (abs(d2 - d1) < epsilon)

import decimal
def roundHalfUp(d):
    # Round to nearest with ties going away from zero.
    rounding = decimal.ROUND_HALF_UP
    # See other rounding options here:
    # https://docs.python.org/3/library/decimal.html#rounding-modes
    return int(decimal.Decimal(d).to_integral_value(rounding=rounding))

#################################################
# Tetris
#################################################
def gameDimensions():
    # These values are set to the writeup defaults
    rows = 15
    cols = 10
    cellSize = 20
    margin = 25
    return (rows, cols, cellSize, margin)

def appStarted(app):
    # Delete this starter code and replace with your own
    app.label = 'Tetris!'
    app.color = 'orange'
    app.size = 0

def keyPressed(app, event):
    # Delete this starter code and replace with your own
    app.color = random.choice(['red', 'orange', 'yellow', 'green', 'blue'])

def timerFired(app):
    # Delete this starter code and replace with your own
    app.size += 10

def redrawAll(app, canvas):
    # Delete this starter code and replace with your own
    for s in ((app.size % 300), ((app.size + 150) % 300)):
        canvas.create_text(app.width/2, app.height/2, fill=app.color,
                           text=app.label, font=f'Arial {s} bold')

def playTetris():
    # Note: Instead of hardcoding width and height, you should call
    # gameDimensions() and calculate the correct width and height values 
    # from rows, cols, cellSize, and margin
    width = 400
    height = 400
    runApp(width=width, height=height)

#################################################
# Test Functions
#################################################

# None!  Though... you may wish to (optionally) add some test 
#        functions of your own for any functions that do not 
#        involve graphics


#################################################
# main
#################################################

def main():
    cs112_f22_week6_linter.lint()
    playTetris()

if __name__ == '__main__':
    main()
