/// <summary> /// Creates an instance of GamePage /// </summary> /// <param name="pt">The type of protagonist to generate</param> /// <param name="et">The type of enemy to generate</param> public GamePage(ProtagonistType pt, EnemyType et, Level.Level _level, double protagonistWeight = 1, double enemyWeight = 1) { InitializeComponent(); level = _level; Protagonist = pt; Enemy = et; //Sets up the grid by decoding the int array and placing everything on the canvas level.SetupGrid(ref cvsPlayArea, ref cvsExitArea, pt, et); //Set the characters weights (for turning moments) GameGridManager.Instance.Characters[0].Weight = protagonistWeight; GameGridManager.Instance.Characters[1].Weight = enemyWeight; //Set the canvas of the singleton for easier access to the canvas (so the canvas does //not need to be referenced every tick for the collision detection visualisation to work) GameGridManager.Instance.GameCanvas = cvsPlayArea; //Setup the angles that open the exits ExitingManager.FindAnglesNeededToOpen(level.ExitLocation.HeightFromAnchor, level.ExitLocation.Length); keyboardInputTimer = new DispatcherTimer() { //Every ~1/1000 of a second update Interval = new TimeSpan(0, 0, 0, 0, 1) }; //Have the timer use the timertick event keyboardInputTimer.Tick += KeyboardInputTimerTick; rotationTimer = new DispatcherTimer() { //Update every 1/4 second Interval = new TimeSpan(0, 0, 0, 0, 250) }; rotationTimer.Tick += (s, e) => { double rotation = Rotation.AbsAngleDelta() * Algorithms.Rotation.RotationMultiplier(GameGridManager.Instance.Characters); GameGridManager.RotateStoryBoard((int)rotation); }; //If there is some networking involved within characters then start the communication manager and tie it to the message manager if (gameType == GameType.Networked) { CommunicationManager.Instance.SetupEnemyTypes(pt, et); //Also tell the server that it has received and loaded the map messageInstance = MessageManager.Instance; messageInstance.MessageHandler += HandleMessage; messageInstance.SendMessage("received"); //Also start the timers StartTimers(); } //Setups up AI timer if this is a singleplayer game if (gameType == GameType.Singleplayer) { aiTimer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 0, 0, 400) }; aiTimer.Tick += AiTimerOnTick; //Also show path tickbox chkShowPath.Visibility = Visibility.Visible; } //Allow keydown so that starts the game etc allowKeyDown = true; }