Tufty2350 programming help

This is my first post here as I’ve just received my Tufty2350 and Badger2350. I will be attending a history conference next week and several more conferences over the next couple of months. I’m a history professor and would like to create a short program on the Tufty. I would like to create a game as an icebreaker and I would like the program to be a short game called, “Should I become a historian” and it will randomly pull 5 questions from a pool of pregenerated questions that all have 3 “answers” and depending on your answers you will be told to run to the nearest university and apply in their history program or “keep your day job.”

I thought that this would be easy enough but beyond displaying the text needed I’m running into roadblock after roadblock. Can anyone suggest or provide a starting point? I used to program in BASIC as a kid and thought this would be a walk in the park…but apparently my brain can’t brain…

Thanks in advance!

EDIT: I should also mention that I have successfully installed Thonny and successfully created a couple of apps after going through the Badgewa.re/docs.

My first thought is maybe some sort of lists or dictionaries with questions and answers all combined together in some way. So I plonk a random quick and dirty bit of code that may trigger some thoughts for you. Its very easy to get lost in a mix of various brackets in my doodle, but it was just a quick coffee time thought. It’s just a bit of micropython code, I’ve no idea how you translate something like this into a Tufty app.

import random

question_pool = {
    1:'Who suceeded Willam the Conqueror',
    2:'What is your gender',
    3:'How tall are you',
    4:'What is your weight',
    5:'When did the reign of King Stephen start'
    }

question_answer_choices = {
    1:[[1,'William Rufus'],[2,'King Stephen'],[3,'Donald Duck']],
    2:[[1,'Male'],[2,'Female'],[3,'Transgender']],
    3:[[1,'6 foot'],[2,'5 foot'],[3,'4 foot']],
    4:[[1,'17 stone'],[2,'16 stone'],[3,'15 stone']],
    5:[[1,'1120'],[2,'1125'],[3,'1135']]
    }

answer_responses = {
    1:[[1,'Correct'],[2,'Close'],[3,"You're a moron"]],
    2:[[1,'Oh boy'],[2,'luvly'],[3,'two for one']],
    3:[[1,'tall'],[2,'short'],[3,'grow up']],
    4:[[1,'beefy'],[2,'large'],[3,'medium']],
    5:[[1,'No'],[2,'close'],[3,'correct']]
    }   
    

# pull 2 random questions to ask from the question pool and put in to_ask list
def to_ask():
    to_ask_list = []
    while len(to_ask_list) < 2:
        q_num = random.randint(1, len(question_pool))
        if q_num not in to_ask_list:
            to_ask_list.append(q_num)
    return to_ask_list


for num in to_ask():
    ask = str((question_pool[num]) + '\nPick From\n' + str(question_answer_choices[num]) + '\nEnter a number: ')
    response = input(ask)
    if int(response) < 1 or int(response) > 3:
        print('Dunce! you did not respond with 1 - 3')
    else:
        print('Well my response is:',answer_responses[num][int(response) - 1][1])
    print('----------------')
        
    
    
    

1 Like

Thank you! This is a great jumping off point for me, and I appreciate the help. Part of the problem was/is that there are all of the demos are graphical in nature so I only had the “hello world” exercise as a starting point…so this really helps.

The simplest way of choosing an answer is just by checking badge.pressed() to see if the user hit A, B or C, but here’s an example of how you might want to do a menu to select from if you want to be a bit fancier:

screen.font = rom_font.nope

menu_items = [
    "Free loot!",
    "Bad idea, but ok.",
    "Thanks... I think.",
    "Welp. o_O"
]

selected = 0

def update():
    global selected

    # adjust selected item index based on button presses
    if badge.pressed(BUTTON_UP):
        selected -= 1
    if badge.pressed(BUTTON_DOWN):
        selected += 1

    # wrap and clamp selected index to the range of items in the menu
    selected %= len(menu_items)

    # write out the dialogue
    screen.pen = color.white
    screen.text("IT'S DANGEROUS TO GO", 10, 10)
    screen.text("ALONE! TAKE THIS.", 10, 22)

    # draw the menu of response options on the screen
    for i in range(len(menu_items)):
        screen.pen = color.taupe

        # if this is the selected item then highlight it
        if i == selected:
            screen.text(">", 10, i * 15 + 50)
            screen.pen = color.white

        # write the menu item label
        screen.text(menu_items[i], 20, i * 15 + 50)

run(update)
2 Likes

Thank you! This worked perfectly and I am now working on the pool of questions. If anyone is interested I’d be happy to post the end result.

1 Like