コード例 #1
0
        /// <summary>
        /// This method is invoked whenever someone from the server performs a
        /// dump action.
        /// </summary>
        /// <param name="actionSender">The person who performed the dump action</param>
        /// <param name="returnedTile"></param>
        public async Task <List <Tile> > PerformDumpAction(string actionSender, Tile returnedTile)
        {
            var tiles = _tileManager.PerformDumpAction(returnedTile);


            //
            // If the dump failed, return an empty tile list
            //

            if (tiles == null)
            {
                return(new List <Tile>());
            }

            var viewModel = GameBoardViewModel.GetInstance();

            _gameDataLogger.LogMove(actionSender, viewModel.GameTime, MoveType.Dump);

            viewModel.TilePileCount -= 2;

            var serverProxy = ServerProxy.GetInstance();

            if (serverProxy.messageSender != null)
            {
                // ToDo: Send the actionsender name here instead of the client name in case it's a bot that's dumping.
                await serverProxy.messageSender.SendMessage(PacketType.c_Dump);
            }

            return(tiles);
        }
コード例 #2
0
 public async void JoinRoom(Friend buddyToJoin)
 {
     var serverProxy = ServerProxy.GetInstance();
     await serverProxy.messageSender.SendMessage(
         PacketType.c_JoinRoom,
         buddyToJoin);
 }
コード例 #3
0
ファイル: Lobby.xaml.cs プロジェクト: jonathanyeung/ozwego
        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.ClientInitiateGame);
            }

            Frame.Navigate(typeof(GameBoardPrototype), args);
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        private async void AddFriendButtonTapped(object sender, TappedRoutedEventArgs e)
        {
            var serverProxy = ServerProxy.GetInstance();

            if (null != serverProxy.messageSender)
            {
                //ToDo: Get this data as a Friend type and use that in the SendMessage.
                throw new NotImplementedException();
                await serverProxy.messageSender.SendMessage(PacketType.c_SendFriendRequest, SearchBar.Text);
            }
        }
コード例 #6
0
        public async void InitiateMessageSend(string message)
        {
            var serverProxy = ServerProxy.GetInstance();

            var chat = new ChatMessage {
                Message = message, Sender = Settings.Alias
            };

            if (serverProxy.messageSender != null)
            {
                await serverProxy.messageSender.SendMessage(PacketType.c_Chat, chat);
            }
        }
コード例 #7
0
        private async void CheckIfAvailableClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DataBaseMessageProcessor.DataBaseMessageReceivedEvent += AliasAvailableCallback;

            _enteredAlias = AliasTextBox.Text;

            var serverProxy = ServerProxy.GetInstance();

            if (serverProxy.messageSender != null)
            {
                await serverProxy.messageSender.SendMessage(PacketType.c_QueryIfAliasAvailable, _enteredAlias);
            }
        }
コード例 #8
0
        public async void RejectFriendRequest(Friend friend)
        {
            PendingFriendRequests.Remove(friend);

            //ToDo: This null check is no bueno.  This needs to get sent at some point,
            // this call will make the packet never get sent to the server.
            var serverProxy = ServerProxy.GetInstance();

            if (null != serverProxy.messageSender)
            {
                await serverProxy.messageSender.SendMessage(
                    PacketType.c_RejectFriendRequest,
                    friend);
            }
        }
コード例 #9
0
        async void SearchBar_KeyUp(object sender, KeyRoutedEventArgs e)
        {
            if (SearchBar.Text != "")
            {
                FriendsSearchUI.Visibility = Visibility.Visible;

                var serverProxy = ServerProxy.GetInstance();
                if (null != serverProxy.messageSender)
                {
                    await serverProxy.messageSender.SendMessage(PacketType.c_FindBuddyFromGlobalList, SearchBar.Text);
                }
            }
            else
            {
                FriendsSearchUI.Visibility = Visibility.Collapsed;
            }
        }
コード例 #10
0
        //public async void JoinRoom(string accountAddress)
        //{
        //    var serverProxy = ServerProxy.GetInstance();
        //    await serverProxy.messageSender.SendMessage(
        //            PacketType.c_JoinRoom,
        //            accountAddress);
        //}


        public async void LeaveRoom()
        {
            //
            // Send a message to the server that you're leaving.
            //

            var serverProxy = ServerProxy.GetInstance();

            if (null != serverProxy.messageSender)
            {
                await serverProxy.messageSender.SendMessage(PacketType.c_LeaveRoom);
            }


            //
            // Add the client (now with a new room GUID) back to the room list.
            //

            var roomManager = RoomManager.GetInstance();

            roomManager.RoomMembers.Clear();
            AddMemberToRoom(Settings.userInstance);
        }
コード例 #11
0
ファイル: MainPage.xaml.cs プロジェクト: jonathanyeung/ozwego
        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);
            }
        }
コード例 #12
0
        /// <summary>
        /// Contains methods that are called when game action messages are received.
        /// </summary>
        /// <summary>
        /// This method is invoked whenever someone (either local or from the server) performs a
        /// peel action.
        /// </summary>
        /// <param name="actionSender">The person who performed the dump action</param>
        /// <param name="IsSenderLocal">If the person performing the peel action is local (not from server) or not</param>
        public async void PeelActionReceived(string actionSender, bool IsSenderLocal = true)
        {
            var serverProxy = ServerProxy.GetInstance();
            var roomManager = RoomManager.GetInstance();
            var viewModel   = GameBoardViewModel.GetInstance();


            //
            // If there are enough tiles left, then do a peel.  Otherwise, if there are not enough
            // tiles, then actionSender has won the game.
            //

            if (_tileManager.GetPileCount() >= (roomManager.RoomMembers.Count + _localPlayers.Count - 1))
            {
                var tiles = _tileManager.PerformPeelAction(roomManager.RoomMembers.Count + _localPlayers.Count - 1);

                if (null == tiles)
                {
                    return;
                }


                //
                // Update the hands of all of the players with one of the returned tiles from the peel.
                // If it's the human player's hand, update the UI too with the returned tile.
                //

                foreach (IPlayer player in _localPlayers)
                {
                    if (player.Alias == _humanPlayer.Alias)
                    {
                        OnPeelOccurred(tiles[0].TileContents, actionSender);
                    }

                    // ToDo: This line can possibly throw an out of bounds exception.
                    player.PeelActionReceived(tiles[0]);
                    tiles.RemoveAt(0);
                }


                //
                // Update UI.
                //

                await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    //
                    // Subtract total online players + bots.  Subtract one b/c the human player is
                    // double counted.
                    //

                    viewModel.TilePileCount -=
                        (roomManager.RoomMembers.Count + _localPlayers.Count - 1);
                });


                //
                // If the person performing the peel is local, then send a message to the server informing
                // of the peel.  Otherwise, if it came from the server, then don't send a message
                // to the server.
                //

                if ((serverProxy.messageSender != null) && IsSenderLocal)
                {
                    // ToDo: This will send the incorrect message to the server if a bot has peeled and not the client.
                    await serverProxy.messageSender.SendMessage(PacketType.c_Peel);
                }


                //
                // Log the Peel event
                //

                _gameDataLogger.LogMove(actionSender, viewModel.GameTime, Storage.MoveType.Peel);
            }
            else
            {
                if ((serverProxy.messageSender != null) && IsSenderLocal)
                {
                    await serverProxy.messageSender.SendMessage(PacketType.c_Victory);
                }

                EndGame(actionSender);
            }
        }
コード例 #13
0
ファイル: MainPage.xaml.cs プロジェクト: jonathanyeung/ozwego
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            try
            {
                var serverProxy = ServerProxy.GetInstance();
                await serverProxy.Authenticate();

                serverProxy.Connect();
            }
            catch (Exception)
            {
                //ToDo: This has thrown a LiveConnectException during debugging.  Need to handle it properly here.
                throw;
            }


            //
            // Background grid initialization
            //

            //RootGrid.Children.Insert(0, _background.PolygonGrid);

            //_background.BeginSubtleAnimation();


            // This frame is hidden, meaning it is never shown.  It is simply used to load
            // each scenario page and then pluck out the input and output sections and
            // place them into the UserControls on the main page.
            HiddenFrame            = new Windows.UI.Xaml.Controls.Frame();
            HiddenFrame.Visibility = Windows.UI.Xaml.Visibility.Collapsed;


            //
            // Load OOBE if this is first launch.
            //

            if (Settings.IsFirstLaunch)
            {
                if (!StandardPopup.IsOpen)
                {
                    StandardPopup.IsOpen = true;
                }
                LoadOOBEView(typeof(OOBEPage1));
            }


            //
            // Friend Lobby Initialization
            //

            var roomManager = RoomManager.GetInstance();

            RoomListUI.ItemsSource = roomManager.RoomMembers;

            var mainPageViewModel = MainPageViewModel.GetInstance();

            ChatWindow.ItemsSource = mainPageViewModel.ChatMessages;
            DataContext            = mainPageViewModel;



            //ContentRoot.Children.Add(HiddenFrame);

            LoadColumnView(typeof(FriendsList));
        }
コード例 #14
0
ファイル: MainPage.xaml.cs プロジェクト: jonathanyeung/ozwego
        private void LogOutButton_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            var serverProxy = ServerProxy.GetInstance();

            serverProxy.Disconnect();
        }