public async void PushCurrentWord() { string pushingWord = ""; StackLayout wordContainer = new StackLayout() { VerticalOptions = LayoutOptions.CenterAndExpand }; foreach (Frame frame in wordCreationBar) { Grid frameGrid = (Grid)frame.Content; Label currentLabel = (Label)frameGrid.Children[0]; if (currentLabel.Text == "") { // Geluid voor als je woord niet compleet is var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("Incorrect.mp3"); player.Play(); await this.DisplayAlert("Alert", "Je woord is nog niet af. Vul alle letters in", "OK"); return; } pushingWord += currentLabel.Text; } if (pushWordDebug) { if (!await CheckWord(pushingWord)) { // Geluid voor fout antwoord if (ConfigFile.soundIsOn && ConfigFile.otherSoundsOn) { var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Volume = ConfigFile.Slider; player.Load("Incorrect.mp3"); player.Play(); } await DisplayAlert("Alert", "Je woord bestaat niet. Probeer een ander woord", "OK"); return; } } Grid grid = (Grid)MiddlePart.Content; grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); Grid leftsideGrid = new Grid(); leftsideGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }); leftsideGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.Children.Add(leftsideGrid, 0, grid.RowDefinitions.Count - 1); leftsideGrid.Children.Add(new Label() { Text = "speler " + currentPlayerTurn, HorizontalOptions = LayoutOptions.CenterAndExpand }, 0, 0); leftsideGrid.Children.Add(new Label() { Text = getValues.WordWorth(FramesToWords.WordCreator(wordCreationBar)).ToString() }, 1, 0); Grid insideGrid = new Grid() { VerticalOptions = LayoutOptions.CenterAndExpand }; for (Int32 i = 0; i < ConfigFile.wordLength; i++) { //Creates gridcolumns equal to the amount of letters needed for the word. (1 column equals 1 letter) insideGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); } for (Int32 i = 0; i < insideGrid.ColumnDefinitions.Count; i++) { Frame frame = wordCreationBar[i]; Grid frameGrid = (Grid)frame.Content; Label label = (Label)frameGrid.Children[0]; string currentLetter = label.Text.ToString(); List <Frame> localFrameList = new List <Frame>() { wordCreationBar[i] }; getValues.WordWorth(FramesToWords.WordCreator(localFrameList)); Grid gridForLabels = new Grid(); gridForLabels.RowDefinitions.Add(new RowDefinition { Height = new GridLength(3, GridUnitType.Star) }); gridForLabels.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }); gridForLabels.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star) }); gridForLabels.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }); gridForLabels.ColumnSpacing = 0; gridForLabels.RowSpacing = 0; gridForLabels.Children.Add(new Label() { Text = currentLetter, FontSize = 20, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }, 0, 0); gridForLabels.Children.Add(new Label() { Text = getValues.LetterWorth(currentLetter.First()).ToString(), FontSize = 12, Margin = 0 }, 1, 1); //Creates a frame to get borders around those labels insideGrid.Children.Add(new Frame() { BorderColor = Color.Black, BackgroundColor = currentPlayerColor, Content = gridForLabels, HeightRequest = 40, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Padding = 0, Margin = 0 }, i, 0); } wordContainer.Children.Add(insideGrid); grid.Children.Add(wordContainer, 1, grid.RowDefinitions.Count - 1); if (currentPlayerTurn == 2) { turn--; } if (highscoreWordPoints < getValues.WordWorth(FramesToWords.WordCreator(wordCreationBar))) { highscoreWord = ""; highscoreWordPoints = getValues.WordWorth(FramesToWords.WordCreator(wordCreationBar)); Label localLabel; foreach (Frame frame in wordCreationBar) { try { Grid mark = (Grid)frame.Content; localLabel = (Label)mark.Children[0]; } catch (Exception) { localLabel = (Label)frame.Content; } highscoreWord += localLabel.Text; } } if (currentPlayerTurn == 1) { totalPointsP1 += getValues.WordWorth(FramesToWords.WordCreator(wordCreationBar)); viewPointCounterP1Label.Text = "totale score: " + totalPointsP1.ToString(); } else { totalPointsP2 += getValues.WordWorth(FramesToWords.WordCreator(wordCreationBar)); viewPointCounterP2Label.Text = "totale score: " + totalPointsP2.ToString(); } //viewPointCounter.Text = "totale score: " + totalPoints; viewTurnCounterLabel.Text = "beurten over: " + turn; // PushButton Geluid if (ConfigFile.soundIsOn && ConfigFile.otherSoundsOn) { var player2 = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player2.Volume = ConfigFile.Slider; player2.Load("Correct.wav"); player2.Play(); } if (turn <= 0) { GameOverHandler(); } currentPlayerColor = currentPlayerColor == player1Color ? player2Color : player1Color; currentPlayerTurn = currentPlayerTurn == 1 ? 2 : 1; currentPlayersTurnLabel.Text = "beurt: speler " + currentPlayerTurn; EmptyPushwordBar(); FillUsableLetterBord(); viewCurrentPushwordValueLabel.Text = "Dit woord: " + getValues.WordWorth(FramesToWords.WordCreator(wordCreationBar)) + " punten"; }
public void SwapLetters(Object sender, EventArgs e) { Frame wordCreationFrame = (Frame)sender; Grid gridTwo = (Grid)wordCreationFrame.Content; Label wordCreationLabel = (Label)gridTwo.Children[0]; Label pointsLabel = (Label)gridTwo.Children[1]; foreach (View gridFrame in grid.Children) { if (gridFrame.BackgroundColor == Color.Red) { //making sure that the program knows which 2 labels are tapped (on your own board and on the bar you want to create the word) Frame currentFrame = (Frame)gridFrame; Grid gridOne = (Grid)currentFrame.Content; Label currentLabel = (Label)gridOne.Children[0]; Label currentPointsLabel = (Label)gridOne.Children[1]; String placeHolder = wordCreationLabel.Text; wordCreationLabel.Text = currentLabel.Text; currentLabel.Text = placeHolder; placeHolder = pointsLabel.Text; pointsLabel.Text = currentPointsLabel.Text; currentPointsLabel.Text = placeHolder; viewCurrentPushwordValueLabel.Text = "woordwaarde: " + getValues.WordWorth(FramesToWords.WordCreator(wordCreationBar)); gridFrame.BackgroundColor = currentPlayerColor; // Pushbar Geluid if (ConfigFile.soundIsOn && ConfigFile.keyboardSoundOn) { var player2 = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player2.Volume = ConfigFile.Slider; player2.Load("Pop.wav"); player2.Play(); } return; } } if (wordCreationLabel.Text != "") { foreach (View gridFrame in grid.Children) {//making sure that the program knows which 2 labels are tapped (on your own board and on the bar you want to create the word) Frame currentFrame = (Frame)gridFrame; Grid gridOne = (Grid)currentFrame.Content; Label currentLabel = (Label)gridOne.Children[0]; Label currentPointsLabel = (Label)gridOne.Children[1]; if (currentLabel.Text == "") { currentLabel.Text = wordCreationLabel.Text; currentPointsLabel.Text = pointsLabel.Text; wordCreationLabel.Text = ""; pointsLabel.Text = ""; } } // Pushbar Geluid if (ConfigFile.soundIsOn && ConfigFile.otherSoundsOn) { var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Volume = ConfigFile.Slider; player.Load("Pop.wav"); player.Play(); } } }