Game Development Reference
In-Depth Information
adding new code. There are a large number of automatic refactorings, but the
following three are the ones I use most commonly.
Renaming
Namespace, class, member, field, and variable names should all be descriptive
and useful. Here's some example code that has a poor naming style.
class GameThing
{
int _health ¼ 10;
int _var2 ¼ 1;
public void HealthUpdate(int v)
{
_health ¼ _health - Math.Max(0, v - _var2);
}
}
GameThing is a poor name unless every single thing in your game is going to
have a health value. It would be better to name it GameCreature . Imagine if
you were halfway through development of a large game. The GameThing class is
repeated hundreds of times across many different files. If you wanted to rename
the GameThing class manually, you could either hand edit all those hundreds of
files or carefully use Visual Studio's Find and Replace tool (this codebase also has
many entirely unrelated classes using similar names such as GameThingMa-
nager , which the Find and Replace tool could accidentally change). Visual
Studio's refactor function can rename the GameThing class safely with only
two clicks of the mouse.
Right-click GameThing . This will bring up a context menu, as shown in
Figure 4.5. Choose the Refactor menu and click Rename.
A new dialog box will appear, and the new name can be entered, as shown in
Figure 4.6.
This will now rename the class everywhere it appears in code. There are options
to also rename this class in comments and strings. The same process can be done
for the function and variable names, resulting in something like this.
class GameCreature
{
int _health ¼ 10;
 
Search WWH ::




Custom Search