//fills the board with empty and colored blocks private void initiateRandomly(Canvas canvas, int size, Random rnd) { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Case rect = new Case(canvas.Height, canvas.Width, size, rnd); Canvas.SetLeft(rect.getRect(), i * canvas.Width / size); Canvas.SetTop(rect.getRect(), j * canvas.Width / size); board[i, j] = rect; rectBoard[i, j] = rect.getRect(); canvas.Children.Add(rect.getRect()); } } }
//this method sets a block so that it will return isEmpty == true private void empty(Case square) { square.getRect().Fill = new SolidColorBrush(Colors.White); square.takeColor(); }
//wible canvas private void Canvas_Loaded_3(object sender, RoutedEventArgs e) { Random random = new Random(); Canvas canvas = sender as Canvas; wibleCanvas = canvas; Case wibleCase = new Case(canvas.Height*6, canvas.Width, size, rnd, false); wible = wibleCase.getRect(); Canvas.SetLeft(wibleCase.getRect(), 0); Canvas.SetTop(wibleCase.getRect(), 0); wible.Fill = new SolidColorBrush(Colors.White); wible.Stroke = new SolidColorBrush(Colors.White); wible.Visibility = Visibility.Collapsed; canvas.Children.Add(wibleCase.getRect()); }
//the event when the board is clicked private void Canvas_MouseDown_2(object sender, MouseButtonEventArgs e) { dispatcherTimer.IsEnabled = false; if (gameOver == false) { int columnNumber = (int)(e.GetPosition(boardCanvas).X / (boardCanvas.Width / 8)); if (selectedCase != 1000) { copyRectangleInHandAt(columnNumber); drawLabelsForBoard(); dispatcherTimer.IsEnabled = true; Random rnd = new Random(); hand[selectedCase] = new Case(boardCanvas.Height, boardCanvas.Width, size, rnd, false); hand[selectedCase].getRect().Stroke = new SolidColorBrush(Colors.Red); wible.Fill = hand[selectedCase].getRect().Fill; Canvas.SetLeft(hand[selectedCase].getRect(), selectedCase * boardCanvas.Width / size); Canvas.SetTop(hand[selectedCase].getRect(), 0); handCanvas.Children.Add(hand[selectedCase].getRect()); drawLabelsForHand(size, handCanvas); if (boilUpTurn == 0) { boilUp(); score += 50; showScore(); boilUpTurn = 4; } else { boilUpTurn--; } updateTurnsLeft(); } } else { initiateRandomly(boardCanvas, size, rnd); gameOverLabel.Visibility = Visibility.Collapsed; gameOver = false; dispatcherTimer.IsEnabled = true; drawLabelsForBoard(); score = 0; wible.Visibility = Visibility.Visible; wibleLabel.Visibility = Visibility.Visible; } }
//init hand private void Canvas_Loaded_2(object sender, RoutedEventArgs e) { Random random = new Random(); rnd = random; Canvas canvas = sender as Canvas; handCanvas = canvas; for (int i = 0; i < size; i++) { Case handCase = new Case(canvas.Height*6, canvas.Width, size, rnd, false); Canvas.SetLeft(handCase.getRect(), i * canvas.Width / size); Canvas.SetTop(handCase.getRect(), 0); hand[i] = handCase; canvas.Children.Add(handCase.getRect()); } drawLabelsForHand(size, canvas); }