/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (doReplay == false) { loopId += 1; Console.WriteLine("Q pressed: " + Keyboard.GetState().IsKeyUp(Keys.Q)); input.Keys = Keyboard.GetState().GetPressedKeys(); recordReplay(loopId, input, currentStage.Id); currentStage.Update(gameTime, input); } else { loopId += 1; if (next == null) { next = replayEvents.Dequeue(); } if (loopId == next.LoopId) { Console.WriteLine(next.ToString()); input.Keys = next.Keys; if (replayEvents.Count > 0) { next = replayEvents.Dequeue(); } } else { input.Keys = noKeys; } currentStage.Update(gameTime, input); } elapsedTime += gameTime.ElapsedGameTime; if (elapsedTime > System.TimeSpan.FromSeconds(1)) { elapsedTime -= TimeSpan.FromSeconds(1); frameRate = frameCounter; frameCounter = 0; } base.Update(gameTime); }
public static Queue <ReplayEvent> Load(string filename) { //TODO: Determine how to handle file issues (non existent, corrupt) and show the errors appropriately from back to front var list = new Queue <ReplayEvent>(); using (StreamReader sr = new StreamReader(filename)) { string s = ""; while ((s = sr.ReadLine()) != null) { list.Enqueue(ReplayEvent.GetEvent(s)); } } return(list); }