Example #1
0
File: Form1.cs Project: jwk000/Ant
 void initAnts()
 {
     for (int i = 0; i < m_kAntCount; i++)
     {
         int    x   = rander.Next(10, m_kXCount - 10);
         int    y   = rander.Next(10, m_kYCount - 10);
         TheAnt ant = new TheAnt();
         ant.pos.X     = x;
         ant.pos.Y     = y;
         ant.direction = rander.Next(0, 3);
         ant.rect.X    = x * m_kGridSize + m_kGridSize / 4;
         ant.rect.Y    = y * m_kGridSize + m_kGridSize / 4;
         m_ants.Add(ant);
     }
 }
Example #2
0
File: Form1.cs Project: jwk000/Ant
        void moveNext(TheAnt ant)
        {
            int r = rander.Next(0, 100);

            if (m_allGrids[ant.pos.X, ant.pos.Y].black)
            //if(r<60)
            {
                //黑-右转
                ant.pos      += m_Roffset[ant.direction];
                ant.direction = (ant.direction + 1) % 4;
            }
            else
            {
                //白-左转
                ant.pos      += m_Loffset[ant.direction];
                ant.direction = (ant.direction + 1) % 4;
            }
            //越界穿透
            if (ant.pos.X < 0)
            {
                ant.pos.X = m_kXCount - 1;
            }
            if (ant.pos.Y < 0)
            {
                ant.pos.Y = m_kYCount - 1;
            }
            if (ant.pos.X == m_kXCount)
            {
                ant.pos.X = 0;
            }
            if (ant.pos.Y == m_kYCount)
            {
                ant.pos.Y = 0;
            }
            ant.rect.X = m_allGrids[ant.pos.X, ant.pos.Y].rect.Left + m_kGridSize / 4;
            ant.rect.Y = m_allGrids[ant.pos.X, ant.pos.Y].rect.Top + m_kGridSize / 4;
            m_allGrids[ant.pos.X, ant.pos.Y].black = !m_allGrids[ant.pos.X, ant.pos.Y].black;
        }