-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel.cs
46 lines (42 loc) · 1.19 KB
/
Level.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pacman
{
public class Level
{
public Keys KeyPressed { get; set; }
public string Name;
public ICreature[,] Map { get; set; }
public static readonly int MapWidth = 30;
public static readonly int MapHeight = 15;
public readonly int NumberOfCoins;
private readonly Func<Level,ICreature[,]> init;
public Level(string name, Func<Level,ICreature[,]> init)
{
this.init = init;
Map = init(this);
Name = name;
NumberOfCoins = CountCoins(Map);
}
public static int CountCoins(ICreature[,] map)
{
var count = 0;
for (var i = 0; i < Level.MapWidth; i++)
for (var j = 0; j < Level.MapHeight; j++)
if (map[i, j] is Coin)
count++;
return count;
}
public void Reset()
{
Map = init(this);
}
}
}