- Timestamp:
- 2011-12-27 04:21:28 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/hniemi/BlockPusher/Blockpusher/Blockpusher/BlockLevel.cs
r2634 r2635 14 14 private Block[,] playfield; 15 15 private Blockpusher game; 16 private Dictionary<char, BlockType> charColor = new Dictionary<char, BlockType>();16 private List<Tuple<char, BlockType>> charcolors = new List<Tuple<char, BlockType>>(); 17 17 private List<Block> goals = new List<Block>(); 18 18 … … 33 33 34 34 /// <summary> 35 /// Name of the level 36 /// </summary> 37 public string Name { get; set; } 38 39 /// <summary> 35 40 /// Constructor from game 36 41 /// </summary> … … 40 45 this.game = game; 41 46 InitCharColors(); 47 } 48 49 /// <summary> 50 /// Adds blocks to game 51 /// </summary> 52 public void AddToGame() 53 { 54 game.Level.Size = new Vector(playfield.GetLength(0) * (Blockpusher.BlockSize + 1), playfield.GetLength(1) * (Blockpusher.BlockSize + 1)); 55 game.Level.CreateBorders(); 56 for (int i = 0; i < playfield.GetLength(0); i++) 57 { 58 for (int j = 0; j < playfield.GetLength(1); j++) 59 { 60 61 playfield[i, j].X = i * (Blockpusher.BlockSize + 1) + game.Level.Left + (Blockpusher.BlockSize / 2); 62 playfield[i, j].Y = -(j * (Blockpusher.BlockSize + 1) + game.Level.Bottom + (Blockpusher.BlockSize / 2)); 63 game.Add(playfield[i,j]); 64 } 65 } 42 66 } 43 67 … … 142 166 public void InitCharColors() 143 167 { 144 charColor.Add('x', BlockType.UnMovable); 145 charColor.Add('b', BlockType.Movable); 146 charColor.Add(' ', BlockType.Empty); 147 charColor.Add('m', BlockType.GoalZone); 148 charColor.Add('p', BlockType.Player); 149 charColor.Add('s', BlockType.SatisfiedGoalZone); 168 charcolors.Add(new Tuple<char, BlockType>('x', BlockType.UnMovable)); 169 charcolors.Add(new Tuple<char, BlockType>('b', BlockType.Movable)); 170 charcolors.Add(new Tuple<char, BlockType>(' ', BlockType.Empty)); 171 charcolors.Add(new Tuple<char, BlockType>('m', BlockType.GoalZone)); 172 charcolors.Add(new Tuple<char, BlockType>('p', BlockType.Player)); 173 charcolors.Add(new Tuple<char, BlockType>('s', BlockType.SatisfiedGoalZone)); 174 } 175 176 /// <summary> 177 /// Finds char matching type. 178 /// If not found, return ' ' 179 /// </summary> 180 /// <param name="type">Type you want to find</param> 181 /// <returns>Matching char</returns> 182 public char FindChar(BlockType type) 183 { 184 foreach (var item in charcolors) 185 { 186 if (item.Item2 == type) return item.Item1; 187 } 188 return ' '; 189 } 190 191 /// <summary> 192 /// Finds Blocktype matching char. 193 /// If not found, BlockType.Empty is returned. 194 /// </summary> 195 /// <param name="c">Char you want to find</param> 196 /// <returns>Matching type</returns> 197 public BlockType FindBlockType(char c) 198 { 199 foreach (var item in charcolors) 200 { 201 if (item.Item1 == c) return item.Item2; 202 } 203 return BlockType.Empty; 150 204 } 151 205 … … 160 214 161 215 playfield = new Block[playfieldWidth, playfieldHeight]; 162 game.Level.Size = new Vector(playfieldWidth * (Blockpusher.BlockSize + 1), playfieldHeight * (Blockpusher.BlockSize + 1));163 game.Level.CreateBorders();164 216 165 217 for (int i = 0; i < playfield.GetLength(0); i++) … … 171 223 block.Y = -(j * (Blockpusher.BlockSize + 1) + game.Level.Bottom + (Blockpusher.BlockSize / 2)); 172 224 173 block.Type = charColor[level[j][i]];225 block.Type = FindBlockType(level[j][i]); 174 226 if (block.Type == BlockType.Player) 175 227 { … … 181 233 goals.Add(block); 182 234 } 183 game.Add(block);184 235 playfield[i, j] = block; 185 236 } … … 207 258 208 259 /// <summary> 260 /// Returns the current state of level. 261 /// </summary> 262 /// <returns></returns> 263 public List<string> CurrentState() 264 { 265 List<string> list = new List<string>(); 266 267 for (int i = 0; i < playfield.GetLength(1); i++) 268 { 269 StringBuilder line = new StringBuilder(); 270 for (int j = 0; j < playfield.GetLength(0); j++) 271 { 272 273 line.Append(FindChar(playfield[j,i].Type)); 274 } 275 list.Add(line.ToString()); 276 } 277 278 return list; 279 } 280 281 /// <summary> 209 282 /// Changes color of players coordinates 210 283 /// </summary>
Note: See TracChangeset
for help on using the changeset viewer.