-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMazeExplorer_ProgramClass
More file actions
58 lines (53 loc) · 1.55 KB
/
MazeExplorer_ProgramClass
File metadata and controls
58 lines (53 loc) · 1.55 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace InClassThursNov21_01
{
class Program
{
private Maze maze = new Maze(1);
public Hero curby = new Hero();
public void Play()
{
while (true)
{
Console.Clear();
maze.Draw(curby);
MoveHero();
}
}
public void MoveHero()
{
ConsoleKeyInfo readKey = Console.ReadKey(true);
if (readKey.Key == ConsoleKey.RightArrow && maze.PointIsFree(curby.GetX() + 1, curby.GetY()))
{
curby.MoveRight();
maze.moves += 1;
}
else if (readKey.Key == ConsoleKey.LeftArrow && maze.PointIsFree(curby.GetX() - 1, curby.GetY()))
{
curby.MoveLeft();
maze.moves += 1;
}
else if (readKey.Key == ConsoleKey.UpArrow && maze.PointIsFree(curby.GetX(), curby.GetY() - 1))
{
curby.MoveUp();
maze.moves += 1;
}
else if (readKey.Key == ConsoleKey.DownArrow && maze.PointIsFree(curby.GetX(), curby.GetY() + 1))
{
curby.MoveDown();
maze.moves += 1;
}
}
static void Main(string[] args)
{
Program thisProgram = new Program();
thisProgram.Play();
Console.ReadLine();
}
}
}