public ConnectionPage()
 {
     //TestFlyweight.CreateObstaclesWithFlyWeight();
     //TestFlyweight.CreateObstaclesWithoutFlyWeight();
     _gameHubConnection = GameHubConnection.GetInstance();
     InitializeComponent();
 }
 public static GameHubConnection GetInstance()
 {
     lock (_threadLock) //using the lock token
     {
         if (_instance == null)
         {
             _instance = new GameHubConnection();
         }
     }
     Debug.WriteLine("Returning GameHubConnection Instance");
     return(_instance);
 }
Ejemplo n.º 3
0
 //private readonly object syncLock = new object();
 public WaitingForGameScreen()
 {
     InitializeComponent();
     _gameHubConnection = GameHubConnection.GetInstance();
     _gameHubConnection.RegisterMethod("StartGame", new Action <GamePlayersDto>((GamePlayersDto game) =>
     {
         Dispatcher.Invoke((() =>
         {
             NavigationService.Navigate(new Game(game.LocalPlayerName, game.OponentPlayerName, game.GameId));
         }));
     }
                                                                                ));
     PlayerReady();
 }
Ejemplo n.º 4
0
        public Game(string localPlayerName, string oponentPlayerName, string gameId)
        {
            _gameId           = gameId;
            PlayerOne.Name    = localPlayerName;
            PlayerTwo.Name    = oponentPlayerName;
            DataContext       = PlayerOne;
            debug.DataContext = PlayerOne;
            InitializeComponent();
            PlayerOne.GameOver += OnGameOver;
            Background_Canvas.Children.RemoveRange(3, Background_Canvas.Children.Count);
            player2.DataContext        = PlayerTwo;
            counterOponent.DataContext = PlayerTwo;
            //debug.Show();

            //get game hub connection and register methods
            _gameHubConnection = GameHubConnection.GetInstance();
            _gameHubConnection.RegisterMethod("UpdateOponent", new Action <Object>((Object playerRequest) =>
            {
                Dispatcher.Invoke((Action)(async() =>
                {
                    var player = JsonConvert.DeserializeObject <PlayerDto>(playerRequest.ToString());
                    await UpdateOponent(player);
                }));
            }
                                                                                   ));

            _gameHubConnection.RegisterMethod("DeleteItem", new Action <Object>((Object itemRequest) =>
            {
                Dispatcher.Invoke((Action)(async() =>
                {
                    var item = JsonConvert.DeserializeObject <ItemDto>(itemRequest.ToString());
                    await DeleteItem(item);
                }));
            }
                                                                                ));

            _gameHubConnection.RegisterMethod("EndGame", new Action <GameEndDto>((GameEndDto request) =>
            {
                Dispatcher.Invoke((Action)(async() =>
                {
                    await EndGame(request);
                }));
            }
                                                                                 ));

            //building map
            //var builder = new MapBuilder(new EasyGameObjectFactory());
            var builder  = new MapBuilder(new MediumGameObjectFactory(), Background_Canvas);
            var director = new MapDirector(builder);

            director.ConstructMap();
            _items = builder.GetMap();

            //setting up command and invoker
            Models.Commands.ICommand command = new SpeedCommand(PlayerOne);
            _invoker = new Invoker();
            _invoker.SetCommand(command);

            //sound adapter
            _soundAdapter = new NullObjectSoundAdapter();
            _soundAdapter.Play();

            //animation adapter
            _playerOneAnimationAdapter  = new PlayerAnimationAdapter(Player_Canvas);
            _playerTwoAnimationAdapter  = new PlayerAnimationAdapter(player2);
            _starAnimationAdapter       = new ObjectAnimationAdapter(new StarAnimationController(Background_Canvas));
            _starShieldAnimationAdapter = new ObjectAnimationAdapter(new StarShieldAnimationController(Background_Canvas));

            //prototype
            //TestingDeepAndShallowCopies();

            //Interpreter
            _expressionParser = new ExpressionParser();

            //Memento
            _careTaker = new CareTaker();

            GraphicalEffects.EndTransiton(Background_Canvas, GamePage);

            PhysicsTimer          = new DispatcherTimer();
            PhysicsTimer.Tick    += PhysicsTimerTick;
            PhysicsTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
            PhysicsTimer.Start();
            //task1 = new Task(PhysicsTimer.Start);

            AnimationTimer          = new DispatcherTimer();
            AnimationTimer.Tick    += AnimationTimerTick;
            AnimationTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            AnimationTimer.Start();
            //task2 = new Task(AnimationTimer.Start);

            StarTimer          = new DispatcherTimer();
            StarTimer.Tick    += StarTimerTick;
            StarTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            StarTimer.Start();
            //task3 = new Task(CoinTimer.Start);

            JumpingTimer          = new DispatcherTimer();
            JumpingTimer.Tick    += JumpingTimerTick;
            JumpingTimer.Interval = new TimeSpan(0, 0, 0, 0, 400);
            JumpingTimer.Start();
            //task4 = new Task(JumpingTimer.Start);

            NetworkTimer          = new DispatcherTimer();
            NetworkTimer.Tick    += NetworktTimerTick;
            NetworkTimer.Interval = new TimeSpan(0, 0, 0, 0, 20);
            NetworkTimer.Start();
            //task5 = new Task(NetworktTimer.Start);

            //task1.Start();
            //task2.Start();
            //task3.Start();
            //task4.Start();
            //task5.Start();
        }