Esempio n. 1
0
        public GameHistoryPage(ServerWorker _serverWorker, SystemSettings _systemSettings)
        {
            serverWorker   = _serverWorker;
            systemSettings = _systemSettings;
            NavigationPage.SetHasNavigationBar(this, false);
            this.Title           = "Games history";
            this.BackgroundColor = Color.FromHex("#39bafa");

            gamesListView = new ListView();
            StackLayout stackLayout = new StackLayout()
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Fill,
                Margin            = new Thickness(10, 10, 0, 10),
            };

            stackLayout.Children.Add(gamesListView);

            gameListViewEmptyMessage = new Label
            {
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                FontAttributes    = FontAttributes.Bold,
                Margin            = new Thickness(20, 10, 20, 10),
                Text = "Here we place your finished games.\nThanks for playing =)",
                HorizontalTextAlignment = TextAlignment.Center,
                IsVisible = false
            };
            stackLayout.Children.Add(gameListViewEmptyMessage);

            gamesListView.ItemTemplate  = new DataTemplate(typeof(UserPage.DateCellView));
            gamesListView.ItemSelected += async delegate
            {
                if ((UserPage.ElementsOfViewCell)gamesListView.SelectedItem == null)
                {
                    return;
                }
                if (isGameStarted)
                {
                    return;
                }
                isGameStarted = true;
                Game game = await GameProcesses.MakeSavedGame(serverWorker, ((UserPage.ElementsOfViewCell)gamesListView.SelectedItem).game.IdGame);

                //await GameProcesses.StartGame(serverWorker, game, () => false);
                GameStateInfo gameStateInfo = await serverWorker.TaskGetGameState(game.IdGame);

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

                gamesListView.SelectedItem = null;
                await UpdateGameList();

                //filesList.SelectedItem = null;
            };

            gamesListView.ItemsSource = customListViewRecords;

            _ = UpdateGameList();

            this.Content = stackLayout;
        }
Esempio n. 2
0
        public UserPage(ServerWorker _serverWorker, SystemSettings _systemSettings)
        {
            NavigationPage.SetHasNavigationBar(this, false);
            this.systemSettings = _systemSettings;
            this.serverWorker   = _serverWorker;
            this.Title          = "Started games";

            userprofilStackLayout = new StackLayout()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.Fill
            };
            StackLayout globalStackLayout = new StackLayout()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.Fill
            };

            relativeLayout = new RelativeLayout()
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.Fill
            };

            absoluteLayout = new AbsoluteLayout()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.Fill
            };
            userName = new Label()
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Start,
                TextColor         = Color.White,
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                FontAttributes    = FontAttributes.Bold,
                Margin            = new Thickness(20, 10, 20, 10),
            };

            var statisticsInfoLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                //BackgroundColor = Color.FromHex("#39bafa"),
                TextColor               = Color.White,
                FontAttributes          = FontAttributes.Bold,
                TextDecorations         = TextDecorations.Underline,
                HorizontalTextAlignment = TextAlignment.Center,
                Text     = "Statistics",
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                Margin   = new Thickness(0, 3, 0, 3),
            };

            performanceCenterLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                //BackgroundColor = Color.FromHex("#39bafa"),
                TextColor               = Color.White,
                FontAttributes          = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
            };

            performanceBorderLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                //BackgroundColor = Color.FromHex("#39bafa"),
                TextColor               = Color.White,
                FontAttributes          = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
            };

            RatingLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                //BackgroundColor = Color.FromHex("#39bafa"),
                TextColor               = Color.White,
                FontAttributes          = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
            };
            var ratingInfoLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                //BackgroundColor = Color.FromHex("#39bafa"),
                TextColor               = Color.White,
                FontAttributes          = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center,
                Text     = "Rating",
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
            };

            Image performanceBorderImage = new Image()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                //BackgroundColor = Color.FromHex("#39bafa"),
                Source        = "top_score_border.png",
                Margin        = 0,
                HeightRequest = ratingInfoLabel.FontSize
            };

            Image performanceCenterImage = new Image()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                //BackgroundColor = Color.FromHex("#39bafa"),
                Source        = "top_score_center.png",
                Margin        = 0,
                HeightRequest = ratingInfoLabel.FontSize
            };

            Grid gridPlayerInfo = new Grid
            {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(3, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(3, GridUnitType.Star)
                    },
                },
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Start,
                //ColumnSpacing = 1,
                RowSpacing = 0,
                Margin     = new Thickness(0, 10, 5, 0)
            };

            Grid gridPlayerScore = new Grid
            {
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1.3, GridUnitType.Star)
                    },
                },
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                },
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Start,
                //ColumnSpacing = 5,
                RowSpacing = 0,
                Margin     = new Thickness(0, 0, 0, 0)
            };


            gridPlayerScore.Children.Add(performanceCenterLabel, 0, 2);
            Grid.SetColumnSpan(performanceCenterLabel, 1);
            Grid.SetRowSpan(performanceCenterLabel, 1);

            gridPlayerScore.Children.Add(performanceCenterImage, 0, 1);
            Grid.SetColumnSpan(performanceCenterImage, 1);
            Grid.SetRowSpan(performanceCenterImage, 1);

            gridPlayerScore.Children.Add(performanceBorderLabel, 1, 2);
            Grid.SetColumnSpan(performanceBorderLabel, 1);
            Grid.SetRowSpan(performanceBorderLabel, 1);

            gridPlayerScore.Children.Add(performanceBorderImage, 1, 1);
            Grid.SetColumnSpan(performanceBorderImage, 1);
            Grid.SetRowSpan(performanceBorderImage, 1);

            gridPlayerScore.Children.Add(RatingLabel, 2, 2);
            Grid.SetColumnSpan(RatingLabel, 1);
            Grid.SetRowSpan(RatingLabel, 1);

            gridPlayerScore.Children.Add(ratingInfoLabel, 2, 1);
            Grid.SetColumnSpan(ratingInfoLabel, 1);
            Grid.SetRowSpan(ratingInfoLabel, 1);

            gridPlayerScore.Children.Add(statisticsInfoLabel, 0, 0);
            Grid.SetColumnSpan(statisticsInfoLabel, 3);
            Grid.SetRowSpan(statisticsInfoLabel, 1);


            gridPlayerInfo.Children.Add(userName, 0, 0);
            Grid.SetColumnSpan(userName, 1);
            Grid.SetRowSpan(userName, 1);

            gridPlayerInfo.Children.Add(gridPlayerScore, 1, 0);
            Grid.SetColumnSpan(gridPlayerScore, 1);
            Grid.SetRowSpan(gridPlayerScore, 1);


            var actionStandings = new TapGestureRecognizer();

            actionStandings.Tapped += async(s, e) =>
            {
                await Navigation.PushAsync(new StandingsPage(serverWorker, systemSettings));
            };
            gridPlayerScore.GestureRecognizers.Add(actionStandings);

            StackLayout stackLayoutListView = new StackLayout()
            {
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.Fill,
                Margin            = new Thickness(10, 0, 0, 0),
            };

            gamesListView = new ListView
            {
                VerticalOptions        = LayoutOptions.CenterAndExpand,
                ItemTemplate           = new DataTemplate(typeof(DateCellView)),
                IsPullToRefreshEnabled = true,
            };

            gameListViewEmptyMessage = new Label
            {
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                FontAttributes    = FontAttributes.Bold,
                Margin            = new Thickness(20, 10, 20, 10),
                Text = "Here we place your current games.\nTo play tap bot or friend.",
                HorizontalTextAlignment = TextAlignment.Center,
                IsVisible = false
            };

            gamesListView.RefreshCommand = new Command(async() =>
            {
                await UpdateGameList();
                gamesListView.IsRefreshing = false;
            });

            _ = UpdateGameList();

            gamesListView.ItemSelected += async delegate
            {
                if ((ElementsOfViewCell)gamesListView.SelectedItem == null)
                {
                    return;
                }
                if (isGameStarted)
                {
                    return;
                }
                Game game = await GameProcesses.MakeSavedGame(serverWorker, ((ElementsOfViewCell)gamesListView.SelectedItem).game.IdGame);

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

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

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

                    isGameStarted = true;
                }
                gamesListView.SelectedItem = null;
                //await UpdateGameList();
            };
            stackLayoutListView.Children.Add(gameListViewEmptyMessage);
            stackLayoutListView.Children.Add(gamesListView);

            StackLayout buttonStack = new StackLayout()
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Fill,
                Margin            = new Thickness(20, 10, 20, 10),
                Orientation       = StackOrientation.Horizontal
            };
            var stackLayoutPlayWithAnotherPlayer = new StackLayout
            {
                Spacing           = 0,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            Label labelPlayWithAnotherPlayer = new Label()
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                FontAttributes    = FontAttributes.Bold,
                Text = "Friend"
            };

            ImageButton PlayWithAnotherPlayer = new ImageButton()
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                //Text = "PVP",
                BackgroundColor = Color.FromHex("#39bafa"),//7ad3ff
                //TextColor = Color.White,
                IsEnabled     = true,
                Source        = "pvp.png",
                HeightRequest = 30,
                WidthRequest  = 60,
                Padding       = 0,
            };

            PlayWithAnotherPlayer.Clicked += async delegate
            {
                if (isGameStarted)
                {
                    return;
                }
                isGameStarted = true;
                await Navigation.PushAsync(new RealPlayerChoicePage(serverWorker, systemSettings));
            };


            var stackLayoutPlayWithBot = new StackLayout
            {
                Spacing           = 0,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            Label labelPlayWithBot = new Label()
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                FontAttributes    = FontAttributes.Bold,
                Text = "Bot"
            };
            ImageButton PlayWithBot = new ImageButton()
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                //Text = "Bot",
                BackgroundColor = Color.FromHex("#39bafa"),
                //TextColor = Color.White,
                Source        = "bot.png",
                HeightRequest = 30,
                WidthRequest  = 60,
                Padding       = 0,
            };

            PlayWithBot.Clicked += async delegate
            {
                if (isGameStarted)
                {
                    return;
                }
                isGameStarted = true;
                Game game = await GameProcesses.MakeGameWithBot(serverWorker);

                GameStateInfo gameStateInfo = await serverWorker.TaskGetGameState(game.IdGame);

                await Navigation.PushAsync(new GameField(serverWorker, systemSettings, game, gameStateInfo));
                await UpdateGameList();
            };

            /*var guide = new CarouselView
             * {
             *  IsVisible = false,
             *  IsEnabled = false,
             *  HorizontalScrollBarVisibility = ScrollBarVisibility.Always
             * };*/

            /*var guideImages = new ObservableCollection<CarouselItem>();
             * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guidePlayWithBot.png") });
             * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guidePlayWithFriend.png") });
             * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideRating.png") });
             * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideGoal.png") });
             * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideMove.png") });
             * guideImages.Add(new CarouselItem { Picture = ImageSource.FromFile("guideScore.png") });*/

            StackLayout stackLayoutHelp = new StackLayout
            {
                Spacing           = 0,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            Label helpLabel = new Label
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                FontAttributes    = FontAttributes.Bold,
                Text = "Help"
            };
            ImageButton helpButton = new ImageButton
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                BackgroundColor   = Color.FromHex("#39bafa"),
                Source            = "help.png",
                //IsEnabled = true,
                HeightRequest = 30,
                WidthRequest  = 60,
                Padding       = 0
            };


            Label infoLabel = new Label
            {
                Text              = "Press button",
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.Center,
            };

            introGuide = new List <GuideStep>
            {
                new GuideStep(null, "Welcome to Random Walk!\nTap to see game guide"),
                new GuideStep(stackLayoutHelp, "Check out our guide!"),
                new GuideStep(stackLayoutPlayWithBot, "Play with a bot!"),
                new GuideStep(stackLayoutPlayWithAnotherPlayer, "Play with a friend!"),
                new GuideStep(gridPlayerScore, "Check out your rating!"),
                new GuideStep(null, "Try to play with a bot now =)")
            };

            SKCanvasView canvasView = new SKCanvasView
            {
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                Margin            = new Thickness(0, 0, 0, 0),
                IsEnabled         = false,
                IsVisible         = false,
                HeightRequest     = systemSettings.ScreenHeight,
                WidthRequest      = systemSettings.ScreenWidth,
            };

            tourGuide = new TourGuide(canvasView);

            if (!Application.Current.Properties.ContainsKey("FirstUse"))
            {
                Application.Current.Properties["FirstUse"] = false;
                Application.Current.SavePropertiesAsync();
                tourGuide.StartIntroGuide(introGuide);
            }

            helpButton.Clicked += delegate
            {
                //StartGuide(guideImages, guide);
                List <GuideStep> introGuideShorten = new List <GuideStep>
                {
                    new GuideStep(null, "Welcome to Random Walk!\nTap to see game guide"),
                    new GuideStep(stackLayoutPlayWithBot, "Play with a bot!"),
                    new GuideStep(stackLayoutPlayWithAnotherPlayer, "Play with a friend!"),
                    new GuideStep(gridPlayerScore, "Check out your rating!"),
                    new GuideStep(null, "Enjoy the game =)")
                };

                tourGuide.StartIntroGuide(introGuideShorten);
            };

            stackLayoutPlayWithAnotherPlayer.Children.Add(PlayWithAnotherPlayer);
            stackLayoutPlayWithAnotherPlayer.Children.Add(labelPlayWithAnotherPlayer);

            stackLayoutPlayWithBot.Children.Add(PlayWithBot);
            stackLayoutPlayWithBot.Children.Add(labelPlayWithBot);

            stackLayoutHelp.Children.Add(helpButton);
            stackLayoutHelp.Children.Add(helpLabel);

            buttonStack.Children.Add(stackLayoutPlayWithAnotherPlayer);
            buttonStack.Children.Add(stackLayoutPlayWithBot);
            buttonStack.Children.Add(stackLayoutHelp);

            userprofilStackLayout.Children.Add(gridPlayerInfo);
            userprofilStackLayout.Children.Add(stackLayoutListView);
            userprofilStackLayout.Children.Add(buttonStack);


            //globalStackLayout.Children.Add(userprofilStackLayout);
            //globalStackLayout.Children.Add(canvasView);

            //absoluteLayout.Children.Add(globalStackLayout, new Rectangle(0, 0, App.ScreenWidth, App.ScreenHeight));
            //absoluteLayout.Children.Add(canvasView, new Rectangle(0, 0, App.ScreenWidth, App.ScreenHeight));
            //absoluteLayout.Children.Add(buttonStack, new Rectangle(0, App.ScreenHeight - 120, App.ScreenWidth, PlayWithBot.Height));

            relativeLayout.Children.Add(userprofilStackLayout,
                                        xConstraint: Constraint.Constant(0),
                                        yConstraint: Constraint.Constant(0),
                                        widthConstraint: Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width);
            }),
                                        heightConstraint: Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height);
            }));
            relativeLayout.Children.Add(canvasView,
                                        xConstraint: Constraint.Constant(0),
                                        yConstraint: Constraint.Constant(0),
                                        widthConstraint: Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width);
            }),
                                        heightConstraint: Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height);
            }));
            Content = relativeLayout;
        }