Game Development Reference
In-Depth Information
(b) Another method in the
string
class is the
Replace
method. This method re-
turns a new string in which each character that corresponds to the character
given as the first parameter is replaced by the character given as the second
parameter. For example:
"Good morning".replace('o','u')
// returns "Guud murning"
"A+2+#?".replace('+','9')
// returns "A929#?"
Implement the
Replace
method (using other methods of the
string
class where
necessary).
(c) Now let's have a look at the method
EndsWith
, which returns whether a string
ends with the string passed as a parameter. For example:
"Allyourbasearebelongtous".endsWith("belongtous")
// returns true
Implement the
EndsWith
method. You may use existing methods in the
string
class, except for the
Substring
and
IndexOf
methods.
3.
Highway
Have a look at the program below. The program should draw a line of cars on
the highway, as can be seen from the screenshot below. Every third car is a truck,
and every second truck is a combination with a trailer.
public class
Highway : Game
{
public
SpriteBatch spriteBatch;
public
Texture2D wheel, car, truck, connection, trailer;
static void
Main()
{
Highway game =
new
Highway();
game.Run();
}
public
Highway()
{
graphics =
new
GraphicsDeviceManager(
this
);
graphics.PreferredBackBufferWidth = 1800;
graphics.PreferredBackBufferHeight = 80;
Content.RootDirectory = "Content";
// TODO: missing part of the constructor
}