Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Make Visual Improvements When the Game Ends

00:00 Visual Improvements When the Game Ends. If there’s a winner, you’ll want to blink some of their cells and print a message stating who won the game. Otherwise, you’ll print a solid grid of cells and optionally inform the players that there were no winners in the case of a tie.

00:16 The ConsoleRenderer class is now modified. print_solid() is now removed and replaced with a conditional.

00:59 Your messages contain special syntax for the name aliases of Unicode characters, including emojis, in order to make the output look more colorful and exciting.

01:11 The example seen on-screen will render the emoji seen on-screen. Note that you call yet another helper function, print_blinking(), which you’ll define next.

01:31 This new function takes the sequence of cells and the numeric positions of those which should be rendered using blinking text. Then it makes a mutable copy of the cells, overwrites the specified cells with blinking and ANSI escape codes, and delegates the rendering to print_solid().

01:56 At this point, you can test your custom renderer using two computer players built into the tic-tac-toe library. Save the code seen on-screen in a file named play.py, located in the frontends/ folder.

02:10 When

02:47 you run this script, you’ll see two artificial players making random moves leading to different outcomes each time.

03:05 While it’s interesting to look at their gameplay, there’s no interactivity whatsoever. You are going to change that in the next section of the course by letting human players decide what moves to make.

Become a Member to join the conversation.