-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestZombi.cs
107 lines (94 loc) · 4.02 KB
/
TestZombi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using Minecraft.Models;
using System.Drawing;
namespace UnitTestProject1
{
[TestClass]
public class TestZombi
{
private readonly int[,] mapWithOutBlockInto = { { 1, 1, 1, 1, 1, 1 }, { 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 1 }, { 1, 1, 1, 1, 1, 1 } };
private readonly int[,] mapWithBlockInto = { { 1, 1, 1, 1, 1, 1 }, { 1, 0, 0, 1, 0, 1 }, { 1, 0, 0, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 1 }, { 1, 0, 0, 0, 0, 1 }, { 1, 0, 1, 0, 0, 1 }, { 1, 0, 1, 0, 0, 1 }, { 1, 1, 1, 1, 1, 1 } };
private readonly int[] decorationObject = { 0, 4, 5 };
[TestMethod]
public void FinishPointInTwoQuarter()
{
Assert.AreEqual(true, IsTrueWay(new Point() { X = 240, Y = 240 }, new Point() { X = 120, Y = 120 }));
}
[TestMethod]
public void FinishPointInThreeQuarter()
{
Assert.AreEqual(true, IsTrueWay(new Point() { X = 120, Y = 120 }, new Point() { X = 240, Y = 240 }));
}
[TestMethod]
public void FinishPointIsStartPoint()
{
Assert.AreEqual(true, IsTrueWay(new Point() { X = 240, Y = 240 }, new Point() { X = 240, Y = 240 }));
}
[TestMethod]
public void MapWithObjectTrueWay()
{
Assert.AreEqual(true, IsTrueWayWithBlock(new Point() { X = 100 ,Y = 200}, new Point() { X =140, Y = 140 }));
}
[TestMethod]
public void TestSolverRandom()
{
var rnd = new Random();
var isGoodWay = true;
for (var i = 0; i < 10; i++)
{
isGoodWay = isGoodWay && IsTrueWay(new Point() { X = rnd.Next(100, 300), Y = rnd.Next(100, 300) },
new Point() { X = rnd.Next(100, 300), Y = rnd.Next(100, 300) });
}
Assert.AreEqual(true, isGoodWay);
}
private bool IsTrueWay(Point playerPoint, Point creaturesPoint)
{
var zombi = new Zombi(creaturesPoint);
var player = new Player(playerPoint);
var isIntoPoint = false;
var count = MaxCountToObject(creaturesPoint, playerPoint);
var glowingBalls = new List<GlowingBalls>();
for (var i = 0; i < count; i++)
{
var point = zombi.GetChangePosition(mapWithOutBlockInto, player, decorationObject, new ScreenPoint(new Point() {X=0,Y=0}),glowingBalls);
if (IsPointIntoArea(playerPoint, point, 40))
{
isIntoPoint = true;
break;
}
}
return isIntoPoint;
}
private bool IsTrueWayWithBlock(Point playerPoint, Point creaturesPoint)
{
var zombi = new Zombi(creaturesPoint);
var player = new Player(playerPoint);
var isIntoPoint = false;
var glowingBalls = new List<GlowingBalls>();
for (var i = 0; i <20; i++)
{
var point = zombi.GetChangePosition(mapWithBlockInto, player, decorationObject, new ScreenPoint(new Point() { X = 0, Y = 0 }), glowingBalls);
if (IsPointIntoArea(playerPoint, point, 40))
{
isIntoPoint = true;
break;
}
}
return isIntoPoint;
}
private int MaxCountToObject(Point start, Point finish)
{
return Math.Abs(start.X - finish.X) / 5 + Math.Abs(start.Y - finish.Y) / 5 + 10;
}
private bool IsPointIntoArea(Point areaPoint, Point objectPoint, int sizeArea)
{
return Math.Abs(areaPoint.X - objectPoint.X) <= sizeArea
&& Math.Abs(objectPoint.Y - objectPoint.Y) <= sizeArea;
}
}
}