import casioplot
from math import *
class Game_over(Exception):
  pass
try:
  while True:
    casioplot.clear_screen()
    casioplot.draw_string(70,100,"PRESS [AC] TO START")
    casioplot.draw_string(82,10,"SHOOT THE TARGET")
    casioplot.show_screen()
except:
  pass
casioplot.show_screen()
casioplot.clear_screen()
targets=1
tick=0
def loadlv():
  global xsqu
  global ysqu
  global xcross
  global ycross
  global totalmiss
  global lvl
  global motion1
  global motion2
  totalmiss=0
  xsqu=50
  ysqu=50
  xcross=102
  ycross=75
  if lvl==1:
    motion1=1
    motion2=0
  if lvl==2:
    motion1=2
    motion2=1
  if lvl==3:
    motion1=1
    motion2=2
  if lvl==4:
    motion1=1
    motion2=3
  if lvl==5:
    ysqu=10
    motion1=3
    motion2=3
  if lvl==6:
    motion1=4
    motion2=4
  if lvl==7:
     motion1=4
     motion2=4
  if lvl==8:
     motion1=5
     motion2=5
  if lvl==9:
     motion1=1
     motion2=5
  if lvl==10:
     motion1=3
     motion2=5
  if lvl==11:
    motion1=4
    motion2=6
  if lvl==12:
    motion1=3
    motion2=6
  if lvl==13:
    motion1=5
    motion2=6
  if lvl==14:
    motion1=4
    motion2=5
  if lvl==15:
    motion1=6
    motion2=5
  if lvl==16:
    motion1=5
    motion2=1
  if lvl==17:
    ycross-=1
    motion1=4
    motion2=0
  if lvl==18:
    xcross-=50
    motion1=7
    motion2=0
  if lvl==19:
    motion1=8
    motion2=4
  if lvl==21:
    motion1=8
    motion2=6
  if lvl==20:
    motion1=9
    motion2=5
  if lvl==22:
    motion1=8
    motion2=6
  if lvl==23:
    motion1=6
    motion2=7
  if lvl==24:
    motion1=8
    motion2=7
  if lvl==25:
    motion1=4
    motion2=7
  if lvl==26:
    ysqu-=25
    motion1=8
    motion2=2
  if lvl==27:
    xsqu+=35
    motion1=5
    motion2=8
  if lvl==28:
    motion1=6
    motion2=8
  if lvl==29:
    motion1=4
    motion2=8
  if lvl==31:
    motion1=8
    motion2=8
  if lvl==30:
    motion1=7
    motion2=8
  if lvl==32:
    xsqu-=5
    motion1=5
    motion2=4
  if lvl==33:
    xsqu+=92
    motion1=5
    motion2=6
  if lvl==34:
    motion1=9
    motion2=5
  if lvl==35:
    ysqu+=10
    motion1=8
    motion2=6
  if lvl==36:
    ysqu+=22
    motion1=6
    motion2=2
  if lvl==37:
    xsqu+=69
    motion1=5
    motion2=3
  if lvl==38:
    motion1=0
    motion2=7
    xsqu=12
  if lvl==39:
    xsqu=25
    motion1=5
    motion2=8
  if lvl==40:
    xsqu=150
    motion1=2
    motion2=8
  if lvl==41:
    print("you won !")
  if lvl>1:
    displvl(lvl)
    try:
      loop()
    except KeyboardInterrupt:
      shoot()
lvl=1
loadlv()
def displvl(lv):
  try:
    for i in range(50):
      casioplot.clear_screen()
      casioplot.draw_string(150,100,"LEVEL "+str(lv))
      casioplot.show_screen()
  except:
     pass
displvl(lvl)
def horiz_line(xaxis,yaxis,lenght):
  for i in range(abs(lenght)):
    if (abs(lenght))==lenght:
      casioplot.set_pixel(xaxis+i,yaxis)
    else:
      casioplot.set_pixel(xaxis-i,yaxis)
def verti_line(xaxis,yaxis,lenght):
  for i in range(lenght):
    casioplot.set_pixel(xaxis,yaxis+i)
def loop():
  global tick
  global xsqu
  global ysqu
  global xcross
  global ycross
  global motion1
  global motion2
  while True:
    if motion1==1:
      xsqu=round(sin(tick)*50)+75
    if motion1==2:
      ysqu=round(sin(tick)*50)+75
    if motion1==3:
      xsqu=round(cos(tick)*125)+75
    if motion1==4:
      xsqu=round(cos(tick)*125)+75
      ysqu=round(sin(tick)*50)+75
    if motion1==5:
      ysqu=round(cos(tick)*50)+75
    if motion1==6:
      xsqu=round(cos(tick)*250)+75
    if motion1==7:
      xsqu=round(tan(tick)*5)+75
    if motion1==8:
      xsqu=round(tan(tick)*5)+90
    if motion1==9:
      xsqu=round(tan(tick)*5)+60
    if motion1==10:
      ysqu=round(cos(tick)*50)+75
    if motion2==1:
      xcross=round(sin(tick)*50)+75
    if motion2==2:
      xcross=round(cos(tick)*50)+75
      ycross=round(cos(tick)*50)+75
    if motion2==3:
      xcross=round(cos(tick/2)*50)+75
      ycross=round(sin(tick)*50)+75
    if motion2==4:
      xcross=round(cos(tick)*-70)+75
      ycross=round(sin(tick)*70)+75
    if motion2==5:
      xcross=round(cos(tick*5)*50)+75
      ycross=round(sin(tick*5)*50)+80
    if motion2==6:
      xcross=round(cos(tick*10)*75)+75
      ycross=round(sin(tick*10)*75)+80
    if motion2==7:
      xcross=round(-tan(tick))+75
    if motion2==8:
      xcross=round(tan(cos(tick)*30)*3)+75
    casioplot.clear_screen()
    horiz_line(xsqu,ysqu,50)
    verti_line(xsqu,ysqu,50)
    horiz_line(xsqu,ysqu+50,50)
    verti_line(xsqu+50,ysqu,50)
    horiz_line(xcross-12,ycross,12)
    horiz_line(xcross+1,ycross,12)
    verti_line(xcross,ycross-12,12)
    verti_line(xcross,ycross+1,12)
    casioplot.show_screen()
    tick+=0.05
def shoot():
  global totalmiss
  global xsqu
  global xcross
  global ysqu
  global ycross
  global lvl
  global motion1
  global motion2
  missed=0
  casioplot.clear_screen()
  horiz_line(xsqu,ysqu,50)
  verti_line(xsqu,ysqu,50)
  horiz_line(xsqu,ysqu,50)
  verti_line(xsqu+50,ysqu,50)
  horiz_line(xcross-12,ycross,12)
  horiz_line(xcross+1,ycross,12)
  verti_line(xcross,ycross-12,12)
  verti_line(xcross,ycross+1,12)
  if xsqu<xcross and xcross<xsqu+50 and ysqu<ycross and ycross<ysqu+50:
    casioplot.draw_string(215,25,"good")
    lvl+=1
    loadlv()
  else:
    casioplot.draw_string(215,25,"missed")
    missed=True
    totalmiss+=1
  for i in range(5000):
    casioplot.show_screen()
  if missed:
    try:
      if totalmiss<3:
        loop()
      else:
        raise Game_over("try again")
    except KeyboardInterrupt:
      shoot()
try:
  loop()
except KeyboardInterrupt:
  shoot()
except RuntimeError:
  casioplot.clear_screen()
  casioplot.draw_string(125,50,"GAME OVER. PRESS [AC]")
