コード例 #1
0
 private void DrawVillage(Graphics g, Agents.Village v, Rectangle area)
 {
     g.FillRectangle(Brushes.Bisque, 0, 0, 199, 628);
     g.DrawString("Food in Village: " + v.GetTotalFood.ToString("F1"), _fontArial, Brushes.BlueViolet, 0, 0);
     if (_selectedAgent != null)
     {
         DrawAgentDescription(g, area);
     }
     v.FoodGraph.Plot(g, new Rectangle(0, 20, 200, 200));
     g.DrawString("Agents in Village: " + v.GetAgentList.Count, _fontArial, Brushes.BlueViolet, 0, 264);
     v.PopGraph.Plot(g, new Rectangle(0, 284, 200, 200));
     g.DrawString("Genes in Village:", _fontArial, Brushes.BlueViolet, 0, 508);
     v.Genes.Plot(g, new Rectangle(0, 528, 200, 100));
 }
コード例 #2
0
 private void ui_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         float  realX = ((e.X - ui.Width * 0.5f) / _zoom + _camera.X) / _sizeRect;
         float  realY = ((e.Y - ui.Height * 0.5f) / _zoom + _camera.Y) / _sizeRect;
         object a     = null;
         float  minD  = float.MaxValue;
         foreach (var v in Board.GetVillages())
         {
             float d = Extensions.Sqr(v.VillageMain.X - realX) + Extensions.Sqr(v.VillageMain.Y - realY);
             if (d < 5 && d < minD)
             {
                 minD = d;
                 a    = v;
             }
             foreach (var agent in v.GetAgentList)
             {
                 d = Extensions.Sqr(agent.GetCurrentX - realX) + Extensions.Sqr(agent.GetCurrentY - realY);
                 if (d < 5 && d < minD)
                 {
                     minD = d;
                     a    = agent;
                 }
             }
         }
         if (_selectedAgent != null && a is Agents.Village)
         {
             _selectedVillage = (Agents.Village)a;
         }
         else
         {
             if (_selectedVillage != null && a is Agent)
             {
                 _selectedAgent = (Agent)a;
             }
             else
             {
                 if (_selectedAgent == null && _selectedVillage == null)
                 {
                     _selectedAgent   = a as Agent;
                     _selectedVillage = a as Agents.Village;
                 }
             }
         }
     }
     if (e.Button == MouseButtons.Middle)
     {
         float realX = ((e.X - ui.Width * 0.5f) / _zoom + _camera.X) / _sizeRect;
         float realY = ((e.Y - ui.Height * 0.5f) / _zoom + _camera.Y) / _sizeRect;
         int   x     = (int)realX;
         int   y     = (int)realY;
         if (VillageValid(x, y) && Board.FullBoard[x, y].GetBase() == -1)
         {
             Agents.Village v  = new Agents.Village(Board, new PointF(x, y));
             int            cv = Board.GetVillages().Count;
             Board.FullBoard[x, y].SetBase(cv);
             Board.FullBoard[x - 1, y].SetBase(cv);
             Board.FullBoard[x + 1, y].SetBase(cv);
             Board.FullBoard[x, y - 1].SetBase(cv);
             Board.FullBoard[x, y + 1].SetBase(cv);
             Board.GetVillages().Add(v);
             for (int i = 0; i < Board.GetVillages().Count; i++)
             {
                 v       = Board.GetVillages()[i];
                 v.Brush = new SolidBrush(Extensions.HsvToRgb((360 * i) / (float)Board.GetVillages().Count, 1, 1));
             }
         }
     }
 }