jwcolby
jwcolby at colbyconsulting.com
Sat Oct 15 09:09:07 CDT 2011
I am writing a game in XNA and C#.Net. The purpose is simply to learn more about C#. One of the things I want to do with this is to learn inheritance. The game has visual objects with bitmaps / sprites. Each cell (screen location) in the game will have a hexagonal bitmap, such as terrain - forest, mountain, water and so forth. These bitmaps are contained in bitmap sheets with X/Y pointers into the sheets for loading the area of the sheet into the object. Obviously these cells are pretty simple and do not move. However another class of objects, military units, have a hex bitmap as well but also have attributes such as how much damage they inflict in combat, how much damage they can absorb before being destroyed etc. Before we go there, I will not be using NOSQL to process this stuff! ;) So it seems that I could do a cell class which holds a bitmap pointer and an x/y location pair. Then my military units could inherit from the cell since they need the attributes of the cell. Beyond that however things get gray. All military units have properties such damage inflicted / absorbed, but there are also properties specific to the military units. Land units cannot enter the water, ships cannot enter the land. Air units can fly over either. Things like that. So it feels like I build a "military unit" class, inheriting from cell, with the commonality of all military units. Then what? Three subclasses of Land, water, air? This is all pretty much new ground for me and I am excited to have such a clear cut reason to use inheritance. -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it