public void UpdateFrame() { if (m_positionList.Count >= m_maxLength) { // remove from the 'end' which is the beginning of this list m_positionList.RemoveAt(0); } // let's move the worm in some random position DomePosition currentHeadPos = (DomePosition)m_positionList[m_positionList.Count - 1]; DomePosition newHeadPos = new DomePosition(); newHeadPos.m_ribPos = currentHeadPos.m_ribPos; newHeadPos.m_rowPos = currentHeadPos.m_rowPos; // this random looks a bit weird, but C# returns a value greater than or equal to the min // but LESS THAN the max int ribDelta = m_random.Next(-1, 2); int rowDelta = m_random.Next(-1, 3); newHeadPos.m_ribPos += ribDelta; newHeadPos.m_rowPos += rowDelta; // handle wrapping around from one end of the dome to another newHeadPos.m_ribPos += Dome.NUM_RIBS; newHeadPos.m_rowPos += Dome.LEDS_PER_RIB; // now make sure that the new position is in bounds newHeadPos.m_ribPos %= Dome.NUM_RIBS; newHeadPos.m_rowPos %= Dome.LEDS_PER_RIB; // add this new position to the list m_positionList.Add(newHeadPos); }
public SexWorm(int ribPos, int rowPos, int maxLength, int randomSeed, int refractoryFrames) { m_random = new Random(randomSeed); m_Color = ColorManager.RandomColor(); // start out with a random position DomePosition firstPos = new DomePosition(); firstPos.m_ribPos = ribPos; firstPos.m_rowPos = rowPos; // set the max length m_maxLength = maxLength; // add in the first position m_positionList.Add(firstPos); m_refractoryFrames = refractoryFrames; }