X hits on this document

295 views

0 shares

0 downloads

0 comments

67 / 102

Vector2.Zero, new Vector2(arrowScale, 0.1f), SpriteEffects.None, 0);

}

You may notice how the arrow’s origin is relative to the position of the catapult. This concludes our update to the game classes at this stage. We will now move to the GameplayScreen class to implement the final pieces of game logic.

145.

Open the GameplayScreen.cs class and Add the following constructor to the GameplayScreen class:

C#

public GameplayScreen()

{

   EnabledGestures = GestureType.FreeDrag |

       GestureType.DragComplete |

       GestureType.Tap;

   random = new Random();

}

This will enable drag and tap support in the game.

146.

Navigate to the LoadContent method and locate the comment “// TODO: Initialize enemy definitions”. Add the following code directly beneath it (the block below shows surrounding code as well, with existing code colored gray as before):

C#

...

computer.Initialize();

computer.Name = "Phone";

// Initialize enemy definitions

player.Enemy = computer;

computer.Enemy = player;

base.LoadContent();

...

147.

Override the Update method. This is where we will implement the turn logic:

C#

public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)

{

   float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

   // Check it one of the players reached 5 and stop the game

   if ((player.Catapult.GameOver || computer.Catapult.GameOver) &&

       (gameOver == false))

Page | 67

Document info
Document views295
Page views295
Page last viewedSun Dec 11 00:30:22 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments