DEV Community

Cover image for CLI Tic Tac Toe (OOP Lesson)
JJ
JJ

Posted on

CLI Tic Tac Toe (OOP Lesson)

A few weeks ago, freshly armed with a repertoire of new lingo related to Object Oriented Programming (OOP), I embarked on what would turn out to be a journey of discovery and frustration. On this journey, I learned a lot, got flustered, wanted to quit, and
ultimately forced myself to dig deep displaying some of that Grit I spoke about last year. I've had brief primers of what OOP is, having played around with C#, Visual Basic before, and really, I should know more than I do. The problem is, I never had a course like The Odin Project (TOP) push me to utilize those concepts. At least until the command-line Tic Tac Toe Ruby project!

To get started with CLI TTT, I knew I would need some classes so I started my planning, trying to implement what I had learned. I started off with what I called a Board class in a board.rb file. I then set to work trying to get the visual aspect of my game going. After much research, HEREDOCS were brought to my attention, specifically squiggly HEREDOCS. At first I ignored the comment on using HEREDOCS not realizing just how powerful they could be for what I was trying to accomplish. After some struggle, they were again brought to my attention and less than two hours later I had a working implementation of my game board and I was all smiles.

As I would find out when I finished, there were better ways to implement my design, but I'm proud that I came up with it. I had no clue how to graphically represent an array in a 3 x 3 grid. With each accomplishment, I added another tool to my belt, but I've got plenty of room to add more tools.

Then came the Player class. I knew I only had two players but I didn't quite understand how initializing my player class with instance variables for players worked. Now I understand that you can instantiate a player by calling some_variable = Player.new(name) and what happens is, when an instance is created, it automatically invokes the initialize method and if any parameters were passed to it, as long as the getter and setters are established (either using attr_reader, attr_writer, attr_accessor, or by defining the getter and setter functions manually) it will create a new player object. Prior to this section of the course, I've heard a lot of people talking about getters and setters and had no clue what they were talking about and remember feeling overwhelmed at the time by all the things yet to learn.

Now I know, and guess what? Now I'm hearing people talk about binary search trees and serialization and all kinds of other topics that I know, when I get there, it will be just another hill to climb. I climbed another hill with OOP. I'm no expert, and have a lot to learn about OOP, this I know. But I also know that with each project, I will get better and better at it. Writing about it helps as well. The biggest thing that helped me though, was having someone to ask questions of, and knowing they wouldn't just give me the answers. That's what I love most about TOP. We are trained early on to guide people to the answer so they can discover the solution on their own. I had some super supportive people helping me and that encourages me to press on knowing my peers have my back!

After wrapping up Tic Tac Toe and feeling the satisfaction that each of my manual test cases passed, I'm excited to move on to the next challenge: Mastermind! I welcome the challenge I know it will bring and can't wait to have a discussion about it the next time I write. Who knows? Perhaps I will come up with something in between. Until next time...be good!

Photo courtesy of: Photo by Pixabay from Pexels:

Top comments (0)