internal Vector2 GetVelocityPixelsPerMs() { if (motionQueue.Count > 1) { // Get all the movement that is less 100 ms from the last time (the mouse up) TimeAndPosition lastTime = motionQueue[motionQueue.Count - 1]; int firstTimeIndex = motionQueue.Count - 1; while (firstTimeIndex > 0 && motionQueue[firstTimeIndex - 1].timeMs + 100 > lastTime.timeMs) { firstTimeIndex--; } TimeAndPosition firstTime = motionQueue[firstTimeIndex]; double milliseconds = lastTime.timeMs - firstTime.timeMs; if (milliseconds > 0) { Vector2 pixels = lastTime.position - firstTime.position; Vector2 pixelsPerSecond = pixels / milliseconds; return(pixelsPerSecond); } } return(Vector2.Zero); }
public IEnumerator WHEN_TimeAndPositionCreated_THEN_TimeGetFunctionWorks() { tempTimeAndPosition = new TimeAndPosition(3, new Position2D(3, 5)); tempTime = tempTimeAndPosition.Time; yield return(null); Assert.AreEqual(3, tempTime); }
// Add clickTime N times to the Clicks List private List <TimeAndPosition> AddClickItemsNTimes(TimeAndPosition clickItem, int N) { List <TimeAndPosition> resultList = new List <TimeAndPosition>(); for (int i = 0; i < N; i++) { resultList.Add(clickItem); } return(resultList); }
public void SetUp() { // Create example clicks: List <TimeAndPosition> exampleClicks = new List <TimeAndPosition>(); TimeAndPosition timeAndPosition_normal = new TimeAndPosition(0.8, new Position2D(0, 0)); exampleClicks.Add(timeAndPosition_normal); // Create example balloon rounds: // balloonRound is an exmaple of round balloonRound.BalloonSize = 60; balloonRound.DestinationPoint = new Position2D(100, 200); balloonRound.DestinationClickTime = 0.8; balloonRound.Clicks = new List <TimeAndPosition>(); balloonRound.SuccessClickPoint = new Position2D(102, 197); // balloonRound_shortestPossibleDestClickTime is an exmaple of round with extreme short DestinationClickTime // which is smaller than 0.15s(the fastest human reaction time) // other fields are the same with balloonRound balloonRound_shortestPossibleDestClickTime.BalloonSize = 60; balloonRound_shortestPossibleDestClickTime.DestinationPoint = new Position2D(100, 200); balloonRound_shortestPossibleDestClickTime.DestinationClickTime = 0.1; // time smaller than 0.15 which is the fastest human reaction time balloonRound_shortestPossibleDestClickTime.Clicks = new List <TimeAndPosition>(); balloonRound_shortestPossibleDestClickTime.SuccessClickPoint = new Position2D(102, 197); // balloonRound_longDestClickTime is an exmaple of round with long DestinationClickTime // other fields are the same with balloonRound balloonRound_longDestClickTime.BalloonSize = 60; balloonRound_longDestClickTime.DestinationPoint = new Position2D(100, 200); balloonRound_longDestClickTime.DestinationClickTime = 1.5; // long destination click time balloonRound_longDestClickTime.Clicks = new List <TimeAndPosition>(); balloonRound_longDestClickTime.SuccessClickPoint = new Position2D(102, 197); // balloonRound_longDistance is an exmaple of round with long distance between SuccessClickPoint and DestinationPoint // other fields are the same with balloonRound balloonRound_longDistance.BalloonSize = 60; balloonRound_longDistance.DestinationPoint = new Position2D(100, 200); balloonRound_longDistance.DestinationClickTime = 0.8; balloonRound_longDistance.Clicks = new List <TimeAndPosition>(); balloonRound_longDistance.SuccessClickPoint = new Position2D(89, 210); // further distance // balloonRound_hasMultipleClicks is an exmaple of round with one unsuccessful click // other fields are the same with balloonRound balloonRound_hasMultipleClicks.BalloonSize = 60; balloonRound_hasMultipleClicks.DestinationPoint = new Position2D(100, 200); balloonRound_hasMultipleClicks.DestinationClickTime = 0.8; balloonRound_hasMultipleClicks.Clicks = exampleClicks; // one extra click balloonRound_hasMultipleClicks.SuccessClickPoint = new Position2D(102, 197); }
/// <summary> /// PressNotOnObject is the function called when there is a /// click action, and this click attempt on the balloon is /// unsuccessful. /// </summary> private void PressNotOnObject() { // If the click attempt was with the left mouse button if (Input.GetMouseButtonUp(0)) { // Get the local position as a Position2D pos = convertScreenToLocalPosition2D(); // Create a timeAndPosition object for the unsuccessful click TimeAndPosition timeAndPosition = new TimeAndPosition(initClickTime, pos); // Add the unsuccessful click object to the list of unsuccessful click objects round.Clicks.Add(timeAndPosition); // Reset the timer for time between unsuccessful clicks initClickTime = 0; } }
public IEnumerator WHEN_BalloonRoundAdded1Round_THEN_BalloonRoundGetterReturnsCorrectValues() { balloonsData = new BalloonsStorage(); balloonsData.Rounds = new List <BalloonsRound>(); round = new BalloonsRound(); round.BalloonSize = 180; double expectedBalloonSize = 180; round.DestinationClickTime = 1.5; double expectedDestinationClickTime = 1.5; round.DestinationPoint = new Position2D(0, 0); Position2D expectedDestinationPoint = new Position2D(0, 0); round.SuccessClickPoint = new Position2D(-200, 67); Position2D expectedSuccessClickPoint = new Position2D(-200, 67); TimeAndPosition testItem1 = new TimeAndPosition(0.5, new Position2D(10, 20)); TimeAndPosition testItem2 = new TimeAndPosition(1.5, new Position2D(0.1, -40)); round.Clicks = new List <TimeAndPosition>(); round.Clicks.Add(testItem1); round.Clicks.Add(testItem2); balloonsData.Rounds.Add(round); BalloonsRound actualCirclesRound = balloonsData.Rounds[0]; yield return(null); Assert.IsTrue(expectedBalloonSize == actualCirclesRound.BalloonSize); Assert.IsTrue(expectedDestinationClickTime == actualCirclesRound.DestinationClickTime); Assert.IsTrue(Math.Abs(expectedDestinationPoint.X - actualCirclesRound.DestinationPoint.X) <= tolerance && Math.Abs(expectedDestinationPoint.Y - actualCirclesRound.DestinationPoint.Y) <= tolerance); Assert.IsTrue(Math.Abs(expectedSuccessClickPoint.X - actualCirclesRound.SuccessClickPoint.X) <= tolerance && Math.Abs(expectedSuccessClickPoint.Y - actualCirclesRound.SuccessClickPoint.Y) <= tolerance); Assert.IsTrue(2 == actualCirclesRound.Clicks.Count); Assert.IsTrue(Math.Abs(testItem1.Time - actualCirclesRound.Clicks[0].Time) <= tolerance && Math.Abs(testItem1.Position.X - actualCirclesRound.Clicks[0].Position.X) <= tolerance && Math.Abs(testItem1.Position.Y - actualCirclesRound.Clicks[0].Position.Y) <= tolerance); Assert.IsTrue(Math.Abs(testItem2.Time - actualCirclesRound.Clicks[1].Time) <= tolerance && Math.Abs(testItem2.Position.X - actualCirclesRound.Clicks[1].Position.X) <= tolerance && Math.Abs(testItem2.Position.Y - actualCirclesRound.Clicks[1].Position.Y) <= tolerance); }
public IEnumerator WHEN_ClicksAdd1Item_THEN_ClicksHas1Item() { TimeAndPosition testTimeAndPosition = new TimeAndPosition(0.5, new Position2D(35, 45)); round = new BalloonsRound(); round.Clicks = new List <TimeAndPosition>(); round.Clicks.Add(testTimeAndPosition); int expectedSizeOfList = 1; yield return(null); // Clciks has only 1 items: Assert.IsTrue(expectedSizeOfList == round.Clicks.Count); // The only 1 item should be testTimeAndPosition: Assert.IsTrue(Math.Abs(round.Clicks[0].Time - testTimeAndPosition.Time) <= tolerance); Assert.IsTrue(Math.Abs(round.Clicks[0].Position.X - testTimeAndPosition.Position.X) <= tolerance && Math.Abs(round.Clicks[0].Position.Y - testTimeAndPosition.Position.Y) <= tolerance); }
public void CreateExampleObjects() { // Create example clicks: List <TimeAndPosition> exampleClicks_normal = new List <TimeAndPosition>(); TimeAndPosition timeAndPosition_normal = new TimeAndPosition(0.8, new Position2D(0, 0)); exampleClicks_normal.Add(timeAndPosition_normal); List <TimeAndPosition> exampleClicks_longTime = new List <TimeAndPosition>(); TimeAndPosition timeAndPosition_longTime = new TimeAndPosition(1.5, new Position2D(0, 0)); exampleClicks_longTime.Add(timeAndPosition_normal); // Create example balloon rounds: // balloonRound is an exmaple of round balloonRound.BalloonSize = 60; balloonRound.DestinationPoint = new Position2D(100, 200); balloonRound.DestinationClickTime = 0.8; balloonRound.Clicks = new List <TimeAndPosition>(); balloonRound.SuccessClickPoint = new Position2D(102, 197); // balloonRound_shortestPossibleDestClickTime is an exmaple of round with extreme short DestinationClickTime // which is smaller than 0.15s(the fastest human reaction time) // other fields are the same with balloonRound balloonRound_shortestPossibleDestClickTime.BalloonSize = 60; balloonRound_shortestPossibleDestClickTime.DestinationPoint = new Position2D(100, 200); balloonRound_shortestPossibleDestClickTime.DestinationClickTime = 0.1; // time smaller than 0.15 which is the fastest human reaction time balloonRound_shortestPossibleDestClickTime.Clicks = new List <TimeAndPosition>(); balloonRound_shortestPossibleDestClickTime.SuccessClickPoint = new Position2D(102, 197); // balloonRound_longDestinationClickTime is an exmaple of round with long DestinationClickTime // other fields are the same with balloonRound balloonRound_longDestinationClickTime.BalloonSize = 60; balloonRound_longDestinationClickTime.DestinationPoint = new Position2D(100, 200); balloonRound_longDestinationClickTime.DestinationClickTime = 1.5; // long destination click time balloonRound_longDestinationClickTime.Clicks = new List <TimeAndPosition>(); balloonRound_longDestinationClickTime.SuccessClickPoint = new Position2D(102, 197); // balloonRound_longTimeInClicks is an exmaple of round with long time in clicks items // other fields are the same with balloonRound balloonRound_longTimeInClicks.BalloonSize = 60; balloonRound_longTimeInClicks.DestinationPoint = new Position2D(100, 200); balloonRound_longTimeInClicks.DestinationClickTime = 0.8; balloonRound_longTimeInClicks.Clicks = exampleClicks_longTime; // long time in clicks item balloonRound_longTimeInClicks.SuccessClickPoint = new Position2D(102, 197); // balloonRound_hasUnsuccessfulClicks is an exmaple of round with one unsuccessful click // other fields are the same with balloonound balloonRound_hasOneUnsuccessfulClick.BalloonSize = 60; balloonRound_hasOneUnsuccessfulClick.DestinationPoint = new Position2D(100, 200); balloonRound_hasOneUnsuccessfulClick.DestinationClickTime = 0.8; balloonRound_hasOneUnsuccessfulClick.Clicks = exampleClicks_normal; // one unsuccessful clicks balloonRound_hasOneUnsuccessfulClick.SuccessClickPoint = new Position2D(102, 197); // balloonRound_has4UnsuccessfulClick has 4 same click items as in balloonRound_hasUnsuccessfulClicks // other fields are the same with balloonRound_hasUnsuccessfulClicks balloonRound_has4UnsuccessfulClick.BalloonSize = 60; balloonRound_has4UnsuccessfulClick.DestinationPoint = new Position2D(100, 200); balloonRound_has4UnsuccessfulClick.Clicks = AddClickItemsNTimes(timeAndPosition_normal, 4); balloonRound_has4UnsuccessfulClick.SuccessClickPoint = new Position2D(102, 197); // balloonRound_has9UnsuccessfulClick has 9 same click items as in balloonRound_hasUnsuccessfulClicks // other fields are the same with balloonRound_hasUnsuccessfulClicks balloonRound_has9UnsuccessfulClick.BalloonSize = 60; balloonRound_has9UnsuccessfulClick.DestinationPoint = new Position2D(100, 200); balloonRound_has9UnsuccessfulClick.Clicks = AddClickItemsNTimes(timeAndPosition_normal, 9); balloonRound_has9UnsuccessfulClick.SuccessClickPoint = new Position2D(102, 197); // balloonRound_has14UnsuccessfulClick has 14 same click items as in balloonRound_hasUnsuccessfulClicks // other fields are the same with balloonRound_hasUnsuccessfulClicks balloonRound_has14UnsuccessfulClick.BalloonSize = 60; balloonRound_has14UnsuccessfulClick.DestinationPoint = new Position2D(100, 200); balloonRound_has14UnsuccessfulClick.Clicks = AddClickItemsNTimes(timeAndPosition_normal, 14); balloonRound_has14UnsuccessfulClick.SuccessClickPoint = new Position2D(102, 197); // balloonRound_has20UnsuccessfulClick has 20 same click items as in balloonRound_hasUnsuccessfulClicks // other fields are the same with balloonRound_hasUnsuccessfulClicks balloonRound_has20UnsuccessfulClick.BalloonSize = 60; balloonRound_has20UnsuccessfulClick.DestinationPoint = new Position2D(100, 200); balloonRound_has20UnsuccessfulClick.Clicks = AddClickItemsNTimes(timeAndPosition_normal, 20); balloonRound_has20UnsuccessfulClick.SuccessClickPoint = new Position2D(102, 197); catchRound.IsIdentifiedKeyPressed = true; catchRound.identifiedKeyPressTime = 0.15f; catchRound.ThiefAppearInRound = false; catchRound.PersonAppearInRound = true; catchRound_longTimeInClicks.IsIdentifiedKeyPressed = true; catchRound_longTimeInClicks.identifiedKeyPressTime = 0.5f; catchRound_longTimeInClicks.ThiefAppearInRound = true; catchRound_longTimeInClicks.PersonAppearInRound = false; catchRound_showTimeInClicks.IsIdentifiedKeyPressed = true; catchRound_showTimeInClicks.identifiedKeyPressTime = 0.8f; catchRound_showTimeInClicks.ThiefAppearInRound = true; catchRound_showTimeInClicks.PersonAppearInRound = false; imaghtHitRound.Add(new ImageHitRound()); imahtHitRound_longTimeInClicks.Add(new ImageHitRound()); imageHit_showTimeInClicks.Add(new ImageHitRound()); imaghtHitRound[0].imageName = ""; imaghtHitRound[0].imageTheme = ""; imaghtHitRound[0].isCorrectlyIdentified = false; imaghtHitRound[0].isKeyPressed = false; imaghtHitRound[0].isSpaceKey = false; imaghtHitRound[0].keyPressTime = 0.5f; imaghtHitRound[0].testTheme = ""; imahtHitRound_longTimeInClicks[0] = new ImageHitRound(); imahtHitRound_longTimeInClicks[0].imageName = ""; imahtHitRound_longTimeInClicks[0].imageTheme = ""; imahtHitRound_longTimeInClicks[0].isCorrectlyIdentified = false; imahtHitRound_longTimeInClicks[0].isKeyPressed = false; imahtHitRound_longTimeInClicks[0].isSpaceKey = false; imahtHitRound_longTimeInClicks[0].keyPressTime = 0.2f; imahtHitRound_longTimeInClicks[0].testTheme = ""; imageHit_showTimeInClicks[0] = new ImageHitRound(); imageHit_showTimeInClicks[0].imageName = ""; imageHit_showTimeInClicks[0].imageTheme = ""; imageHit_showTimeInClicks[0].isCorrectlyIdentified = false; imageHit_showTimeInClicks[0].isKeyPressed = false; imageHit_showTimeInClicks[0].isSpaceKey = false; imageHit_showTimeInClicks[0].keyPressTime = 0.8f; imageHit_showTimeInClicks[0].testTheme = ""; }
public void SetUp() { // Create example clicks: List <TimeAndPosition> exampleClicks = new List <TimeAndPosition>(); TimeAndPosition timeAndPosition_longTime = new TimeAndPosition(1.5, new Position2D(0, 0)); exampleClicks.Add(timeAndPosition_longTime); // Create example balloon rounds: // balloonRound is an exmaple of round balloonRound.BalloonSize = 60; balloonRound.DestinationPoint = new Position2D(100, 200); balloonRound.DestinationClickTime = 0.8; balloonRound.Clicks = new List <TimeAndPosition>(); balloonRound.SuccessClickPoint = new Position2D(102, 197); // balloonRound_shortestPossibleDestClickTime is an exmaple of round with extreme short DestinationClickTime // which is smaller than 0.15s(the fastest human reaction time) // other fields are the same with balloonRound balloonRound_shortestPossibleDestClickTime.BalloonSize = 60; balloonRound_shortestPossibleDestClickTime.DestinationPoint = new Position2D(100, 200); balloonRound_shortestPossibleDestClickTime.DestinationClickTime = 0.1; // time smaller than 0.15 which is the fastest human reaction time balloonRound_shortestPossibleDestClickTime.Clicks = new List <TimeAndPosition>(); balloonRound_shortestPossibleDestClickTime.SuccessClickPoint = new Position2D(102, 197); // balloonRound_longMoveTimeInDestinationClickTime is an exmaple of round with long DestinationClickTime // other fields are the same with balloonRound balloonRound_longDestinationClickTime.BalloonSize = 60; balloonRound_longDestinationClickTime.DestinationPoint = new Position2D(100, 200); balloonRound_longDestinationClickTime.DestinationClickTime = 1.5; // long destination click time balloonRound_longDestinationClickTime.Clicks = new List <TimeAndPosition>(); balloonRound_longDestinationClickTime.SuccessClickPoint = new Position2D(102, 197); // balloonRound_longMoveTimeInClicks is an exmaple of round with long time in clicks items // other fields are the same with balloonRound balloonRound_longTimeInClicks.BalloonSize = 60; balloonRound_longTimeInClicks.DestinationPoint = new Position2D(100, 200); balloonRound_longTimeInClicks.DestinationClickTime = 0.8; balloonRound_longTimeInClicks.Clicks = exampleClicks; // long time in clicks item balloonRound_longTimeInClicks.SuccessClickPoint = new Position2D(102, 197); // Example squares IndexAndPosition IndexAndPositionIndex0 = new IndexAndPosition(0, new Position2D(0, 0)); IndexAndPosition IndexAndPositionIndex1 = new IndexAndPosition(1, new Position2D(1, 1)); // Set data for round where Highlighted and Recalled are identical in Squares mini-game squareRound_sameOrder.HighlightedSquares = new List <IndexAndPosition>(); squareRound_sameOrder.HighlightedSquares.Add(IndexAndPositionIndex0); squareRound_sameOrder.HighlightedSquares.Add(IndexAndPositionIndex1); squareRound_sameOrder.RecalledSquares = new List <IndexAndPosition>(); squareRound_sameOrder.RecalledSquares.Add(IndexAndPositionIndex0); squareRound_sameOrder.RecalledSquares.Add(IndexAndPositionIndex1); squareRound_sameOrder.RecallTime = 4f; squareRound_sameOrder.SquareHighlightInterval = 0.7f; squareRound_sameOrder.SquareHighlightInterval = 0.7f; // Set data for round where Highlighted and Recalled squares are in a different order in Squares mini-game squareRound_differentOrder.HighlightedSquares = new List <IndexAndPosition>(); squareRound_differentOrder.HighlightedSquares.Add(IndexAndPositionIndex0); squareRound_differentOrder.HighlightedSquares.Add(IndexAndPositionIndex1); squareRound_differentOrder.RecalledSquares = new List <IndexAndPosition>(); squareRound_differentOrder.RecalledSquares.Add(IndexAndPositionIndex1); squareRound_differentOrder.RecalledSquares.Add(IndexAndPositionIndex0); squareRound_differentOrder.RecallTime = 4f; squareRound_differentOrder.SquareHighlightInterval = 0.7f; squareRound_differentOrder.SquareHighlightInterval = 0.7f; // Set data for round where Recalled squares has a gap value in Squares mini-game squareRound_gap.HighlightedSquares = new List <IndexAndPosition>(); squareRound_gap.HighlightedSquares.Add(IndexAndPositionIndex0); squareRound_gap.HighlightedSquares.Add(IndexAndPositionIndex1); squareRound_gap.RecalledSquares = new List <IndexAndPosition>(); squareRound_gap.RecalledSquares.Add(IndexAndPositionIndex0); squareRound_gap.RecallTime = 4f; squareRound_gap.SquareHighlightInterval = 0.7f; squareRound_gap.SquareHighlightInterval = 0.7f; // Set data for round where Recalled squares has a mismatch value in Squares mini-game squareRound_mismatch.HighlightedSquares = new List <IndexAndPosition>(); squareRound_mismatch.HighlightedSquares.Add(IndexAndPositionIndex0); squareRound_mismatch.HighlightedSquares.Add(IndexAndPositionIndex1); squareRound_mismatch.RecalledSquares = new List <IndexAndPosition>(); squareRound_mismatch.RecalledSquares.Add(IndexAndPositionIndex0); squareRound_mismatch.RecallTime = 4f; squareRound_mismatch.SquareHighlightInterval = 0.7f; squareRound_mismatch.SquareHighlightInterval = 0.7f; catchRound.IsIdentifiedKeyPressed = true; catchRound.identifiedKeyPressTime = 0.15f; catchRound.ThiefAppearInRound = false; catchRound.PersonAppearInRound = true; catchRound_longTimeInClicks.IsIdentifiedKeyPressed = true; catchRound_longTimeInClicks.identifiedKeyPressTime = 0.5f; catchRound_longTimeInClicks.ThiefAppearInRound = true; catchRound_longTimeInClicks.PersonAppearInRound = false; catchRound_showTimeInClicks.IsIdentifiedKeyPressed = true; catchRound_showTimeInClicks.identifiedKeyPressTime = 0.8f; catchRound_showTimeInClicks.ThiefAppearInRound = true; catchRound_showTimeInClicks.PersonAppearInRound = false; catchRound_showTimeInClicks.IsIdentifiedKeyPressed = true; catchRound_showTimeInClicks.identifiedKeyPressTime = 0.8f; catchRound_showTimeInClicks.ThiefAppearInRound = true; catchRound_showTimeInClicks.PersonAppearInRound = false; imaghtHitRound.Add(new ImageHitRound()); imahtHitRound_longTimeInClicks.Add(new ImageHitRound()); imageHit_showTimeInClicks.Add(new ImageHitRound()); imaghtHitRound[0] = new ImageHitRound(); imaghtHitRound[0].imageName = ""; imaghtHitRound[0].imageTheme = ""; imaghtHitRound[0].isCorrectlyIdentified = false; imaghtHitRound[0].isKeyPressed = false; imaghtHitRound[0].isSpaceKey = false; imaghtHitRound[0].keyPressTime = 0.5f; imaghtHitRound[0].testTheme = ""; imahtHitRound_longTimeInClicks[0] = new ImageHitRound(); imahtHitRound_longTimeInClicks[0].imageName = ""; imahtHitRound_longTimeInClicks[0].imageTheme = ""; imahtHitRound_longTimeInClicks[0].isCorrectlyIdentified = false; imahtHitRound_longTimeInClicks[0].isKeyPressed = false; imahtHitRound_longTimeInClicks[0].isSpaceKey = false; imahtHitRound_longTimeInClicks[0].keyPressTime = 0.2f; imahtHitRound_longTimeInClicks[0].testTheme = ""; imageHit_showTimeInClicks[0] = new ImageHitRound(); imageHit_showTimeInClicks[0].imageName = ""; imageHit_showTimeInClicks[0].imageTheme = ""; imageHit_showTimeInClicks[0].isCorrectlyIdentified = false; imageHit_showTimeInClicks[0].isKeyPressed = false; imageHit_showTimeInClicks[0].isSpaceKey = false; imageHit_showTimeInClicks[0].keyPressTime = 0.8f; imageHit_showTimeInClicks[0].testTheme = ""; }