コード例 #1
0
 private TriTileView DrawTriangleWithPiece(TriTile triTile)
 {
     TriTileView ttv = DrawTriangleWithoutPiece(triTile);
     ttv.Piece = DrawPiece(ttv.CenterPoint, triTile.IsBlack, false);
     return ttv;
 }
コード例 #2
0
        private void RedrawTile(TriTile triTileChanged)
        {
            TriTileView ttv = _triTile2TriTileView[triTileChanged];

            //Remove the UIElements from the collections
            LayoutGameBoard.Children.Remove(ttv.Piece);
            LayoutGameBoard.Children.Remove(ttv.TrianglePolygon);

            //Create them again
            TriTileView newTtv;
            if (triTileChanged.HasPiece)
                newTtv = DrawTriangleWithPiece(triTileChanged);
            else
                newTtv = DrawTriangleWithoutPiece(triTileChanged);

            _triTile2TriTileView[triTileChanged] = newTtv;
            _point2TriTileView[newTtv.CenterPoint] = newTtv;

            //Add them
            LayoutGameBoard.Children.Add(newTtv.TrianglePolygon);
            if (triTileChanged.HasPiece)
                LayoutGameBoard.Children.Add(newTtv.Piece);
        }
コード例 #3
0
        private TriTileView DrawTriangleWithoutPiece(TriTile triTile)
        {
            SolidColorBrush strokeBrush = new SolidColorBrush();
            strokeBrush.Color = Colors.Black;

            SolidColorBrush fillBrush = new SolidColorBrush();
            if (triTile.IsBlack)
                fillBrush.Color = Colors.DarkGray;
            else
                fillBrush.Color = Colors.White;

            Polygon trianglePolygon = new Polygon();

            if (!triTile.HexTile.IsActive)
                trianglePolygon.Opacity = TMP_OPACITY;
            else
                trianglePolygon.Opacity = MAX_OPACITY;

            trianglePolygon.Stroke = strokeBrush;
            trianglePolygon.Fill = fillBrush;
            trianglePolygon.StrokeThickness = 1;

            //DEBUG
            var tt = new System.Windows.Controls.ToolTip();
            tt.Content = string.Format("{0},{1}", triTile.X, triTile.Y);
            trianglePolygon.ToolTip = tt;

            Point center;
            Point point1, point2, point3;
            //Calculates the coordinates for the points of the triangle
            if (triTile.IsBlack)
            {
                point1 = new Point(OFFSET_X + triTile.X * (TRIANGLE_SIZE / 2) - TRIANGLE_SIZE / 2 + triTile.Y * (TRIANGLE_SIZE / 4) + TRIANGLE_SIZE / 4, OFFSET_Y - (triTile.Y / 2 + 1) * TRIANGLE_SIZE);//cima esquerda
                point2 = new Point(OFFSET_X + triTile.X * (TRIANGLE_SIZE / 2) + (TRIANGLE_SIZE / 2) + triTile.Y * TRIANGLE_SIZE / 4 + TRIANGLE_SIZE / 4, OFFSET_Y - (triTile.Y / 2 + 1) * TRIANGLE_SIZE);//cima direita
                point3 = new Point(OFFSET_X + triTile.X * (TRIANGLE_SIZE / 2) + TRIANGLE_SIZE / 2 + triTile.Y * (TRIANGLE_SIZE / 4) - TRIANGLE_SIZE / 4, OFFSET_Y - triTile.Y / 2 * TRIANGLE_SIZE);//baixo

                center = new Point((point1.X + point2.X) / 2, (point1.Y + point3.Y) / 2);
            }
            else
            {
                point1 = new Point(OFFSET_X + triTile.X / 2 * TRIANGLE_SIZE + triTile.Y * TRIANGLE_SIZE / 4 + TRIANGLE_SIZE / 2, OFFSET_Y - (triTile.Y / 2 + 1) * TRIANGLE_SIZE);//cima
                point2 = new Point(OFFSET_X + triTile.X / 2 * TRIANGLE_SIZE + triTile.Y / 2 * TRIANGLE_SIZE / 2, OFFSET_Y - triTile.Y / 2 * TRIANGLE_SIZE);//baixo esquerda
                point3 = new Point(OFFSET_X + triTile.X * (TRIANGLE_SIZE / 2) + TRIANGLE_SIZE + triTile.Y * (TRIANGLE_SIZE / 4), OFFSET_Y - triTile.Y / 2 * TRIANGLE_SIZE);//baixo direita

                center = new Point((point2.X + point3.X) / 2, (point1.Y + point2.Y) / 2);
            }

            PointCollection trianglePoints = new PointCollection();
            trianglePoints.Add(point1);
            trianglePoints.Add(point2);
            trianglePoints.Add(point3);
            trianglePolygon.Points = trianglePoints;

            return new TriTileView
            {
                CenterPoint = center,
                TrianglePolygon = trianglePolygon,
                TriTile = triTile
            };
        }