All pastes #989932 Raw Edit

Stuff

public text v1 · immutable
#989932 ·published 2008-04-19 21:19 UTC
rendered paste body
The following code causes the bool function "IsHit(pos,clickTime)" to retain a true value (and thus increase the molesHit variable) about 100 times before the statement is false.
The m object is a mouse class that checks to see if the mouse has been clicked.  If it has, the current position is set.  It works correctly.

How can I change this code so that the statement will only be true once?

while (GetTimeInSecs() < EndTime)
{
	gotoxy(0,2);
	SetC(YELLOW);
	cout << "Time Remaining: " << fixed << setprecision(1) << EndTime-GetTimeInSecs();

	if (m.clicked())
	{
		pos = m.position(); // Current X/Y cordinates saved
		clickTime = GetTimeInSecs();
	}
	
	if ((s.IsHit(pos,clickTime)) ||
	   (GetTimeInSecs() >= s.StartTime()+s.Duration()))
	{
		if (s.IsHit(pos,clickTime)) { 
			molesHit++;
			gotoxy(60,2);
			cout << "Mole(s) Hit: " << fixed << setprecision(1) << molesHit;
			pos.X = 0; // Must reset position
			pos.Y = 0; // Must reset position
		}
		s.Erase();
		moleX = rand() % 60;
		moleY = rand() % 18;
		if (moleY <= 4) { moleY += 4; } // Prevent covering heading
		s.Set(moleX,moleY,moleX+strength,moleY+strength);
		s.SetColor(Color(rand() % 10));
		if (s.Duration() > 0.5) { s.SetDuration(s.Duration()-0.5); } // Limit mole duration
		s.Draw();
	}
}