CPTR 124 Fundamentals of Programming
In this lab you will rewrite your Tic-Tac-Toe code so that it controls the logic of a game using an object with instance variables and methods instead of global variables and functions.
- Teams
You are welcome to work with a partner on this lab. You and your partner should begin thinking about the problems and begin writing the code before lab time. You may work by yourself if you wish.
- What to do
In your original Tic-Tac-Toe game engine,
ttt_logic.py
, you used global variables and global functions to maintain the state of the game. In this assignment you will restructure your code so that it fits inside of a Python class definition. Your class will be namedTicTacToeGame
, and you should define the class in a file namedttt_logic_object.py
. Your original global variables will become fields within aTicTacToeGame
object, and your original functions will become methods within yourTicTacToeGame
class.To expedite the conversion process you can use the exact same variable names as before. The method names will be the same as the global function names from the earlier assignment, but they will need to include the extra
self
parameter.You should not have to alter the logic of the code within your functions. You will need to update how you refer to your variables, however; for example, if you used a global variable before named
nw
, you would need to refer to it asself.nw
inside of a method.The code within your
ttt_logic_object.py
file must be compatible with the newtictactoe_object.py
file. This new client file behaves identically to the original graphical user interface. It merely has been updated to interact with a Tic-Tac-Toe game object (that is, an instance of yourTicTacToeGame
class) rather than the functions that the earlier code provided.Review the earlier Tic-Tac-Toe assignment as needed to recall the meaning of the string parameters and division of responsibilities within the code.
- Check out
Your finished program will be evaluated for correctness and compliance. Double check to ensure the following:
- that your
ttt_logic_object.py
file contains no printing statements, - that your
ttt_logic_object.py
file executes properly with the unmodifiedtictactoe_object.py
file, and - that two players can play your graphical Tic-Tac-Toe game and things work as they would in the paper version.
Follow the special instructions given during lab for the evaluation component. When approved, you should submit your Python source file to http://eclass.e.southern.edu. Be sure your name (and your partner's name, if necessary) are included in comments at the top of each source file.
- that your