private void InitializeBoardBackgroundStandard() { Color c = new Color(); c.R = 15; c.G = 15; c.B = 15; c.A = 255; SolidColorBrush s = new SolidColorBrush(c); // The top gray Dark gray section IEnumerable <Point> ps = null; for (int i = 0; i < 19; i++) { double j = 9f - i; Point[] topSide = new Point[] { new Point(4f, j), new Point(3f, j), new Point(2f, j), new Point(1f, j), new Point(0f, j), new Point(-1, j), new Point(-2, j), new Point(-3f, j), new Point(-4f, j) }; if (ps == null) { ps = topSide.ToList(); } else { ps = ps.Concat(topSide.ToList()); } } List <TetrisPoint> tl = new List <TetrisPoint>(); foreach (Point p in ps) { System.Windows.Shapes.Rectangle e = new Rectangle(); e.Width = 16; e.Height = 16; e.Fill = s; e.SetValue(Canvas.LeftProperty, p.X); e.SetValue(Canvas.TopProperty, p.Y); TetrisPoint tp = new TetrisPoint(p, e); tl.Add(tp); } TetrisShape ts = new TetrisShape(tl); _boardBackground = ts; }
private void InitializeBoardBoarderStandard() { Point[] leftSide = new Point[] { new Point(-5f, -9f), new Point(-5f, -8f), new Point(-5f, -7f), new Point(-5f, -6f), new Point(-5f, -5f), new Point(-5f, -4f), new Point(-5f, -3f), new Point(-5f, -2f), new Point(-5f, -1f), new Point(-5f, 9f), new Point(-5f, 8f), new Point(-5f, 7f), new Point(-5f, 6f), new Point(-5f, 5f), new Point(-5f, 4f), new Point(-5f, 3f), new Point(-5f, 2f), new Point(-5f, 1f), new Point(-5f, 0f), }; Point[] rightSide = new Point[] { new Point(5f, -9f), new Point(5f, -8f), new Point(5f, -7f), new Point(5f, -6f), new Point(5f, -5f), new Point(5f, -4f), new Point(5f, -3f), new Point(5f, -2f), new Point(5f, -1f), new Point(5f, 9f), new Point(5f, 8f), new Point(5f, 7f), new Point(5f, 6f), new Point(5f, 5f), new Point(5f, 4f), new Point(5f, 3f), new Point(5f, 2f), new Point(5f, 1f), new Point(5f, 0f) }; Point[] bottomSide = new Point[] { new Point(5f, 10f), new Point(4f, 10f), new Point(3f, 10f), new Point(2f, 10f), new Point(1f, 10f), new Point(0f, 10f), new Point(-1f, 10f), new Point(-2f, 10f), new Point(-3f, 10f), new Point(-4f, 10f), new Point(-5f, 10f) }; Point[] topSide = new Point[] { new Point(5f, -10f), new Point(5f, -10f), new Point(5f, -11f), new Point(5f, -12f), new Point(5f, -13f), new Point(5f, -14f), new Point(5f, -15f), new Point(5f, -16f), new Point(5f, -17f), //new Point(0f, -10f), new Point(5f, -17f), new Point(5f, -16f), new Point(-5, -15f), new Point(-5, -14), new Point(-5f, -13f), new Point(-5f, -12f), new Point(-5f, -11f), new Point(-5f, -10f), new Point(-5f, -10f) }; IEnumerable <Point> ps = topSide.Concat <Point>(bottomSide).Concat <Point>(leftSide).Concat <Point>(rightSide); List <TetrisPoint> tl = new List <TetrisPoint>(); foreach (Point p in ps) { System.Windows.Shapes.Rectangle e = new Rectangle(); e.Width = 16; e.Height = 16; e.Fill = Brushes.DarkSlateGray; e.SetValue(Canvas.LeftProperty, p.X); e.SetValue(Canvas.TopProperty, p.Y); TetrisPoint tp = new TetrisPoint(p, e); tl.Add(tp); } TetrisShape ts = new TetrisShape(tl); _boardBoarder = ts; }
private int ClearFullRows() { int rowsCleared = 0; Vector down = new Vector(0, 1); Dictionary <int, int> pointsOnARow = new Dictionary <int, int>(); for (int i = -30; i < 30; i++) { pointsOnARow.Add(i, 0); } foreach (TetrisShape piece in this) { foreach (TetrisPoint tp in piece.points) { int idx = Convert.ToInt32(tp.worldPointTranform.Y + tp.localpoint.Y); pointsOnARow[idx] += 1; } } List <TetrisPoint> pointsToKill = new List <TetrisPoint>(); pointsToKill.Clear(); Storyboard sb = new Storyboard(); foreach (KeyValuePair <int, int> rowCount in pointsOnARow) { if (rowCount.Value > 8) { rowsCleared++; // Full row.. we need to explode this and destory these points. for (int i = 0; i < this.Count; i++) // for each piece { foreach (TetrisPoint tp in this[i].points) // for each point on the piece. { if (Convert.ToInt32(tp.worldPointTranform.Y + tp.localpoint.Y) == rowCount.Key) { // destroy this point. pointsToKill.Add(tp); // start some animations for these, then we want to acutally remove them later. Shape s = tp.shape; // pointsToKill[j].shape.Fill = Brushes.Wheat; DoubleAnimation day = new DoubleAnimation(2, TimeSpan.FromMilliseconds(800)); DoubleAnimation dax = new DoubleAnimation(2, TimeSpan.FromMilliseconds(800)); DoubleAnimation dal = new DoubleAnimation(-30, TimeSpan.FromMilliseconds(800)); DoubleAnimation dat = new DoubleAnimation(-30, TimeSpan.FromMilliseconds(800)); sb.Children.Add(day); sb.Children.Add(dax); sb.Children.Add(dal); sb.Children.Add(dat); Storyboard.SetTargetName(day, s.Name); Storyboard.SetTargetName(dax, s.Name); Storyboard.SetTargetName(dal, s.Name); Storyboard.SetTargetName(dat, s.Name); Storyboard.SetTargetProperty(day, new PropertyPath(Shape.HeightProperty)); Storyboard.SetTargetProperty(dax, new PropertyPath(Shape.WidthProperty)); Storyboard.SetTargetProperty(dal, new PropertyPath(Canvas.LeftProperty)); Storyboard.SetTargetProperty(dat, new PropertyPath(Canvas.TopProperty)); System.Windows.Forms.Application.DoEvents(); } } } } } sb.Begin(this.boardCanvas); System.Windows.Forms.Application.DoEvents(); TetrisPoint tmp = null; while (pointsToKill.Count > 0)// this loop pauses us until our animations finish. { System.Windows.Forms.Application.DoEvents(); tmp = pointsToKill.First(); if ((double)tmp.shape.GetValue(Canvas.TopProperty) <= 0) { boardCanvas.Children.Remove(tmp.shape); var vv = from lots in this where lots.points.Contains(tmp) select lots; vv.First().points.Remove(tmp); pointsToKill.Remove(tmp); tmp.shape = null; tmp = null; } System.Windows.Forms.Application.DoEvents(); System.Windows.Forms.Application.DoEvents(); } pointsToKill.Clear(); // at this stage all the points have been removed we just need to shift the board down. foreach (KeyValuePair <int, int> row in pointsOnARow) { if (row.Value > 8) { // so every point above this key should drop one row. for (int i = 0; i < this.Count; i++) { foreach (TetrisPoint tp in this[i].points) { if (Convert.ToInt32(tp.worldPointTranform.Y + tp.localpoint.Y) <= row.Key) { tp.worldPointTranform += down; //tp.localpoint.Offset(0,1);// += 1; } } } } } for (int i = 0; i < this.Count; i++) { updateShape(this[i], TimeSpan.FromMilliseconds(30)); } foreach (KeyValuePair <int, int> rowCount in pointsOnARow) { if (rowCount.Value > 0 && rowCount.Key <= -10) { this.GameOver = true; } } return(rowsCleared); }