Skip to content

Commit 626e553

Browse files
author
242440 Adam Kruszynski
committed
some minor modifications, Logic tests done
1 parent c618b8b commit 626e553

22 files changed

Lines changed: 141 additions & 1 deletion

File tree

Data/bin/Debug/net6.0/Data.dll

0 Bytes
Binary file not shown.

Data/bin/Debug/net6.0/Data.pdb

-20 Bytes
Binary file not shown.

Logic/ILogic.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public interface ILogic // Logic API
1111
void Initialize(int width, int height, int ballsNumber, int ballsRadius = 25, int ballsWeight = 10, int ballsSpeed = 5);
1212
ILocation GetLocation(int index);
1313

14+
int GetDirectionValue(int index);
15+
void SetDirectionValue(int i, int value);
16+
int MockFindPotentialCollision(int index);
17+
1418
void Start();
1519
void Stop();
1620
}

Logic/Logic.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ public ILocation GetLocation(int index)
139139
return new Location { X = _ballsManager.GetBall(index).X, Y = _ballsManager.GetBall(index).Y };
140140
}
141141

142+
public int GetDirectionValue(int index)
143+
{
144+
return _directions[index];
145+
}
146+
147+
148+
public void SetDirectionValue(int i, int value)
149+
{
150+
_directions[i] = value;
151+
}
152+
142153
public void Initialize(int width, int height, int ballsNumber, int ballsRadius = 25, int ballsWeight = 10, int ballsSpeed = 5)
143154
{
144155
_ballsNumber = ballsNumber;
@@ -182,6 +193,28 @@ static int FindPotentialCollision(int index)
182193
return -1; // not found
183194
}
184195

196+
public int MockFindPotentialCollision(int index)
197+
{
198+
IBall ball = _ballsManager.GetBall(index);
199+
int ballX = ball.X;
200+
int ballY = ball.Y;
201+
for (int ballNumber = 0; ballNumber < _ballsNumber; ++ballNumber)
202+
{
203+
if (index == ballNumber)
204+
{
205+
continue;
206+
}
207+
int comparedX = _ballsManager.GetBall(ballNumber).X;
208+
int comparedY = _ballsManager.GetBall(ballNumber).Y;
209+
int distance = (int)Math.Round(Math.Sqrt((ballX - comparedX) * (ballX - comparedX) + (ballY - comparedY) * (ballY - comparedY)));
210+
if (distance <= 2 * _ballRadius)
211+
{
212+
return ballNumber; // collision of two balls
213+
}
214+
}
215+
return -1; // not found
216+
}
217+
185218
public void Start()
186219
{
187220
_isRunning = true;
@@ -199,5 +232,7 @@ public void Stop()
199232
_tasks[i].Wait();
200233
}
201234
}
235+
236+
202237
}
203238
}

Logic/bin/Debug/net6.0/Data.dll

0 Bytes
Binary file not shown.

Logic/bin/Debug/net6.0/Data.pdb

-20 Bytes
Binary file not shown.

Logic/bin/Debug/net6.0/Logic.dll

0 Bytes
Binary file not shown.

Logic/bin/Debug/net6.0/Logic.pdb

328 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)