#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov  5 21:26:06 2020
@author: chenguanlin
"""
import time as T
import random as r
import webbrowser as web
#---------------------------------------------------------------------------------------------------
#難度調整
def adjust():
    print('----難度,模式選擇----')
    print('共有四個難度,一個新玩法')
    T.sleep(0.5)
    print('easy是簡單難度，隨機刷新5個字元')
    T.sleep(0.5)
    print('baby是嬰兒難度，簡單的跟呼吸一樣，隨機刷新兩個字元')
    T.sleep(0.5)
    print('hard是困難難度，字元種類更多，隨機刷新5個字元')
    T.sleep(0.5)
    print('demon是地獄級難度，沒事不要虐待自己，字元種類更多，隨機刷新10個字元')
    T.sleep(0.5)
    print('reaction是考驗反應的模式，連續輸入隨機出現的10個數字，然後計算你的分數')
    T.sleep(0.5)
    adj=str(input('請輸入難度:'))
    if adj=='easy':
        easy()
    elif adj=='hard':
        difficult()
    elif adj=='baby':
        baby()
    elif adj=='demon':
        demon2()
    elif adj=='reaction':
        reactiongame()
    else:
        print('錯誤')
        adjust()
#---------------------------------------------------------------------------------------------------
#出題
def baby():
    str1='0123456789abcdefghijklmnopqrstuvwxyz'
    global a,t1
    a=r.choice(str1)+r.choice(str1)
    print('倒數三秒開始')
    print('3')
    T.sleep(1)
    print('2')
    T.sleep(1)
    print('1')
    T.sleep(1)
    print('(嬰兒難度)第%d題:'%(t),end='')
    print(str(a))
    t1=T.time()
    babygame()
def demon2():
    str1='0123456789!@#$%^&*-+=<>?/:;[]{}~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    global a,t1
    a=r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)
    print('地獄級難度 :D')
    T.sleep(0.5)
    print('倒數五秒開始')
    print('5')
    T.sleep(1)
    print('4')
    T.sleep(1)        
    print('3')
    T.sleep(1)
    print('2')
    T.sleep(1)
    print('1')
    T.sleep(1)
    print('(地獄級)第%d題:'%(t),end='')
    print(str(a))
    t1=T.time()
    demongame2()
def demon():
    str1='0123456789!@#$%^&*-+=<>?/:;[]{}~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    global a,t1
    a=r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)
    print('地獄級難度 :D')
    T.sleep(0.5)
    print('倒數五秒開始')
    print('5')
    T.sleep(1)
    print('4')
    T.sleep(1)        
    print('3')
    T.sleep(1)
    print('2')
    T.sleep(1)
    print('1')
    T.sleep(1)
    print('(地獄級)第%d題:'%(t),end='')
    print(str(a))
    t1=T.time()
    demongame()
def difficult():    
    str1='0123456789!@#$%^&*-+=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    global a,t1
    a=r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)
    print('倒數三秒開始')
    print('3')
    T.sleep(1)
    print('2')
    T.sleep(1)
    print('1')
    T.sleep(1)
    print('(困難)第%d題:'%(t),end='')
    print(str(a))
    t1=T.time()
    dgame()
def easy():
    str1='0123456789abcdefghijklmnopqrstuvwxyz'
    global a,t1
    a=r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)
    print('倒數三秒開始')
    print('3')
    T.sleep(1)
    print('2')
    T.sleep(1)
    print('1')
    T.sleep(1)
    print('第%d題:'%(t),end='')
    print(str(a))
    t1=T.time()
    game()
def first():
    str1='0123456789abcdefghijklmnopqrstuvwxyz'
    global a,t1
    a=r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)+r.choice(str1)       
    print('第%d題:'%(t),end='')
    print(str(a))
    t1=T.time()
    game()
#----------------------------------------------------------------------------------------------
#新模式
def reactiongame():
    list1=[0,1,2,3,4,5,6,7,8,9]
    t2=r.sample(list1,10)
        
    error=int(0)
    for count in range(5,0,-1):
        print('倒數%d秒'%(count))
        T.sleep(1)
    time1=T.time()
    for t in range(10):
        
        a=str(t2[t])
        print('第%d題'%(t+1))
        print(a,end="")
        b=str(input('輸入一樣的數字:'))
        print('')
        if a==b:
            continue
        else:
            print('error')
            error+=1
            continue
        
    time2=T.time()
    print('花了%.2f秒'%((time2-time1)))
    print('一共%d次錯誤'%(error))   
    print('分數:%.2f分'%((50-((time2-time1)+int(error)*3.5)*1)*2.1))
    if error>=6:
        print('#爛透了#')
    print('@要調整難度的話請輸入adj',end='')  
    c=str(input('繼續？y or n: '))
    if c=='y':
            reactiongame()
    elif c=='n': 
        print('結束!下次見:)')
    elif c=='adj': 
        
        t=0
        
        adjust()
    else:
        print('錯誤')
        adjust()

#----------------------------------------------------------------------------------------------
#遊戲跟結算    
def babygame():
    b=str(input('Ans:'))
    if str(a)==str(b):
        t2=T.time()        
        print('用了%.2f秒'%(t2-t1))
        T.sleep(1)
        print('@要調整難度的話請輸入adj',end='')        
        c=str(input('繼續？y or n: '))
        if c=='y':
            global t
            t+=1
            baby()
        elif c=='n': 
            print('結束!下次見:)')
        elif c=='adj': 
            t+=1
            adjust()
        else:
            print('錯誤')
            adjust()
    else:
        print('打錯了哈哈')
        babygame()              
def demongame2():#不會跳回簡單
    b=str(input('Ans:'))
    if str(a)==str(b):
        t2=T.time()        
        print('用了%.2f秒'%(t2-t1))
        T.sleep(1)
        print('@要調整難度的話請輸入adj',end='')   
        c=str(input('繼續？y or n: '))
        if c=='y':
            global t
            t+=1
            demon2()
        elif c=='n': 
            print('結束!下次見:)')
        elif c=='adj':
            t+=1
            adjust()
        else:
            print('錯誤')
            adjust()
    else:
        print('打錯了哈哈')
        demongame()            



def demongame():
    b=str(input('Ans:'))
    if str(a)==str(b):
        t2=T.time()        
        print('用了%.2f秒'%(t2-t1))
        c=str(input('繼續(會跳回簡單難度)？y or n: ',end=''))
        if c=='y':
            global t
            t+=1
            easy()
        elif c=='n':
            print('結束!下次見:)')
        else:
            print('錯誤')
            adjust()
    else:
        print('打錯了哈哈')
        demongame()                   
def dgame():  
    b=str(input('Ans:'))
    if str(a)==str(b):
        t2=T.time()        
        print('用了%.2f秒'%(t2-t1))
        T.sleep(1)
        print('@要調整難度的話請輸入adj',end='')        
        c=str(input('繼續？y or n: '))
        if c=='y':
            global t
            t+=1
            if(t%10==0):
                demon()
            else:
                difficult()
        elif c=='n': 
            print('結束!下次見:)')
        elif c=='adj':
            t+=1
            adjust()
        else:
            print('錯誤')
            adjust()
    else:
        print('打錯了哈哈')
        dgame()
#easy
def game():  
    b=str(input('Ans:'))
    if str(a)==str(b):
        t2=T.time()
        print('用了%.2f秒'%(t2-t1))
        T.sleep(1)
        print('@要調整難度的話請輸入adj',end='')
        c=str(input('繼續？y or n: '))
        if c=='y':
            global t
            t+=1
            if (t%10==0):
                demon()
            elif (t%5==0):
                di=str(input('難度提高？y or n: '))
                if di=='y':
                    difficult()
                elif di=='n':
                    easy()
                else:
                    print('錯誤')
            else:
                easy()
        elif c=='n': 
            print('結束!下次見:)')
        elif c=='adj':
            t+=1
            adjust()
        else:
            print('錯誤')
            adjust()
    else:
        print('打錯了哈哈')
        game()
#-------------------------------------------------
print('規則:')
T.sleep(0.1)
print('打出跟題目一樣的字後按enter 看你速度多快')
T.sleep(0.45)
start=input('開始遊戲？y or n: ')
if start=='y':
    t=int(0)
    t+=1
    adjust()
elif start=='n':
    print('掰掰!(｀Д´)')
else:
    print('錯誤，給你懲罰')
    T.sleep(1)
    web.open('https://images.app.goo.gl/yVH7neZqcxfnTkBy7')
