Example #1
0
 void DrawBoard(Board board)
 {
     try
     {
         MainCanvas.Children.Clear();
         _imageToPieceMap.Clear();
         foreach (var kvp in board.playedPieces)
         {
             HexagonDrawing hexWithImage = HexagonDrawing.GetHexagonDrawing(kvp.Value, _drawSize, kvp.Key, _mainCanvasOffsetPoint);
             MainCanvas.Children.Add(hexWithImage.image);
             MainCanvas.Children.Add(hexWithImage.polygon);
             _imageToPieceMap[hexWithImage.polygon]    = kvp.Key;
             hexWithImage.polygon.MouseLeftButtonDown += polygon_MouseLeftButtonDown;
         }
         UnplayedPiecesCanvas.Children.Clear();
         _unplayedImageToPieceMap.Clear();
         HashSet <Tuple <PieceColor, string> > shown = new HashSet <Tuple <PieceColor, string> >();
         foreach (Piece unplayedPiece in board.unplayedPieces.OrderBy(p => p.number))
         {
             var pieceTypeTuple = new Tuple <PieceColor, string>(unplayedPiece.color, unplayedPiece.GetPieceNotation());
             if (shown.Contains(pieceTypeTuple))
             {
                 continue;
             }
             AddUnplayedPieceToCanvas(unplayedPiece);
             shown.Add(pieceTypeTuple);
         }
         DrawGameInfo(board);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Example #2
0
        private void AddUnplayedPieceToCanvas(Piece piece)
        {
            Hex            hex          = GetHexForUnplayedPiece(piece);
            HexagonDrawing hexWithImage = HexagonDrawing.GetHexagonDrawing(hex, _drawSize, piece, _unplayedCanvasOffsetPoint);

            UnplayedPiecesCanvas.Children.Add(hexWithImage.image);
            _unplayedImageToPieceMap[hexWithImage.image] = piece;
            hexWithImage.image.MouseLeftButtonDown      += unplayedPieceImage_MouseLeftButtonDown;
        }
Example #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Point canvasCenterPoint = new Point(MainCanvas.ActualWidth / 2, MainCanvas.ActualHeight / 2);

            _mainCanvasOffsetPoint = HexagonDrawing.GetOffsetPointFromCenter(canvasCenterPoint, _drawSize);
            Point unplayedCanvasCenterPoint = new Point(UnplayedPiecesCanvas.ActualWidth / 2, UnplayedPiecesCanvas.ActualHeight / 2);

            _unplayedCanvasOffsetPoint     = HexagonDrawing.GetOffsetPointFromCenter(unplayedCanvasCenterPoint, _drawSize);
            MovesListBox.SelectionChanged += MovesListBox_SelectionChanged;
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, NewGameExecute, NewGameCanExecute));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Stop, StopExecute, StopCanExecute));
        }
Example #4
0
        public static FutureMoveDrawing GetFutureMoveDrawing(Hex hex, double size, Point offsetPoint)
        {
            HexagonDrawing    hexDrawing = GetHexagonDrawing(hex, size, offsetPoint);
            FutureMoveDrawing drawing    = new FutureMoveDrawing();

            drawing._center  = hexDrawing.center;
            drawing._piece   = hexDrawing.piece;
            drawing._polygon = hexDrawing.polygon;
            drawing._image   = hexDrawing.image;
            drawing.height   = hexDrawing.height;
            drawing.width    = hexDrawing.width;
            Canvas.SetZIndex(drawing._polygon, 99);
            drawing._polygon.Fill = Brushes.Tan;
            return(drawing);
        }
Example #5
0
        public static HexagonDrawing GetHexagonDrawing(Hex hex, double size, Piece piece, Point offsetPoint)
        {
            HexagonDrawing drawing = GetHexagonDrawing(hex, size, offsetPoint);

            drawing._piece = piece;
            drawing._image = PieceToImage(piece);
            double imageXOffset = drawing._image.Source.Width / 2;
            double imageYOffset = drawing._image.Source.Height / 2;
            double scale        = drawing.width / drawing._image.Source.Width + .25;

            drawing._image.RenderTransform = new ScaleTransform(scale, scale, imageXOffset, imageYOffset);
            Canvas.SetZIndex(drawing._image, -1);
            Canvas.SetLeft(drawing._image, drawing.center.X - imageXOffset);
            Canvas.SetTop(drawing._image, drawing.center.Y - imageYOffset);
            return(drawing);
        }
Example #6
0
        public static HexagonDrawing GetHexagonDrawing(Hex hex, double size, Point offsetPoint)
        {
            HexagonDrawing drawing = new HexagonDrawing();

            drawing._polygon = new Polygon();
            drawing._center  = HexCoordToCenterPoint(hex, size, offsetPoint);
            for (int i = 1; i <= 6; i++)
            {
                drawing._polygon.Points.Add(HexCorner(drawing.center, size, i));
            }
            drawing._polygon.Stroke = Brushes.Black;
            drawing._polygon.Fill   = Brushes.Transparent;
            drawing.height          = size * 2;
            drawing.width           = Math.Sqrt(3) / 2 * drawing.height;
            return(drawing);
        }
Example #7
0
        public static Point GetOffsetPointFromCenter(Point centerPoint, double size)
        {
            HexagonDrawing calculatedCenter = GetHexagonDrawing(new Hex(24, 24), size, new Point(0, 0));

            return(new Point(calculatedCenter._center.X - centerPoint.X, calculatedCenter._center.Y - centerPoint.Y));
        }