炸彈數字(終極密碼)

最後編輯:2016-05-17 建立:2015-12-31 歷史紀錄

炸彈數字(終極密碼)

終極密碼就是選定一個範圍的數字,例如1~100,

由裁判選定其中一個數字,讓其餘的人猜數字

(當然除料裁判外其他玩家不知道答案),

如果沒猜中的話裁判要依猜出的數字將範圍縮小,

讓下一個輪到的人繼續猜,直到猜中數字為止,

終極密碼1-100 1到100

例如終極密碼是77,

 

一般會切中間的數字

第一個人猜50,則裁判要說50到100,

第二個人則要猜50~100的數字,譬如88,

裁判則說50~88,50到88,

猜到的話,裁判就可以公佈答案,

看是要給予獎勵或是懲罰

遊戲網址:http://ftp.phjh.tc.edu.tw/~klychen/R esearch/FinalNumber/ChooseNum.php

用四位數七段顯示器 麵包板 樹莓派 呈現

 

  • import RPi.GPIO as GPIO
  • import time
  • import random
  • import multiprocessing
  • GPIO.setmode(GPIO.BCM)
  • GPIO.setwarnings(False)
  • segments = (10, 9, 11, 5, 6, 13, 19, 26)
  • led =(7)
  • for segment in segments:
  • GPIO.setup(segment, GPIO.OUT)
  • GPIO.output(segment, 0)
  • GPIO.setup(led , GPIO.OUT)
  • GPIO.output(led , False)
  • digits = (3, 4, 17, 27)
  • for digit in digits:
  • GPIO.setup(digit, GPIO.OUT)
  • GPIO.output(digit, 1)
  • dictionary = {' ':(0,0,0,0,0,0,0),
  • '0':(1,1,1,1,1,1,0),
  • '1':(0,1,1,0,0,0,0),
  • '2':(1,1,0,1,1,0,1),
  • '3':(1,1,1,1,0,0,1),
  • '4':(0,1,1,0,0,1,1),
  • '5':(1,0,1,1,0,1,1),
  • '6':(1,0,1,1,1,1,1),
  • '7':(1,1,1,0,0,0,0),
  • '8':(1,1,1,1,1,1,1),
  • '9':(1,1,1,1,0,1,1),
  • 'Y':(0,1,1,1,0,1,1),
  • 'O':(1,1,1,1,1,1,0),
  • 'P':(1,1,0,0,1,1,1),
  • 'L':(0,0,0,1,1,1,0),
  • 'E':(1,0,0,1,1,1,1),
  • 'S':(1,0,1,1,0,1,1),
  • '-':(0,0,0,0,0,0,1)}
  • def display(string,s):
  • loop=True
  • if s:loop=s*1000
  • while len(string)<4:
  • string='0'+string
  • n=0
  • while loop:
  • for digit in digits:
  • GPIO.output(digit, 1)
  • GPIO.output(digits[n], 0)
  • i = 0
  • for on_or_off in dictionary[string[n]]:
  • if n==1:
  • GPIO.output(segments[i], on_or_off)
  • GPIO.output(segments[7], True)
  • else:
  • GPIO.output(segments[i], on_or_off)
  • GPIO.output(segments[7], False)
  • i += 1
  • time.sleep(0.001)
  • n += 1
  • n %= 4
  • if s:loop-=1
  • a=0
  • b=99
  • boom_num=random.randint(1,98)
  • while True:
  • p = multiprocessing.Process(target=display, args=(str(b+a*100),0))
  • p.start()
  • enter_int = input('Enter a number %s ~ %s : '%(a,b))
  • if enter_int<= a or enter_int>= b:
  • print('ERROR!!!! please enter again~')
  • p.terminate()
  • GPIO.output(led,True)
  • display('----',1)
  • GPIO.output(led , False)
  • continue
  • if enter_int == boom_num :
  • print('BOOM !!!! you lose~')
  • GPIO.output(led,True)
  • p.terminate()
  • display('LOSE',5)
  • GPIO.output(led , False)
  • break
  • if enter_int < boom_num :
  • p.terminate()
  • a = int(enter_int)
  • continue
  • if enter_int > boom_num :
  • p.terminate()
  • b = int(enter_int)
  • continue
  • GPIO.cleanup()

遊戲試玩(如下) :

Enter a number 0 ~ 99 : 10

Enter a number 10 ~ 99 : 20

Enter a number 20 ~ 99 : 50

Enter a number 50 ~ 99 : 60

Enter a number 50 ~ 60 : 45

ERROR!!!! please enter again~

Enter a number 50 ~ 60 : 55

Enter a number 55 ~ 60 : 57

Enter a number 57 ~ 60 : 58

Enter a number 58 ~ 60 : 59

BOOM !!!! you lose~