I’ve completed another prototype. This is actually a game designed by my oldest son (9 years old) that he created on paper, and I decided to flesh it out for him. The game is a local multi-player game where each player is a Pokemon trainer. As you travel around the board you can have random encounters with wild-pokemon, catch and train them, and eventually test out your skills against a gym. The first player to earn four gym badges wins!
There are a ton of resources available that show the end result of tile-based games. Fans, hobbyists etc, painstakingly capture entire dungeons, shops, towns and world maps etc. from their favorite games. The TileMapper project is a tool created using Unity which allows you to easily extract the unique tiles from a tile map (for educational purposes of course). It has a variety of features to make this process easy and even includes a feature to help you recreate the map using the newly captured tiles.
In this post we will begin the first real step of the project as we create the game screen – this will consist of a simple text field for user input and a scrollable text view showing the history of messages throughout the game. I will go in-depth on the description of code for the view controller as well as the manager object that records the message history. When we complete this lesson, you should be able to type messages into the text field and see them get appended to the log of messages in the text view.
You’ve probably been told before not to re-invent the wheel, but when it comes to my own code I couldn’t disagree more. I love re-inventing the wheel because it helps you understand why things are designed the way they are, and occasionally allows you to make something better. I’m currently “thinking out loud” about a whole new approach to the way I implement state machines that can provide functionality I had been wanting but not thought was possible – until now.
In this lesson we will write the code for the TicTacToe game model itself. This is just an abstract implementation that by itself isn’t playable, and doesn’t actually display anything. It simply has the idea of what the game is, what the rules are, and how to win, etc.
It’s finally time to see how everything works together. In this post we will review the “Table View’s” code. This complex component will utilize the TableViewCell, Spacer, Flow, and Container elements we have already discussed to complete a very flexible component which accomplishes every goal I set out to achieve.
The final “variable” implementation of our TableView helps to finish tying everything together. It breaks the four possible flows down into two categories: “Horizontal” or “Vertical”. You can think of this as a “Container”, because it causes the “Content” of the “ScrollRect” to adjust its size as necessary to fit all of the cells we have loaded. In addition, this script is responsible for deciding what kind of Flow to use based on the settings of the “Content” itself.
Just like we broke down the logic for determining the size and relative position of cells, we can also break down the logic for their flow. Should they be arranged from top-to-bottom, or bottom-to-top? How about right-to-left or left-to-right? In this lesson we will create a new interface so that we can easily support any of these options.
Making a scrolling list of cells isn’t that hard. Making a list that only creates as many cells as is necessary for display is slightly harder. Using a single component which can elegantly handle variations like whether or not the cell size can change or what direction the scrolling will occur, is pretty advanced. The best way to approach this kind of challenge is to break it down into manageable pieces.
A lot of the hard work performed by a table view is related to the reuse of its cells. We will need a component that will help ease the process of positioning those cells once they have been added to the table view. It will also need a way to animate into and out of the table view.