Guest User

Untitled

a guest
Apr 16th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web.Script.Serialization;
  4.  
  5. public class BoardObjects
  6. {
  7. public BoardObjects(int background, int foreground, int enemyground)
  8. {
  9. this.background = background;
  10. this.foreground = foreground;
  11. this.enemyground = enemyground;
  12. }
  13. public int background;
  14. public int foreground;
  15. public int enemyground;
  16. }
  17.  
  18. public class Board
  19. {
  20. private int mSize_x, mSize_y;
  21. private List<List<BoardObjects>> mBoard;
  22.  
  23. public List<List<BoardObjects>> BackBoard
  24. {
  25. get { return mBoard; }
  26. }
  27.  
  28. public Board(int x, int y)
  29. {
  30. mSize_x = x;
  31. mSize_y = y;
  32. InitializeBoard();
  33. GenerateBoard();
  34. }
  35.  
  36. private void GenerateBoard()
  37. {
  38. Random random = new Random();
  39. for (int xIndex = 0; xIndex < mSize_x ; xIndex++)
  40. {
  41. for (int yIndex = 0; yIndex < mSize_y ; yIndex++)
  42. {
  43. mBoard[xIndex].Add(new BoardObjects(random.Next(0, 5), random.Next(0, 5), random.Next(0, 5)));
  44. }
  45. }
  46. }
  47.  
  48. private void InitializeBoard()
  49. {
  50. mBoard = new List<List<BoardObjects>>();
  51. for (int indexY = 0; indexY < mSize_y; indexY++)
  52. {
  53. List<BoardObjects> subList = new List<BoardObjects>();
  54. mBoard.Add(subList);
  55. }
  56. }
  57. }
  58.  
  59. public class ExportMap
  60. {
  61. private Board mBoard;
  62.  
  63. public ExportMap(Board board)
  64. {
  65. mBoard = board;
  66. }
  67.  
  68. public void Export()
  69. {
  70. var json = new JavaScriptSerializer().Serialize(mBoard);
  71. System.IO.File.WriteAllText (@".\map.json", json);
  72. Console.WriteLine(json);
  73. }
  74. }
  75. class Program
  76. {
  77. static void Main()
  78. {
  79. Board board = new Board(8, 8);
  80. ExportMap exportMap = new ExportMap(board);
  81. exportMap.Export();
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment