2022年8月10日水曜日

ChallengeRaspi_pico minislot




 #pico mini slot

#Pico Minislot

#Press Redkey  to start

#Press Greenkey to show slotleft

#Press Yellokey to show slotcenter

#Press Bluekey to show slotright

#Your first money is $1000


from machine import Pin, I2C

import ssd1306

import random

import utime


i2c = I2C(0, sda=Pin(16), scl=Pin(17) )

addr = i2c.scan()

print( "address is :" + str(addr) )

display = ssd1306.SSD1306_I2C(128, 64, i2c)


swflag1=False

swflag2=False

swflag3=False

swflag4=False


str1=''

str2=''

str3=''

str4=''


intval=0.5

yourmoney=900

randend=6  #9 slot  6 dice  2 tyouhan


bt1=Pin(18,Pin.IN,Pin.PULL_UP)

bt2=Pin(19,Pin.IN,Pin.PULL_UP)

bt3=Pin(20,Pin.IN,Pin.PULL_UP)

bt4=Pin(21,Pin.IN,Pin.PULL_UP)


def slotleft():

    global str1

    str1 = str(random.randint(1,randend))

    display.text(str1,15,10,1)    

    display.show()

    print(str1)


def slotcenter():

    global str2

    str2 = str(random.randint(1,randend))

    display.text(str2,45,10,1)

    display.show()

    print(str2)

    

def slotright():

    global str3

    str3 = str(random.randint(1,randend))

    display.text(str3,75,10,1)  

    display.show()

    print(str3)

    

def slotclear():

    display.fill(0)

    display.show()

       

def bt1_handler(pin):

    global swflag1

    swflag1=True

             

def bt2_handler(pin):

    global swflag2

    swflag2=True

           

def bt3_handler(pin):

    global swflag3

    swflag3=True

        

def bt4_handler(pin):

    global swflag4

    swflag4=True


bt1.irq(trigger = Pin.IRQ_FALLING,handler=bt1_handler) 

bt2.irq(trigger = Pin.IRQ_FALLING,handler=bt2_handler)    

bt3.irq(trigger = Pin.IRQ_FALLING,handler=bt3_handler)

bt4.irq(trigger = Pin.IRQ_FALLING,handler=bt4_handler)


display.text('Pico Minislot',0,0,1)

display.text('Redkey start',0,10,1)

display.text('Greenkey left',0,20,1)

display.text('Yellokey center',0,30,1)

display.text('Bluekey right',0,40,1)

display.show()


while True:   

    if swflag1==True:

        utime.sleep(intval)

        slotleft()

        swflag1=False

        

    if swflag2==True:

        utime.sleep(intval)

        slotcenter()

        swflag2=False


    if swflag3==True:

        utime.sleep(intval)

        slotright()

        swflag3=False

        

    if swflag4==True:

        utime.sleep(intval)

        slotclear()

        swflag4=False

        if str1==str2 and str2==str3:

            yourmoney=yourmoney +100

            display.text('$ ' + str(yourmoney),0,55,1)

            display.show()

        else:       

            yourmoney=yourmoney -100

            if yourmoney <= 0 :

                display.fill(0)

                display.text('Game over',0,0,1)

                display.show()

            else:

                display.text('$ ' +str(yourmoney),0,55,1)

                display.show()

            


0 件のコメント:

コメントを投稿