Example #1
0
        private void DrawGame(Graphics graphics)
        {
            //graphics.Clear(Color.Black);

            playingArea   = new Rectangle(new Point(0, 0), form.Size);
            playingArea.X = playingArea.X + 10;
            playingArea.Y = playingArea.Y + 10;

            playingArea.Width  -= 30;
            playingArea.Height -= 50;

            graphics.DrawRectangle(new Pen(Brushes.White), playingArea.X, playingArea.Y, playingArea.Width, playingArea.Height);


            for (int i = 0; i < gameLogicToDraw.SizeY; i++)
            {
                for (int j = 0; j < gameLogicToDraw.SizeX; j++)
                {
                    float centerPointX = playingArea.X + GetCenterPoint(j, i).X;
                    float centerPointY = playingArea.Y + GetCenterPoint(j, i).Y;

                    int tileX = ConvertScreenToTileCoordsX(j);
                    int tileY = ConvertScreenToTileCoordsY(i);

                    Tile thisTile = gameLogicToDraw.Tiles[tileX, tileY];

                    for (int k = 0; k < 6; k++)
                    {
                        System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
                        PointF p1 = Hexagon[k];
                        PointF p2 = Hexagon[(k + 1) % 6];
                        m.Translate(centerPointX, centerPointY);
                        m.Scale(hexRadiusX, hexRadiusY);
                        p1 = m.TransformPoint(p1);
                        p2 = m.TransformPoint(p2);

                        int penWidth = 4;

                        Pen pen1;

                        Tuple <int, int> neighbouringTile = gameLogicToDraw.GetNeighbouringTile(Tuple.Create(tileX, tileY), (HexDirections)k, true);
                        Faction          thisFaction      = gameLogicToDraw.GetTile(Tuple.Create(tileX, tileY)).OccupiedByFaction;

                        if (thisFaction == Faction.Empty)
                        {
                            if (gameLogicToDraw.GetTile(gameLogicToDraw.GetNeighbouringTile(Tuple.Create(tileX, tileY), (HexDirections)k)).OccupiedByFaction == Faction.Empty)
                            {
                                pen1 = new Pen(Color.Gray, penWidth);
                                graphics.DrawLine(pen1, p1, p2);
                            }
                        }
                        else
                        {
                            if (gameLogicToDraw.IsOutOfBounds(neighbouringTile))
                            {
                                pen1 = new Pen(FactionColors[thisFaction.ID], penWidth);
                                graphics.DrawLine(pen1, p1, p2);
                            }
                            else
                            {
                                Faction neighbourFaction = gameLogicToDraw.GetTile(neighbouringTile).OccupiedByFaction;
                                if (neighbourFaction == Faction.Empty)
                                {
                                    //if (k == (int)(HexDirections.Up))

                                    pen1 = new Pen(FactionColors[thisFaction.ID], penWidth);
                                    graphics.DrawLine(pen1, p1, p2);
                                }
                                else if (neighbourFaction == thisFaction)
                                {
                                    continue;
                                }
                                else
                                {
                                    pen1 = new Pen(FactionColors[thisFaction.ID], penWidth);
                                    Pen pen2 = new Pen(FactionColors[neighbourFaction.ID], penWidth);
                                    graphics.DrawLineTwoColour(pen1, pen2, p1, p2, 5);
                                }
                            }
                        }
                    }

                    string tileString = "X";
                    Pen    stringPen  = new Pen(Color.Red);
                    Pen    fillPen    = new Pen(Color.ForestGreen);
                    switch (thisTile.Type)
                    {
                    case TerrainTypes.Land:
                        tileString      = " ";
                        stringPen.Brush = Brushes.SandyBrown;
                        break;

                    case TerrainTypes.Water:
                        tileString      = " ";
                        stringPen.Brush = Brushes.Aqua;
                        fillPen.Color   = Color.DeepSkyBlue;
                        break;

                    case TerrainTypes.City:
                        tileString      = "c";
                        stringPen.Brush = Brushes.LightGray;
                        //fillPen.Color=Color.SandyBrown;
                        break;

                    case TerrainTypes.Harbor:
                        tileString      = "H";
                        stringPen.Brush = Brushes.Yellow;
                        break;

                    case TerrainTypes.Capital:
                        tileString      = "C";
                        stringPen.Brush = Brushes.DarkGray;
                        break;

                    default:
                        tileString = "X";
                        break;
                    }

                    RectangleF rect = new RectangleF(centerPointX - hexRadiusX * 0.8f, centerPointY - hexRadiusY * 0.8f, hexRadiusX * 1.6f, hexRadiusY * 1.6f);
                    graphics.FillEllipse(fillPen.Brush, rect);

                    graphics.DrawString(tileString,
                                        new Font(FontFamily.GenericSansSerif, 25), stringPen.Brush, new PointF(centerPointX - 15, centerPointY - 18));


                    graphics.DrawString(tileX.ToString() + ", " + tileY.ToString() + ";" + gameLogicToDraw.GetTile(Tuple.Create(tileX, tileY)).OccupiedByFaction.ID.ToString(),
                                        new Font(FontFamily.GenericMonospace, 7), Brushes.White, new PointF(centerPointX - 20, centerPointY - 7));
                }
            }

            /*GraphicsPath path = new GraphicsPath();
             * GraphicsPath path2 = new GraphicsPath();
             * //Point[] points = new Point[] { new Point(0, 50), new Point(25, 100), new Point(75, 100), new Point(100, 50), new Point(75, 0), new Point(25, 0) };
             *
             * Point point1 = new Point(-50, 50);
             * point1 = m.TransformPoint(point1);
             *
             * Point point2 = new Point(50, -50);
             * point2 = m.TransformPoint(point2);
             *
             * graphics.DrawLineTwoColour(pen1, pen2, point1, point2, 14);*/

            //path.CloseFigure();
        }
Example #2
0
	public RectangleF[] GetRegionScans(Matrix matrix)
	{
		//HACK: this is temporary and will not work on transforms with shear.
		RectangleF[] newRects = new RectangleF[rects.Length];
		for(int i = 0; i < newRects.Length; i++)
		{
			RectangleF r = rects[i];
			float ox, oy, or, ob;
			matrix.TransformPoint(r.X, r.Y, out ox, out oy);
			matrix.TransformPoint(r.Right, r.Bottom, out or, out ob);
			newRects[i] = RectangleF.FromLTRB(ox, oy, or, ob);
		}
		return newRects;
	}