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 BoardObjects
- {
- public BoardObjects(int background, int foreground, int enemyground)
- {
- this.background = background;
- this.foreground = foreground;
- this.enemyground = enemyground;
- }
- public int background;
- public int foreground;
- public int enemyground;
- }
- public class Board
- {
- private int mSize_x, mSize_y;
- private List<List<BoardObjects>> mBoard;
- public List<List<BoardObjects>> BackBoard
- {
- get { return mBoard; }
- }
- public Board(int x, int y)
- {
- mSize_x = x;
- mSize_y = y;
- InitializeBoard();
- GenerateBoard();
- }
- private void GenerateBoard()
- {
- Random random = new Random();
- for (int xIndex = 0; xIndex < mSize_x ; xIndex++)
- {
- for (int yIndex = 0; yIndex < mSize_y ; yIndex++)
- {
- mBoard[xIndex].Add(new BoardObjects(random.Next(0, 5), random.Next(0, 5), random.Next(0, 5)));
- }
- }
- }
- private void InitializeBoard()
- {
- mBoard = new List<List<BoardObjects>>();
- for (int indexY = 0; indexY < mSize_y; indexY++)
- {
- List<BoardObjects> subList = new List<BoardObjects>();
- mBoard.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