/
Playground.cs
101 lines (86 loc) · 2.22 KB
/
Playground.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using BlockDefender.Terrain;
using Microsoft.Xna.Framework;
using System.Collections.ObjectModel;
namespace BlockDefender
{
class Playground
{
private Map Map;
private List<Player> PlayerList;
public IEnumerable<Player> Players
{
get
{
return new ReadOnlyCollection<Player>(PlayerList);
}
}
public int ColumnCount
{
get
{
return Map.ColumnCount;
}
}
public int RowCount
{
get
{
return Map.RowCount;
}
}
public Playground(Map map)
{
Map = map;
PlayerList = new List<Player>();
}
public void Load(ContentManager Content)
{
foreach (var field in Map.Fields)
{
field.Load(Content);
}
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (var field in Map.Fields)
{
field.Draw(spriteBatch);
}
foreach (var player in PlayerList)
{
player.Draw(spriteBatch);
}
}
public Player SpawnNextPlayer()
{
return SpawnPlayerAt(Map.Fields[0, new Random().Next(Map.RowCount)].Center);
}
public Player SpawnPlayerAt(Vector2 position)
{
int nextId = 0;
if(PlayerList.Count > 0)
nextId = PlayerList.Max(player => player.Id) + 1;
var p = new Player(nextId, this, position);
AddPlayer(p);
return p;
}
public void AddPlayer(Player p)
{
PlayerList.Add(p);
}
public Field FieldAt(int column, int row)
{
return Map.FieldAt(column, row);
}
public void replaceFieldAt(int column, int row, Field field)
{
Map.Fields[column, row] = field;
}
}
}