-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflyweight.cs
More file actions
63 lines (55 loc) · 1.38 KB
/
Copy pathflyweight.cs
File metadata and controls
63 lines (55 loc) · 1.38 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
59
60
61
62
63
using System.Collections;
using System.Collections.Generic;
public class Terrain
{
private int _numberOfTrees;
private int _movementCost;
private bool _impassable;
public Terrain(int trees, int cost, bool isImpassable)
{
_numberOfTrees = trees;
_movementCost = cost;
_impassable = isImpassable;
}
}
public class World
{
private Terrain[][] _worldTiles;
private Terrain _water;
private Terrain _mountains;
private Terrain _grass;
public World(File file)
{
_water = new Terrain(0, 0, true);
_mountain = new Terrain(2, 5, false);
_grass = new Terrain(10, 2,false);
LoadTilesFromFile(file);
}
private LoadTilesFromFile(File file)
{
_worldTiles = new Terrain[file.worldWidth][file.worldHeight]();
for(int i = 0; i < file.worldWidth; i++){
for(int j = 0; j < file.worldHeight; j++){
_worldTiles[i][j] = AssignTerrain(file.terrainData[i][j])
}
}
}
private Terrain AssignTerrain(int tag)
{
switch(tag)
{
case 1:
return _water;
case 2:
return _mountain;
default:
return _grass;
}
}
}
public class File
{
public int worldWidth;
public int worldHeight;
public int[][] terrainData;
}