# Winter Holiday Tag - December project # Game of Tag, extension 2 and 3 import radio from codex import * import ascii_art import time import random # -- Constants -- NUM_PLAYERS = 5 MY_NUM = 5 MIN_SECONDS = 15 #seconds MAX_SECONDS = 30 #seconds present = ''' /.=BLACK x=WHITE 0=GREEN #=RED @=ORANGE C=CYAN ....xx.........xx....... ...x##xx.....xx##x...... ...x####xxxxx####x...... ....xx###x#x###xx....... ......x##x#x##x......... .......xxxxxxx@@@....... ...xxxxxxxxxxxxxxx@..... ...x0000x###x0000x.@.... ...x0000x###x0000x.@.... ...xxxxxxxxxxxxxxx.CCC.. ...x0000x###x0000x.CCC.. ...x0000x###x0000x.CCC.. ...x0000x###x0000x.CCC.. ...x0000x###x0000x.CCC.. ...x0000x###x0000x...... ...x0000x###x0000x...... ...x0000x###x0000x...... ...x0000x###x0000x...... ...x0000x###x0000x...... ...x0000x###x0000x...... ...x0000x###x0000x...... ...x0000x###x0000x...... ...x0000x###x0000x...... ...xxxxxxxxxxxxxxx...... ''' tag = ascii_art.get_images(present, scale=10) # -- Functions -- def set_pic(have_present): if have_present: display.draw_image(tag[0]) pixels.set([RED, RED, GREEN, GREEN]) else: display.show(pics.TARGET) pixels.off() def end_game(have_present, count): radio.off() if not have_present: display.clear() display.print("Tags:", scale=5) display.print(count, scale=8) # -- Set Up -- radio.on() radio.config(channel=6) have_present = False count = 0 if MY_NUM == 1: have_present = True random_time = random.randint(MIN_SECONDS, MAX_SECONDS) end_time = time.time() + random_time # -- Play Game -- while True: if buttons.is_pressed(BTN_U) and have_present: send_to = MY_NUM while send_to == MY_NUM: send_to = random.randint(1, NUM_PLAYERS) radio.send(str(send_to)) have_present = False set_pic(have_present) if MY_NUM == 1 and time.time() > end_time: radio.send('Z') end_game(have_present, count) break msg = radio.receive() if msg: if msg == str(MY_NUM): count = count + 1 have_present = True if msg == 'Z': end_game(have_present, count) break