-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.cs
85 lines (77 loc) · 5.01 KB
/
Events.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
using System;
using SplashKitSDK;
namespace MyPathFinding
{
// This is a static event class that contains static methods that handles inputs from user.
public static class Events
{
// This is called when S key is pressesd.
public static void TestOnSKey(object sender, OnPathChangedEventArgs onPathChangedEventArgs)
{
PathFindingGUI pathFindingGUI = (PathFindingGUI)sender;
pathFindingGUI.StartX = onPathChangedEventArgs.pathFinding.GetGrid().GetColumnNumber(SplashKit.MousePosition());
pathFindingGUI.StartY = onPathChangedEventArgs.pathFinding.GetGrid().GetRowNumber(SplashKit.MousePosition());
if (onPathChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY) != null)
{
pathFindingGUI.pathNodes = onPathChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY);
}
onPathChangedEventArgs.pathFinding.GetGrid().PrintGrid();
}
// This is called when E key is pressesd.
public static void TestOnEKey(object sender, OnPathChangedEventArgs onPathChangedEventArgs)
{
PathFindingGUI pathFindingGUI = (PathFindingGUI)sender;
pathFindingGUI.EndX = onPathChangedEventArgs.pathFinding.GetGrid().GetColumnNumber(SplashKit.MousePosition());
pathFindingGUI.EndY = onPathChangedEventArgs.pathFinding.GetGrid().GetRowNumber(SplashKit.MousePosition());
if (onPathChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY) != null)
{
pathFindingGUI.pathNodes = onPathChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY);
}
onPathChangedEventArgs.pathFinding.GetGrid().PrintGrid();
}
// This is called when W key is pressesd.
public static void TestOnWKey(object sender, OnWallChangedEventArgs onWallChangedEventArgs)
{
PathFindingGUI pathFindingGUI = (PathFindingGUI)sender;
onWallChangedEventArgs.pathFinding.GetGrid().GetRowColumnNumber(SplashKit.MousePosition(), out double x, out double y);
if (onWallChangedEventArgs.pathFinding.GetGrid().GetValue(SplashKit.MousePosition()) != null)
{
if (!onWallChangedEventArgs.pathFinding.GetGrid().GetValue(SplashKit.MousePosition()).IsWalkAble)
{
onWallChangedEventArgs.wallManagement.RemoveWall(Convert.ToInt32(x), Convert.ToInt32(y));
pathFindingGUI.pathNodes = onWallChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY);
Util.FillSquare(Color.White, Convert.ToInt32(x), Convert.ToInt32(y), pathFindingGUI.CellSize);
}
else
{
onWallChangedEventArgs.wallManagement.MakeWall(Convert.ToInt32(x), Convert.ToInt32(y));
pathFindingGUI.pathNodes = onWallChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY);
Util.FillSquare(Color.Black, Convert.ToInt32(x), Convert.ToInt32(y), pathFindingGUI.CellSize);
}
}
}
// This is called when Space key is pressesd.
public static void TestOnSpace(object sender, OnPathChangedEventArgs onPathChangedEventArgs)
{
PathFindingGUI pathFindingGUI = (PathFindingGUI)sender;
if (onPathChangedEventArgs.pathFinding != null)
{
for (int i = 1; i < onPathChangedEventArgs.pathFinding.GetVisitedPath().Count; i++)
{
PathNode searchNode = onPathChangedEventArgs.pathFinding.GetVisitedPath()[i];
SplashKit.FillRectangle(Color.LightBlue, searchNode.X * pathFindingGUI.CellSize + 2, searchNode.Y * pathFindingGUI.CellSize + 2, pathFindingGUI.CellSize - 2, pathFindingGUI.CellSize - 2);
if (i % 5 == 0) pathFindingGUI.window.Refresh(60);
}
// If there is no path found, return.
if(pathFindingGUI.pathNodes == null) return;
for (int i = 1; i < pathFindingGUI.pathNodes.Count - 1; i++)
{
// Color Green, x is axis of pathNodes[i] in grid * cellSize, y is thr ordinate location of pathNodes[i] in grid * cellSize, with and height = cellSize
Util.FillSquare(Color.Yellow, pathFindingGUI.pathNodes[i].X, pathFindingGUI.pathNodes[i].Y, pathFindingGUI.CellSize);
pathFindingGUI.window.Refresh(60);
}
SplashKit.Delay(5000);
}
}
}
}