Skip to content

Latest commit

 

History

History

2024-02-03

Table of Content

Lecture 18: Build a Tic-Tac-Toe Game (part II)

Topics

Here are the topics we are going to cover

  • Modify the code for the tic-tac-toe game to cover edge cases like
    • Bad input
    • Reset game
    • Quit game
  • Break the code for the tic-tac-toe game to separate files
  • Rewrite the code for the tic-tac-toe game in python class
  • Create a graphic user interface (GUI) with tkinter

Code sample

Concepts

  • Widgets in tkinter [source]
    Widget Class Description
    Label A widget used to display text on the screen
    Button A button that can contain text and can perform an action when clicked
    Entry A text entry widget that allows only a single line of text
    Text A text entry widget that allows multiline text entry
    Frame A rectangular region used to group related widgets or provide padding between widgets

Course materials

  • slides [TBD]

Suggested reading

Practice

  1. Modify the code in the class demo [link] for the tic-tac-toe game such that:
    1. Player could quit the game with command "q" and type in "y" to confirm and quit the game
    2. If the player regrets and types in "n" to continue the game, he could still type in "q" to try to quit the game again without being treated as invalid input
    3. Do the same to reset the game in the middle, use the command "reset"
graph LR;
    A[Start] --> B[Input];
    B --> C[Restart];
    B --> D[Quit];
    B --> E[Valid Position?];
    C --> |Reset Board|A;
    D --> F[End Game]
    E --> |NO|B;
    E --> |YES|G[Update the Board];
    G --> H[Display the Board];
    H --> I[Check Win];
    I --> |YES|F;
    I --> |NO|J[Check Tie];
    J --> |YES|F;
    J --> |NO|B;
Loading
  1. Research the usage of the library tkinter and build a window interface, such that
    1. The window has a title "Tic Tac Toe"
    2. The window has a box entry for user to type
    3. The window has a button below the box entry
    4. When the user clicks the button, a window should pop up and display the same message the user typed in

(We haven't covered much on the library tkinter, so you might need some online research to figure out question 2)