示例#1
0
 //Vykreslení
 public void Draw(Graphics g, List <Color> colors)
 {
     foreach (Branch branch in Branches)
     {
         if (branch.Count > 1)
         {
             Pen pen = new Pen(colors[branch.Color], 0.3f);
             pen.StartCap = pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
             Point a = branch[0];
             for (int i = 1; i < branch.Count; i++)
             {
                 Point b = branch[i];
                 //Ošetří případ, kdy jde o přetečení přes okraj
                 if (Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y) > 1)
                 {
                     int dx = Grid.ModW(b.X - a.X);
                     if (dx > 1)
                     {
                         dx -= Grid.Width;
                     }
                     int dy = Grid.ModH(b.Y - a.Y);
                     if (dy > 1)
                     {
                         dy -= Grid.Height;
                     }
                     Pen pen2 = new Pen(colors[branch.Color], 0.3f);
                     pen2.StartCap = System.Drawing.Drawing2D.LineCap.Round;
                     g.DrawLine(pen2, new PointF(a.X + 0.5f, a.Y + 0.5f), new PointF(a.X + 0.5f * dx + 0.5f, a.Y + 0.5f * dy + 0.5f));
                     g.DrawLine(pen2, new PointF(b.X + 0.5f, b.Y + 0.5f), new PointF(b.X - 0.5f * dx + 0.5f, b.Y - 0.5f * dy + 0.5f));
                 }
                 //Ostatní případy
                 else
                 {
                     g.DrawLine(pen, new PointF(a.X + 0.5f, a.Y + 0.5f), new PointF(b.X + 0.5f, b.Y + 0.5f));
                 }
                 //Překreslit horní čáru přes most
                 if (Grid.Bridges[a.X, a.Y])
                 {
                     Pen pen3 = new Pen(Color.Black, 0.3f);
                     if (Cells[a.X, a.Y] >= 0)
                     {
                         pen3 = new Pen(colors[Cells[a.X, a.Y]], 0.3f);
                     }
                     g.DrawLine(pen3, new PointF(a.X, a.Y + 0.5f), new PointF(a.X + 1, a.Y + 0.5f));
                 }
                 a = b;
             }
         }
     }
     Grid.RedrawBridges(g);
 }
示例#2
0
 protected override void Apply(Point coords, Grid grid)
 {
     if (0 <= coords.X && coords.X <= 2 * grid.Width + 1 && 0 <= coords.Y && coords.Y <= 2 * grid.Height + 1)
     {
         int dx = coords.Y % 2; //schválně "naopak", zajímá mě lichost v kolmém směru
         int dy = coords.X % 2;
         int x  = coords.X - dx;
         int y  = coords.Y - dy;
         if (Grid.Directions.All(d => !grid.Bridges[grid.ModW((x + dx * d.X) / 2), grid.ModH((y + dy * d.Y) / 2)]))
         {
             grid.Walls[grid.Mod2W(coords.X), grid.Mod2H(coords.Y)] ^= true;
         }
     }
 }
示例#3
0
 private int AreaTo(Point p, Point d)
 {
     return(Areas[Grid.ModW(p.X + d.X), Grid.ModH(p.Y + d.Y)]);
 }
示例#4
0
 private int CellTo(Point p, Point d)
 {
     return(Cells[Grid.ModW(p.X + d.X), Grid.ModH(p.Y + d.Y)]);
 }