/
Map.cs
146 lines (109 loc) · 3.31 KB
/
Map.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace TankWar
{
public class Map
{
Texture2D eagleSprite;
Rectangle eagleRectangle;
public List<Cube> Cubes=new List<Cube>();
List<Cube> walls=new List<Cube>();
List<Cube> grasses=new List<Cube>();
List<Cube> waters=new List<Cube>();
List<Cube> irons=new List<Cube>();
int wallNum;
int ironNum;
int grassNum;
int waterNum;
//public int [] cubesLocation{ get; }
//get should be deleted
int[,] wallsLocation;
int[,] grassesLocation;
int[,] watersLocation;
int[,] ironsLocation;
WallCube cubeTest;
public Rectangle Home{
get { return eagleRectangle;}
}
#region Constructors
public Map (ContentManager content,Random rand)
{
//random map
}
public Map(ContentManager content){
//default map
//walls
walls = new List<Cube> ();
wallsLocation =ArrayDimension(MapLayout1.WallCubesLocation) ;
for (int i=0; i<wallsLocation.GetLength(0); i++) {
walls.Add (new WallCube (content, wallsLocation [i, 0], wallsLocation [i, 1]));
}
//grass
grasses = new List<Cube> ();
grassesLocation = ArrayDimension (MapLayout1.GrassCubesLocation);
for (int i=0; i<grassesLocation.GetLength(0); i++) {
grasses.Add (new GrassCube (content, grassesLocation [i, 0], wallsLocation [i, 1]));
}
//and iron grass water
irons = new List<Cube> ();
ironsLocation = ArrayDimension (MapLayout1.IronCubesLocation);
for (int i=0; i<ironsLocation.GetLength(0); i++) {
irons.Add (new IronCube (content, ironsLocation [i, 0], ironsLocation [i, 1]));
}
waters = new List<Cube> ();
watersLocation = ArrayDimension (MapLayout1.WaterCubesLocation);
for (int i=0; i<watersLocation.GetLength(0); i++) {
waters.Add (new WaterCube (content, watersLocation [i, 0], watersLocation [i, 1]));
}
//set cubes list
// add home firstly
Cubes.Add(new EagleCube(content,GameConstants.EAGLE_X, GameConstants.WIN_HEIGHT-40));
Cubes.AddRange (walls);
Cubes.AddRange (grasses);
Cubes.AddRange (irons);
Cubes.AddRange (waters);
}
public Map (ContentManager content,int wallNum, int ironNum, int grassNum, int waterNum){
this.wallNum = wallNum;
this.ironNum = ironNum;
this.grassNum = grassNum;
this.waterNum = waterNum;
}
#endregion
#region Method
public void Draw(SpriteBatch spriteBatch){
//spriteBatch.Draw (eagleSprite, eagleRectangle, Color.White);
foreach (Cube cube in Cubes) {
cube.Draw (spriteBatch);
}
}
public void Update(GameTime gameTime){
}
/// <summary>
/// Arraies the dimension. Change a 1 dimension array to 2 dimensions
/// </summary>
/// <returns>The dimension.</returns>
/// <param name="arr1">Arr1.</param>
public int[,] ArrayDimension(int[] arr1){
//set a temp 2 dimensions array
int [,] arr2=new int[arr1.Length/2,2];
//set j value to show the 2 dimensions array
int j = 0;
//use for loop to change 1 dimension array to 2 dimensions array
for (int i=0;i<arr1.Length-1;i+=2) {
arr2 [j, 0] = arr1 [i];
arr2 [j, 1] = arr1 [i+1];
j++;
}
return arr2;
}
#endregion
}
}