Esempio n. 1
0
        protected override void OnAppearing()
        {
            singleIcon.Source = ImageSource.FromFile("playerSelect");
            singleIcon.ScaleTo(1, 1);
            multiIcon.Source = ImageSource.FromFile("greyPlayerSelect");

            singleplayer.TextColor = Color.Black;
            multiplayer.TextColor  = Color.Gray;

            singleSelected = true;
            multiSelected  = false;

            sqlDatabase = new SQLDatabase();

            try
            {
                easyHighScore = sqlDatabase.GetEasyHighscore(1);

                roundText.Text = "Round " + easyHighScore.Round;

                if (!string.IsNullOrEmpty(easyHighScore.Name))
                {
                    nameText.Text = "By " + easyHighScore.Name;
                }
            }

            catch
            {
                roundText.FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label));
                roundText.Text     = "You have no highscores, \n let's go make some!";
                nameText.Text      = "";
            }

            SpinMe();
        }
Esempio n. 2
0
 // Add a new Easy highscore entry.
 public void AddEasyHighscore(EasyHighscore score)
 {
     connection.Insert(score);
 }
Esempio n. 3
0
 // Update Easy highscore Data.
 public void UpdateEasyHighscore(EasyHighscore easyHighscore)
 {
     connection.Update(easyHighscore);
 }
Esempio n. 4
0
        public void GridPage()
        {
            int totalScores = 0;

            if (easyHighScores.Count == 0)
            {
                totalScores = 1;
                a           = 1;
            }

            else if (easyHighScores.Count > 0 && easyHighScores.Count < 10)
            {
                totalScores = easyHighScores.Count;
            }

            else if (easyHighScores.Count >= 10)
            {
                totalScores = 10;
            }


            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());
            gridLayout.RowDefinitions.Add(new RowDefinition());

            gridLayout.ColumnDefinitions.Add(new ColumnDefinition());



            for (int rowIndex = 0; rowIndex < 10; rowIndex++)             // Adds all the Rows
            {
                for (int columnIndex = 0; columnIndex < 1; columnIndex++) // Adds all the columns
                {
                    if (counter == totalScores)                           // Amount of images to display
                    {
                        break;
                    }


                    var starTopImage = new Image {
                        Margin = new Thickness(0, 10, 0, 0)
                    };
                    var starBotImage = new Image {
                        Margin = new Thickness(0, 0, 0, 10)
                    };
                    // var scoreButton = new Button { HeightRequest = 100, WidthRequest = 50, BackgroundColor = Color.Blue, TextColor = Color.White };

                    var layout = new AbsoluteLayout {
                        HeightRequest = 100, BackgroundColor = Color.Transparent, WidthRequest = 500, Margin = new Thickness(0, 20, 0, 0)
                    };

                    var scoreIndexStack = new StackLayout {
                        BackgroundColor = Color.FromHex("#32AE96"), HeightRequest = 100, WidthRequest = 50, Margin = new Thickness(20, 0, 0, 0)
                    };


                    var dateFrame = new Frame {
                        BackgroundColor = Color.FromHex("#32AE96"), HasShadow = false, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(5, 5, 5, 5), Margin = new Thickness(0, 10, 0, 0)
                    };

                    var scoreFrame = new Frame {
                        HasShadow = true, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(15, 15, 15, 15), Margin = new Thickness(20, 0, 20, 0)
                    };
                    var scoreStack = new StackLayout {
                        BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(20, 20, 20, 10)
                    };


                    var scoreIndexLabel = new Label {
                        TextColor = Color.White, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand
                    };
                    var scoreLabel = new Label {
                        HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.Start
                    };
                    var nameLabel = new Label {
                        Margin = new Thickness(0, 15, 0, 0), HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.End
                    };

                    var dateLabel = new Label {
                        TextColor = Color.White, Margin = new Thickness(0, 0, 0, 0), HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand
                    };
                    //FontSize = 12,
                    var frameStack = new StackLayout {
                        BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
                    };

                    AbsoluteLayout.SetLayoutBounds(frameStack, new Rectangle(0, 0, 1, 1));
                    AbsoluteLayout.SetLayoutFlags(frameStack, AbsoluteLayoutFlags.All);

                    AbsoluteLayout.SetLayoutBounds(scoreFrame, new Rectangle(0, 0, 1, 1));
                    AbsoluteLayout.SetLayoutFlags(scoreFrame, AbsoluteLayoutFlags.All);

                    AbsoluteLayout.SetLayoutBounds(scoreStack, new Rectangle(0, 0, 1, 1));
                    AbsoluteLayout.SetLayoutFlags(scoreStack, AbsoluteLayoutFlags.All);


                    AbsoluteLayout.SetLayoutBounds(scoreIndexStack, new Rectangle(0, 0, 50, 100));

                    AbsoluteLayout.SetLayoutBounds(dateFrame, new Rectangle(1, 0, 0.3, 0.4));
                    AbsoluteLayout.SetLayoutFlags(dateFrame, AbsoluteLayoutFlags.All);

                    frameStack.Children.Add(scoreFrame);
                    scoreFrame.Content = scoreStack;
                    dateFrame.Content  = dateLabel;

                    scoreStack.Children.Add(scoreLabel);
                    scoreStack.Children.Add(nameLabel);

                    scoreIndexStack.Children.Add(starTopImage);
                    scoreIndexStack.Children.Add(scoreIndexLabel);
                    scoreIndexStack.Children.Add(starBotImage);


                    if (easyHighScores.Count > 0)
                    {
                        if (counter == 0)
                        {
                            scoreIndexStack.BackgroundColor = Color.FromHex("#DAA520");
                            dateFrame.BackgroundColor       = Color.FromHex("#DAA520");
                            starTopImage.Source             = "star";
                            starBotImage.Source             = "star";
                        }

                        else if (counter == 1)
                        {
                            scoreIndexStack.BackgroundColor = Color.FromHex("#E5E5E5");
                            dateFrame.BackgroundColor       = Color.FromHex("#E5E5E5");
                        }

                        layout.Children.Add(frameStack);
                        layout.Children.Add(scoreStack);

                        layout.Children.Add(scoreIndexStack);
                        layout.Children.Add(dateFrame);

                        scoreIndexLabel.Text = (counter + 1).ToString();

                        EasyHighscore score = easyHighScores[counter];

                        string roundSubStr = score.Round;
                        scoreLabel.Text = "Round: " + roundSubStr;//Round number score to display.

                        DateTime dt         = score.CreatedOn;
                        string   dateSubStr = dt.ToString("dd.MM.yyyy");
                        dateLabel.Text = dateSubStr;//Date of the score to display.

                        string nameSubStr = score.Name;
                        nameLabel.Text = nameSubStr;

                        gridLayout.Children.Add(layout, columnIndex, rowIndex);
                    }

                    else if (easyHighScores.Count == 0 && a == 1) // The high scores list is empty and there are none to load.

                    {
                        scoreStack.BackgroundColor = Color.Transparent;

                        layout.Children.Add(frameStack);
                        layout.Children.Add(scoreStack);
                        // layout.Children.Add(scoreIndexStack);

                        scoreLabel.Margin = new Thickness(0, 0, 0, 0);
                        scoreLabel.HorizontalTextAlignment = TextAlignment.Center;

                        scoreLabel.Text = "No highscores to show. \nLet's go make some!";

                        gridLayout.Children.Add(layout, columnIndex, rowIndex);
                    }

                    counter++;
                } // End of for column.
            }     // End of for row.
        }         // End of Grid page Met
Esempio n. 5
0
        public void AddToList(string nameTextRe)
        {
            string roundCountStr = roundCount.ToString();

            if (roundCount < 10)
            {
                roundCountStr = "0" + roundCountStr;    //Convert to two digit.
            }
            if (difFlag == "easy")
            {
                EasyHighscore newScore = new EasyHighscore();

                newScore.Round     = roundCountStr;
                newScore.Name      = nameTextRe;
                newScore.CreatedOn = DateTime.Now;
                sqlDatabase.AddEasyHighscore(newScore);

                localEasyScores.Add(newScore);
                localEasyScores.Sort((p, q) => string.Compare(p.Round, q.Round, StringComparison.CurrentCulture));

                sqlDatabase = new SQLDatabase();
                sqlDatabase.DeleteAllEasyHighscores();

                int counter = localEasyScores.Count;

                foreach (EasyHighscore score in localEasyScores)
                {
                    score.ID = counter;
                    sqlDatabase.AddEasyHighscore(score);
                    counter--;
                }
            }// End of easy if.

            if (difFlag == "medium")
            {
                MediumHighscore newScore = new MediumHighscore();

                newScore.Round     = roundCountStr;
                newScore.Name      = nameTextRe;
                newScore.CreatedOn = DateTime.Now;
                sqlDatabase.AddMediumHighscore(newScore);

                localMediumScores.Add(newScore);
                localMediumScores.Sort((p, q) => string.Compare(p.Round, q.Round, StringComparison.CurrentCulture));

                sqlDatabase = new SQLDatabase();
                sqlDatabase.DeleteAllMediumHighscores();

                int counter = localMediumScores.Count;

                foreach (MediumHighscore score in localMediumScores)
                {
                    score.ID = counter;
                    sqlDatabase.AddMediumHighscore(score);
                    counter--;
                }
            }// End of medium if.

            if (difFlag == "hard")
            {
                HardHighscore newScore = new HardHighscore();

                newScore.Round     = roundCountStr;
                newScore.Name      = nameTextRe;
                newScore.CreatedOn = DateTime.Now;
                sqlDatabase.AddHardHighscore(newScore);


                localHighScores.Add(newScore);

                localHighScores.Sort((p, q) => string.Compare(p.Round, q.Round, StringComparison.CurrentCulture));

                sqlDatabase = new SQLDatabase();

                sqlDatabase.DeleteAllHardHighscores();

                int counter = localHighScores.Count;

                foreach (HardHighscore score in localHighScores)
                {
                    score.ID = counter;

                    sqlDatabase.AddHardHighscore(score);

                    counter--;
                }
            }// End of hard if.

            alreadyAdded = true;

            SaveName(nameTextRe);
        }
Esempio n. 6
0
        public LoserPage(int correctCount, int foodToFind, int roundCountRe, string difFlagIn, string playerModeIn)
        {
            // Sets local report lists to the ones brought in from playing page.
            roundCount = roundCountRe;
            difFlag    = difFlagIn;

            InitializeComponent();

            // test.Text = GameReport.pickedFoodList.Count.ToString();

            //**** Data Gathering ********************
            sqlDatabase = new SQLDatabase();
            localData   = sqlDatabase.GetAllData();

            foreach (Data data in localData)
            {
                if (data.CreatedOn == DateTime.Today)
                {
                    data.GamesPlayed = data.GamesPlayed + 1;

                    sqlDatabase.UpdateData(data);


                    if (roundCount > data.RoundCountHigh)
                    {
                        data.RoundCountHigh = roundCount;
                        sqlDatabase.UpdateData(data);
                    }
                }
            }
            //**** Data Gathering ********************

            nameEntry.IsVisible = false;

            playerMode = playerModeIn;

            mainMenu.Text = "Main Menu";
            restart.Text  = "Restart Game";

            scoreLabel.HorizontalTextAlignment = TextAlignment.Center;
            scoreLabel.Text = "In the last round\nYou got " + correctCount + " out of " + foodToFind + " correct.";

            newHSLabel.HorizontalTextAlignment = TextAlignment.Center;
            nameEntry.HorizontalTextAlignment  = TextAlignment.Center;

            sqlDatabase = new SQLDatabase();

            localTrophyList = sqlDatabase.GetAllTrophies();


            //******** HIGHSCORE CHECKER **************************************//
            // Start of Easy diff if.
            if (difFlag == "easy")
            {
                localEasyScores = sqlDatabase.GetAllEasyHighscores();
                Console.WriteLine(localEasyScores.Count);

                if (localEasyScores.Count < 10)
                {
                    nameEntry.IsVisible = true;
                    LoadName();
                    newHigh = true;
                    int topScore = 0;
                    if (localEasyScores.Count > 0)
                    {
                        EasyHighscore topScoreStrE = localEasyScores[0];
                        Int32.TryParse(topScoreStrE.Round, out topScore);
                    }

                    if (roundCount > topScore)
                    {
                        endGame.Source  = "podium2";
                        newHSLabel.Text = "Wow! \n New Top Highscore!";
                    }

                    else
                    {
                        endGame.Source  = "bigStar";
                        newHSLabel.Text = "New Highscore!";
                    }
                }

                else if (localEasyScores.Count == 0)
                {
                    endGame.Source  = "podium2";
                    newHSLabel.Text = "Wow! \n New Top Highscore!";
                }

                else if (localEasyScores.Count == 10)
                {
                    ScoreChecker(roundCount);
                }
            }// End of Easy diff if.

            // Start of Medium diff if.
            if (difFlag == "medium")
            {
                localMediumScores = sqlDatabase.GetAllMediumHighscores();
                Console.WriteLine(localMediumScores.Count);

                if (localMediumScores.Count < 10)
                {
                    nameEntry.IsVisible = true;
                    LoadName();
                    newHigh = true;
                    int topScore = 0;
                    if (localMediumScores.Count > 0)
                    {
                        MediumHighscore topScoreStrM = localMediumScores[0];
                        Int32.TryParse(topScoreStrM.Round, out topScore);
                    }

                    if (roundCount > topScore)
                    {
                        endGame.Source  = "podium2";
                        newHSLabel.Text = "Wow! \n New Top Highscore!";
                    }

                    else
                    {
                        endGame.Source  = "bigStar";
                        newHSLabel.Text = "New Highscore!";
                    }
                }

                else if (localMediumScores.Count == 0)
                {
                    endGame.Source  = "podium2";
                    newHSLabel.Text = "Wow! \n New Top Highscore!";
                }

                else if (localMediumScores.Count == 10)
                {
                    ScoreChecker(roundCount);
                }
            }// End of Medium diff if.

            //Start of Hard diff if.
            if (difFlag == "hard")
            {
                localHighScores = sqlDatabase.GetAllHardHighscores();
                Console.WriteLine(localHighScores.Count);

                if (localHighScores.Count < 10)
                {
                    nameEntry.IsVisible = true;
                    LoadName();
                    newHigh = true;
                    int topScore = 0;
                    if (localHighScores.Count > 0)
                    {
                        HardHighscore topScoreStrH = localHighScores[0];
                        Int32.TryParse(topScoreStrH.Round, out topScore);
                    }

                    if (roundCount > topScore)
                    {
                        endGame.Source  = "podium2";
                        newHSLabel.Text = "Wow! \n New Top Highscore!";
                    }

                    else
                    {
                        endGame.Source  = "bigStar";
                        newHSLabel.Text = "New Highscore!";
                    }
                }

                else if (localHighScores.Count == 0)
                {
                    endGame.Source  = "podium2";
                    newHSLabel.Text = "Wow! \n New Top Highscore!";
                }

                else if (localHighScores.Count == 10)
                {
                    ScoreChecker(roundCount);
                }
            }// End of Hard diff if.


            //******** TROPHY / AWARD CHECKER **************************************//

            AwardChecker(); // After score checker perfrom an award check

            //******** BUTTON PRESSES **************************************//

            mainMenu.Clicked += mainMenu_Clicked;

            restart.Clicked += restart_Clicked;

            //******** POST GAME REPORT **************************************//

            pickedGridLayout.RowDefinitions.Add(new RowDefinition());
            pickedGridLayout.ColumnDefinitions.Add(new ColumnDefinition());


            string itemStr;
            int    counter = 0;


            int rowAmount = (GameReport.pickedFoodList.Count / 4) + 1;


            for (int rowIndex = 0; rowIndex < rowAmount; rowIndex++)      // Adds all the Rows
            {
                for (int columnIndex = 0; columnIndex < 4; columnIndex++) // Adds all the columns
                {
                    if (counter == GameReport.pickedFoodList.Count)       // Amount of images to display
                    {
                        break;
                    }


                    var imageReport = new Image {
                        HeightRequest = 100, BackgroundColor = Color.Transparent
                    };

                    itemStr = GameReport.pickedFoodList[counter].ToString();
                    int itemInt = GameReport.pickedFoodList[counter];

                    // iOS stuff
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        imageReport.Source = (itemStr);//sets the images to go into the grid
                    }

                    // Android stuff
                    if (Device.RuntimePlatform == Device.Android)
                    {
                        imageReport.Source = ("image" + itemStr);//sets the images to go into the grid
                    }

                    pickedGridLayout.Children.Add(imageReport, columnIndex, rowIndex);

                    //****** Right or Wrong markers on picked images list.
                    var rightOrWrongIndi = new Image {
                    };

                    rightOrWrongIndi.HorizontalOptions = LayoutOptions.End;
                    rightOrWrongIndi.VerticalOptions   = LayoutOptions.End;

                    if (GameReport.rightFoodList.Contains(itemInt))
                    {
                        rightOrWrongIndi.Source        = "right";
                        rightOrWrongIndi.WidthRequest  = 25;
                        rightOrWrongIndi.HeightRequest = 25;
                        pickedGridLayout.Children.Add(rightOrWrongIndi, columnIndex, rowIndex);// adds the selected item indicator
                    }

                    else
                    {
                        rightOrWrongIndi.Source        = "wrong";
                        rightOrWrongIndi.WidthRequest  = 15;
                        rightOrWrongIndi.HeightRequest = 15;
                        pickedGridLayout.Children.Add(rightOrWrongIndi, columnIndex, rowIndex);// adds the selected item indicator
                    }

                    //******


                    counter++;
                }// End of For loop for coloum.
            }

            shoppingListGridLayout.RowDefinitions.Add(new RowDefinition());
            shoppingListGridLayout.ColumnDefinitions.Add(new ColumnDefinition());

            string shownStr;
            int    shownCounter = 0;

            int rowFoodListAmount = (List.foodList.Count / 4) + 1;

            for (int rowIndex = 0; rowIndex < rowFoodListAmount; rowIndex++) // Adds all the Rows
            {
                for (int columnIndex = 0; columnIndex < 4; columnIndex++)    // Adds all the columns
                {
                    if (shownCounter == List.foodList.Count)                 // Amount of images to display
                    {
                        break;
                    }

                    var imagePicked = new Image {
                        HeightRequest = 100, BackgroundColor = Color.Transparent
                    };

                    shownStr = List.foodList[shownCounter].ToString();


                    //iOS stuff
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        imagePicked.Source = shownStr;//sets the images to go into the grid
                    }

                    //Android stuff
                    if (Device.RuntimePlatform == Device.Android)
                    {
                        imagePicked.Source = "image" + shownStr;//sets the images to go into the grid
                    }

                    shoppingListGridLayout.Children.Add(imagePicked, columnIndex, rowIndex);

                    shownCounter++;
                }
            }


            // endRound.Children.Add(pickedGridLayout);
        }// End of main method.