Ejemplo n.º 1
0
        public async Task GetSelectedGameData(int GameId)
        {
            Game = await GameProcesses.MakeSavedGame(serverWorker, GameId);

            CancelGame = await GameProcesses.StartGame(serverWorker, Game);

            GameStateInfo = await serverWorker.TaskGetGameState(Game.IdGame);
        }
Ejemplo n.º 2
0
        public RealPlayerChoicePage(ServerWorker _serverWorker, SystemSettings systemSettings)
        {
            serverWorker         = _serverWorker;
            this.BackgroundColor = Color.FromHex("#39bafa");
            NavigationPage.SetHasNavigationBar(this, false);

            /*Grid grid = new Grid
             * {
             *  RowDefinitions =
             *  {
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *      new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
             *  },
             *  ColumnDefinitions =
             *  {
             *      new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
             *      new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
             *      new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
             *  },
             *  Margin = new Thickness(5, 15, 5, 15),
             * };*/

            var stackLayout = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.Fill,
                Margin            = new Thickness(10, 0, 10, 0),
                Spacing           = 0,
            };

            Label headLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text           = "Play with friend",
                TextColor      = Color.White,
                FontAttributes = FontAttributes.Bold,
                FontSize       = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                Margin         = new Thickness(0, 10),
            };

            Entry entryLogin = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Placeholder       = "Enter player login",
                TextColor         = Color.White,
                BackgroundColor   = Color.FromHex("#39bafa"),
                PlaceholderColor  = Color.LightGray,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                Margin            = new Thickness(0, 5),
            };

            //Подумай над удалением после выбора
            entryLogin.TextChanged += async delegate
            {
                try
                {
                    if (entryLogin != null && entryLogin.Text != null && entryLogin.Text.Length > 0 && !hasLoginSelected)
                    {
                        playersList = await serverWorker.TaskGetPlayerList(entryLogin.Text);

                        if (playersList != null)
                        {
                            List <ElementsOfViewCell> currentElementsList = new List <ElementsOfViewCell>();
                            for (int i = 0; i < playersList.Count; i++)
                            {
                                currentElementsList.Add(new ElementsOfViewCell(playersList[i].Login, playersList[i].IdPlayer));
                            }
                            listPlayer.ItemsSource  = currentElementsList;
                            listPlayer.SelectedItem = null;
                        }
                        else
                        {
                            listPlayer.ItemsSource = null;
                        }
                    }
                    else
                    {
                        listPlayer.ItemsSource = null;
                        if (hasLoginSelected)
                        {
                            hasLoginSelected = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    string exceptionStackTrace = ex.StackTrace;
                }
            };

            listPlayer = new ListView
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };
            listPlayer.ItemTemplate  = new DataTemplate(typeof(DateCellView));
            listPlayer.ItemSelected += delegate
            {
                hasLoginSelected = true;
                if ((ElementsOfViewCell)listPlayer.SelectedItem == null)
                {
                    return;
                }
                string selectedLogin = ((ElementsOfViewCell)listPlayer.SelectedItem).Login;
                selectedIdPlayer        = ((ElementsOfViewCell)listPlayer.SelectedItem).IdPlayer;
                entryLogin.Text         = selectedLogin;
                listPlayer.ItemsSource  = null;
                listPlayer.SelectedItem = null;
            };
            //listPlayer.ItemsSource =
            Button backButton = new Button()
            {
                Text            = "Back",
                TextColor       = Color.White,
                FontAttributes  = FontAttributes.Bold,
                BackgroundColor = Color.FromHex("#69c6f5")
            };

            backButton.Clicked += async delegate { await Navigation.PopAsync(); };
            Button playButton = new Button()
            {
                Text            = "Play!",
                TextColor       = Color.White,
                FontAttributes  = FontAttributes.Bold,
                BackgroundColor = Color.FromHex("#69c6f5"),
                HeightRequest   = 40,
                VerticalOptions = LayoutOptions.Center,
            };

            playButton.Clicked += async delegate
            {
                //проверим введённый ник
                if (playersList != null)
                {
                    selectedIdPlayer = -1;
                    foreach (var player in playersList)
                    {
                        if (player.Login == entryLogin.Text)
                        {
                            selectedIdPlayer = player.IdPlayer;
                        }
                    }
                }

                if (entryLogin.Text == "" || entryLogin.Text is null || selectedIdPlayer != -1) // !(await serverWorker.TaskCheckLogin(entryLogin.Text))
                {
                    Game game = await GameProcesses.MakeGameWithPlayer(serverWorker, selectedIdPlayer);

                    cancelGame = await GameProcesses.StartGame(serverWorker, game);

                    if (!cancelGame)
                    {
                        GameStateInfo gameStateInfo = await serverWorker.TaskGetGameState(game.IdGame);

                        Navigation.RemovePage(this);
                        await Navigation.PushAsync(new GameField(serverWorker, systemSettings, game, gameStateInfo));

                        isGameStarted = true;
                    }
                    else
                    {
                        await serverWorker.TaskCancelGame(game.IdGame);
                    }
                }
Ejemplo n.º 3
0
 public async Task GetCancelGame()
 {
     CancelGame = await GameProcesses.StartGame(serverWorker, Game);
 }