Three Key Monte (ex10-3, P.359)

  1. Write a program to play "Three Key Monte."
  2. Your program should draw three buttons labeled "Door 1", "Door 2", and "Door 3" in a screen.
  3. In each iteration, the program randomly select one door (without telling the user which one is selected).
  4. The program then prompts the user to press one of the keys '1', '2', or '3'.
  5. A press on the selected key is a win, and a press on one of the other two is a loss.
  6. You should tell the user whether they won or lost, and in the case of a loss, which was the correct door.
  7. When the user press 'q' to exit the program, it shows the ratio of wins.
  8. Your program may re-use the classes Button and Text defined in the curses_button module.
  9. The following is a sample code which demonstrates how to utilize the classes defined in this module.
    
    import curses
    from curses_button import Button, Text
    
    stdscr = curses.initscr()
    curses.noecho()
    stdscr.keypad(True)
    
    b1 = Button(stdscr, 0, 0, "One", '1')
    b2 = Button(stdscr, 0, 10, "Two", '2')
    b3 = Button(stdscr, 0, 20, "Three", '3')
    buttons = [b1, b2, b3]
    
    statusBar = Text(stdscr, 23, 0, "Status:", 0)
    
    while True:
        c = stdscr.getkey()
        if c == 'q': break
        for b in buttons:
            if b.getKey() == c:
                statusBar.setText("You press " + b.caption)
    
    curses.endwin()