Game Development Reference
In-Depth Information
_health--;
if (_health <= 0)
{
_dead ΒΌ true;
}
}
}
class Invader : Spacecraft
{
}
class FlyingSaucer : Spacecraft
{
}
class Player : Spacecraft
{
}
Now that the code is all in one place, it's much easier to change in the future.
C++
C++ does not follow the DRY principle from its very foundations. In C# there is
one file that defines classes and methods: the .cs file. In C++, there is a header
defining the class and all the method prototypes. A second file with a .cpp ex-
tension defines the functions again but this time with their bodies. So you have
something like the following.
// Header File Player.h
class Player
{
void TeleportTo(Vector position);
};
// CPP File Player.cpp
void Player::TeleportTo(Vector position)
{
// code
}
If we want to add a return value, to report if the teleport was successful, the code
must be modified in two places. That's not DRY! In C++, the class im-
plementation is defined in one file and the class interface in another; this code
duplication is shown in the above code snippet. All but the smallest C++
 
Search WWH ::




Custom Search