Guest User

Untitled

a guest
Apr 16th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web.Script.Serialization;
  4.  
  5.  
  6. public class Board
  7. {
  8. private int mSize_x, mSize_y;
  9. private List<List<int>> mBackBoard;
  10. private List<List<int>> mFrontBoard;
  11. private List<List<int>> mEnemyBoard;
  12.  
  13. public List<List<int>> BackBoard
  14. {
  15. get { return mBackBoard; }
  16. }
  17.  
  18. public List<List<int>> FrontBoard
  19. {
  20. get { return mFrontBoard; }
  21. }
  22.  
  23. public List<List<int>> EnemyBoard
  24. {
  25. get { return mFrontBoard; }
  26. }
  27.  
  28.  
  29.  
  30. public Board(int x, int y)
  31. {
  32. mSize_x = x;
  33. mSize_y = y;
  34. InitializeBoards(x, y);
  35. GenerateBoard();
  36. }
  37.  
  38. public void AssignToBack(int x, int y, int value)
  39. {
  40. mBackBoard[x][y] = value;
  41. }
  42.  
  43. public void AssignToFront(int x, int y, int value)
  44. {
  45. mFrontBoard[x][y] = value;
  46. }
  47.  
  48. public void AssignToEnemy(int x, int y, int value)
  49. {
  50. mEnemyBoard[x][y] = value;
  51. }
  52.  
  53. private void GenerateBoard()
  54. {
  55. Random random = new Random();
  56. for (int xIndex = 0; xIndex < mSize_x ; xIndex++)
  57. {
  58. for (int yIndex = 0; yIndex < mSize_y ; yIndex++)
  59. {
  60. mBackBoard[xIndex].Add(random.Next(0, 5));
  61. mFrontBoard[xIndex].Add(random.Next(0, 5));
  62. mEnemyBoard[xIndex].Add(random.Next(0, 5));
  63. }
  64. }
  65. }
  66.  
  67. private void InitializeBoards(int x, int y)
  68. {
  69. InitializeBackBoard();
  70. InitializeFrontBoard();
  71. InitializeEnemyBoard();
  72. }
  73.  
  74. private void InitializeBackBoard()
  75. {
  76. mBackBoard = new List<List<int>>();
  77. for (int indexY = 0 ; indexY < mSize_y; indexY++)
  78. {
  79. List<int> subList = new List<int>();
  80. mBackBoard.Add(subList);
  81. }
  82. }
  83.  
  84. private void InitializeFrontBoard()
  85. {
  86. mFrontBoard = new List<List<int>>();
  87. for (int indexY = 0; indexY < mSize_y; indexY++)
  88. {
  89. List<int> subList = new List<int>();
  90. mFrontBoard.Add(subList);
  91. }
  92.  
  93. }
  94.  
  95. private void InitializeEnemyBoard()
  96. {
  97. mEnemyBoard = new List<List<int>>();
  98. for (int indexY = 0; indexY < mSize_y; indexY++)
  99. {
  100. List<int> subList = new List<int>();
  101. mEnemyBoard.Add(subList);
  102. }
  103. }
  104.  
  105. }
  106.  
  107. public class ExportMap
  108. {
  109. private Board mBoard;
  110.  
  111. public ExportMap(Board board)
  112. {
  113. mBoard = board;
  114. }
  115.  
  116. public void Export()
  117. {
  118. var json = new JavaScriptSerializer().Serialize(mBoard);
  119. System.IO.File.WriteAllText (@".\map.json", json);
  120. Console.WriteLine(json);
  121. }
  122. }
  123. class Program
  124. {
  125. static void Main()
  126. {
  127. Board board = new Board(8, 8);
  128. ExportMap exportMap = new ExportMap(board);
  129. exportMap.Export();
  130.  
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment