Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Web.Script.Serialization;
- public class Board
- {
- private int mSize_x, mSize_y;
- private List<List<int>> mBackBoard;
- private List<List<int>> mFrontBoard;
- private List<List<int>> mEnemyBoard;
- public List<List<int>> BackBoard
- {
- get { return mBackBoard; }
- }
- public List<List<int>> FrontBoard
- {
- get { return mFrontBoard; }
- }
- public List<List<int>> EnemyBoard
- {
- get { return mFrontBoard; }
- }
- public Board(int x, int y)
- {
- mSize_x = x;
- mSize_y = y;
- InitializeBoards(x, y);
- GenerateBoard();
- }
- public void AssignToBack(int x, int y, int value)
- {
- mBackBoard[x][y] = value;
- }
- public void AssignToFront(int x, int y, int value)
- {
- mFrontBoard[x][y] = value;
- }
- public void AssignToEnemy(int x, int y, int value)
- {
- mEnemyBoard[x][y] = value;
- }
- private void GenerateBoard()
- {
- Random random = new Random();
- for (int xIndex = 0; xIndex < mSize_x ; xIndex++)
- {
- for (int yIndex = 0; yIndex < mSize_y ; yIndex++)
- {
- mBackBoard[xIndex].Add(random.Next(0, 5));
- mFrontBoard[xIndex].Add(random.Next(0, 5));
- mEnemyBoard[xIndex].Add(random.Next(0, 5));
- }
- }
- }
- private void InitializeBoards(int x, int y)
- {
- InitializeBackBoard();
- InitializeFrontBoard();
- InitializeEnemyBoard();
- }
- private void InitializeBackBoard()
- {
- mBackBoard = new List<List<int>>();
- for (int indexY = 0 ; indexY < mSize_y; indexY++)
- {
- List<int> subList = new List<int>();
- mBackBoard.Add(subList);
- }
- }
- private void InitializeFrontBoard()
- {
- mFrontBoard = new List<List<int>>();
- for (int indexY = 0; indexY < mSize_y; indexY++)
- {
- List<int> subList = new List<int>();
- mFrontBoard.Add(subList);
- }
- }
- private void InitializeEnemyBoard()
- {
- mEnemyBoard = new List<List<int>>();
- for (int indexY = 0; indexY < mSize_y; indexY++)
- {
- List<int> subList = new List<int>();
- mEnemyBoard.Add(subList);
- }
- }
- }
- public class ExportMap
- {
- private Board mBoard;
- public ExportMap(Board board)
- {
- mBoard = board;
- }
- public void Export()
- {
- var json = new JavaScriptSerializer().Serialize(mBoard);
- System.IO.File.WriteAllText (@".\map.json", json);
- Console.WriteLine(json);
- }
- }
- class Program
- {
- static void Main()
- {
- Board board = new Board(8, 8);
- ExportMap exportMap = new ExportMap(board);
- exportMap.Export();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment