Exemple #1
0
        public async Task Initialize(GameBoardNavigationArgs args)
        {
            _gameConnectionType = args.GameConnectionType;
            _gameMode           = args.GameMode;

            _tileManager = TileManager.GetInstance();
            await _tileManager.InitializeForNewGame();

            _botManager = BotManager.GetInstance();

            _gameBoard = GameBoard.GetInstance();
            _gameBoard.ClearBoard();

            _dictionary = Dictionary.GetInstance();
            await _dictionary.PopulateDictionary();

            InitializeGameClock();

            _humanPlayer = new HumanPlayer();

            _localPlayers.Clear();
            _localPlayers.Add(_humanPlayer);

            _botManager.ClearBotList();

            for (int i = 0; i < args.BotCount; i++)
            {
                _botManager.CreateBot(5);
            }

            foreach (IRobot bot in _botManager.BotList)
            {
                _localPlayers.Add(bot);
            }

            foreach (IPlayer player in _localPlayers)
            {
                player.InitializeForGame();
            }

            OnInitializeComplete();
        }
        private async void StartGame_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            //
            // Only allow the room host to initiate a game.
            //

            var roomManager = RoomManager.GetInstance();

            if (roomManager.Host.EmailAddress != Settings.EmailAddress)
            {
                return;
            }

            var args = new GameBoardNavigationArgs()
            {
                GameConnectionType = GameConnectionType.Online,
                BotCount = 0
            };

            var serverProxy = ServerProxy.GetInstance();
            if (serverProxy.messageSender != null)
            {
                await serverProxy.messageSender.SendMessage(PacketType.c_InitiateGame);
            }

            Frame.Navigate(typeof(GameBoardPrototype), args);
        }
        private void OnGameFoundEvent(object sender)
        {
            GameBoardNavigationArgs args = new GameBoardNavigationArgs()
            {
                GameConnectionType = GameConnectionType.Online,
                BotCount = 0
            };

            Frame.Navigate(typeof(GameBoardPrototype), args);
        }
        private async void OnMatchmakingButtonTapped(object sender, TappedRoutedEventArgs e)
        {
            //
            // Navigate to the page.
            //

            MainToMatchmaking.Begin();

            OnNavigatedToMatchmakingPane();


            //
            // Send the matchmaking begin packets to the server if connected.
            //

            var serverProxy = ServerProxy.GetInstance();

            // ToDo: Replace all of these null check calls of messageSender with checks to the connection status.
            if (serverProxy.messageSender != null)
            {
                await serverProxy.messageSender.SendMessage(PacketType.c_StartingMatchmaking);
            }
            else
            {

                GameBoardNavigationArgs args = new GameBoardNavigationArgs()
                {
                    GameConnectionType = GameConnectionType.Local,
                    BotCount = 1
                };

                // ToDo: If the user navigates away from this page, then the navigation to the gameboard needs to be cancelled.
                await Task.Delay(5000);

                // ToDo: Re-enable.
                //Frame.Navigate(typeof(GameBoardPrototype), args);
            }
        }
        private void OnGameDebugButtonTapped(object sender, TappedRoutedEventArgs e)
        {
            GameBoardNavigationArgs args = new GameBoardNavigationArgs()
            {
                GameConnectionType = GameConnectionType.Local,
                BotCount = 0
            };

            Frame.Navigate(typeof(GameBoardPrototype), args);
        }
        private async void OnPlayAgainClicked(object sender, RoutedEventArgs e)
        {
            switch (_navigationArgs.GameMode)
            {
                case GameMode.Friendly:
                    Frame.Navigate(typeof(MainPage)); //ToDo: Navigate to the Lobby pane of the Main Page
                    break;

                case GameMode.Matchmaking:
                    var serverProxy = ServerProxy.GetInstance();

                    if (serverProxy.messageSender != null)
                    {
                        await serverProxy.messageSender.SendMessage(PacketType.ClientStartingMatchmaking);
                        Frame.Navigate(typeof(MainPage)); //ToDo: Navigate to the Matchmaking pane of the Main Page
                    }
                    else
                    {
                        var args = new GameBoardNavigationArgs
                        {
                            GameConnectionType = GameConnectionType.Local,
                            BotCount = 1
                        };

                        Frame.Navigate(typeof(GameBoardPrototype), args);
                    }

                    break;

                default:
                    Frame.Navigate(typeof(MainPage));
                    break;
            }
        }
        public override void DoActions(PacketType packetType, object data, string senderEmailAddress)
        {
            var roomManager = RoomManager.GetInstance();
            Friend friend;

            switch (packetType)
            {
                case PacketType.s_RoomList:
                    var friendList = data as FriendList;

                    if (friendList != null)
                    {
                        foreach (var f in friendList.Friends)
                        {
                            roomManager.AddMemberToRoom(f);
                        }
                    }

                    break;

                case PacketType.s_UserJoinedRoom:
                    friend = data as Friend;

                    if (friend != null)
                    {
                        roomManager.AddMemberToRoom(friend);
                    }

                    break;

                case PacketType.s_UserLeftRoom:
                    friend = data as Friend;

                    if (friend != null)
                    {
                        roomManager.RemoveMemberFromRoom(friend);
                    }

                    break;

                case PacketType.s_BeginGameInitialization:
                    var currentFrame = Window.Current.Content as Frame;
                    if (currentFrame != null)
                    {
                        var args = new GameBoardNavigationArgs()
                        {
                            GameConnectionType = GameConnectionType.Online,
                            BotCount = 0
                        };

                        currentFrame.Navigate(typeof(GameBoardPrototype), args);
                    }
                    break;

                case PacketType.s_Chat:
                    var chatmessage = data as ChatMessage;

                    if (chatmessage != null)
                    {
                        roomManager.ChatMessageReceived(chatmessage);
                    }

                    break;

                case PacketType.s_HostTransfer:
                    friend = data as Friend;

                    if (friend != null)
                    {
                        roomManager.ChangeRoomHost(friend);
                    }

                    break;

                default:
                    throw new ArgumentException(
                            "Passed PacketType is not meant to be handled by this MessageProcessor");
            }
        }
        public async Task Initialize(GameBoardNavigationArgs args)
        {
            _gameConnectionType = args.GameConnectionType;
            _gameMode = args.GameMode;

            _tileManager = TileManager.GetInstance();
            await _tileManager.InitializeForNewGame();

            _botManager = BotManager.GetInstance();

            _gameBoard = GameBoard.GetInstance();
            _gameBoard.ClearBoard();

            _dictionary = Dictionary.GetInstance();
            await _dictionary.PopulateDictionary();

            InitializeGameClock();

            _humanPlayer = new HumanPlayer();

            _localPlayers.Clear();
            _localPlayers.Add(_humanPlayer);

            _botManager.ClearBotList();

            for (int i = 0; i < args.BotCount; i++)
            {
                _botManager.CreateBot(5);
            }

            foreach (IRobot bot in _botManager.BotList)
            {
                _localPlayers.Add(bot);
            }

            foreach (IPlayer player in _localPlayers)
            {
                player.InitializeForGame();
            }

            OnInitializeComplete();
        }