示例#1
0
        public static void ReadBoard(string path, string jsonPath)
        {
            Excel.Application xlApp       = new Excel.Application();
            Excel.Workbook    xlWorkBook  = xlApp.Workbooks.Open(string.Format(@"{0}\{1}", Environment.CurrentDirectory, path));
            Excel._Worksheet  xlWorksheet = xlWorkBook.Sheets[1];
            Excel.Range       xlRange     = xlWorksheet.UsedRange;

            var BoardJson = new BoardJson();

            Node[,] boardNodes = new Node[50, 50];
            for (int i = 6; i < 56; i++)
            {
                for (int column = 1; column < 51; column++)
                {
                    boardNodes[i - 6, column - 1] = new Node();
                    CreateBoardNode(i - 6, column - 1, xlRange.Cells[i, column].Value2.ToString(), "Prefabs/wall.txt", "Prefabs/pickup.txt", "Prefabs/powerup.txt", boardNodes[i - 6, column - 1], BoardJson);
                }
            }

            BoardJson.AllBoardNodes = boardNodes;

            xlWorkBook.Close(0);
            xlApp.Quit();

            JsonSerializerSettings set = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects
            };

            string json = JsonConvert.SerializeObject(BoardJson, set);

            File.WriteAllText(jsonPath, json);
        }
示例#2
0
        private bool HandleNonColumnInput(ConsoleKeyInfo key)
        {
            if (key.Key == ConsoleKey.S)
            {
                Console.WriteLine();
                Console.WriteLine("Enter Name to Save: ");
                var name = Console.ReadLine();
                board.Name = name;
                BoardJson.Serialize(board);
                return(true);
            }

            if (key.Key == ConsoleKey.L)
            {
                Console.WriteLine();
                Console.WriteLine("Enter Name to Load: ");
                var name = Console.ReadLine();
                board.Name = name;
                board      = BoardJson.Deserialize(name);
                return(true);
            }


            Console.BackgroundColor = ConsoleColor.Red;
            Console.WriteLine();
            Console.WriteLine($"Invalid column. Press any key");
            Console.ReadLine();
            return(true);
        }
 public ActionResult <BoardJson> Get()
 {
     using (StreamReader r = new StreamReader(@"C:\Users\Oliver\source\repos\ManagR\ManagR\board.json"))
     {
         string json      = r.ReadToEnd();
         var    boardJson = BoardJson.FromJson(json);
         return(boardJson);
     }
 }
示例#4
0
 public Board(String boardString)
 {
     using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(boardString)))
     {
         DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(BoardJson));
         ParsedBoard = (BoardJson)deserializer.ReadObject(ms);
         ParsedBoard.field.Replace("\n", "");
         LengthXY = new LengthToXY(Size);
     }
 }
示例#5
0
        public static void SetBoard(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            FileStream fin = File.OpenRead(path);

            BoardJson boardJSON = null;

            using (StreamReader r = new StreamReader(fin))
            {
                JsonSerializerSettings set = new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.Objects
                };

                string json = r.ReadToEnd();
                boardJSON = JsonConvert.DeserializeObject <BoardJson>(json, set);

                BoardCalculateNeighbour(boardJSON.AllBoardNodes);

                GameManager.Instance.SetSpawnPoint(boardJSON.Spawn);
                GameManager.Instance.SetupPickupBoard(boardJSON.TotalItems);


                var exit   = boardJSON.AllBoardNodes[boardJSON.GhostSpawnExit[0], boardJSON.GhostSpawnExit[1]];
                var spawns = new List <Node>();

                foreach (var a in boardJSON.GhostSpawnPoints)
                {
                    spawns.Add(boardJSON.AllBoardNodes[a[0], a[1]]);
                }

                AIManager.Instance.SetGhostSpawn(exit, spawns);

                foreach (var item in boardJSON.EntityInScene)
                {
                    item.SetPrefab();
                    EntityManager.Instance.AddEntity(item);
                }
            }
        }
示例#6
0
        public List <BoardJson> GetBoardByGame(long idGame)
        {
            // normaly : list of 2 items
            var boards = _context.Boards.Where(board => board.IdGame == idGame).ToList();

            BoardJson boardState1 = new BoardJson(boards.First(), _celluleController.GetCellulesByBoard(boards.First().Id));

            // remove first item to take the new second item
            boards.RemoveAt(0);
            BoardJson boardState2 = new BoardJson(boards.First(), _celluleController.GetCellulesByBoard(boards.First().Id));

            List <BoardJson> boardStates = new List <BoardJson>
            {
                boardState1,
                boardState2
            };

            return(boardStates);
        }
示例#7
0
        public JsonResult LoadBoard()
        {
            BoardJson boardVM      = null;
            var       responseTask = client.GetAsync("Board");

            responseTask.Wait();
            var result = responseTask.Result;

            if (result.IsSuccessStatusCode)
            {
                var json = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result).ToString();
                boardVM = JsonConvert.DeserializeObject <BoardJson>(json);
            }
            else
            {
                ModelState.AddModelError(string.Empty, "server error, try after some time");
            }
            return(Json(boardVM));
        }
示例#8
0
        static void CreateBoardNode(int row, int column, string nodeString, string wallName, string pickupName, string powerupName, Node currentNode, BoardJson board)
        {
            if (nodeString == "x")
            {
                Entity wall = EntityManager.Instance.SpawnPrefab(wallName);
                wall.Transform.Position = new Vector3(row, 0, column);

                board.EntityInScene.Add(wall);

                currentNode.Position = wall.Transform.Position;
                currentNode.Walkable = false;
            }

            else if (nodeString == "o")
            {
                Entity node = EntityManager.Instance.SpawnPrefab(pickupName);
                node.Transform.Position = new Vector3(row, 0.4f, column);

                board.EntityInScene.Add(node);

                currentNode.Position = new Vector3(row, 0, column);
                currentNode.Walkable = true;

                board.TotalItems++;
            }

            else if (nodeString == "g")
            {
                //Ghost Spawn
                currentNode.Position = new Vector3(row, 0, column);
                currentNode.Walkable = false;

                board.GhostSpawnExit[0] = row;
                board.GhostSpawnExit[1] = column;
            }

            else if (nodeString == "s")
            {
                //Player SPawn
                currentNode.Position = new Vector3(row, 0, column);
                currentNode.Walkable = true;

                board.Spawn = new Vector3(row, 0, column);
            }

            else if (nodeString == "p")
            {
                //Power Up Spawn
                Entity node = EntityManager.Instance.SpawnPrefab(powerupName);
                node.Transform.Position = new Vector3(row, 0.4f, column);

                board.EntityInScene.Add(node);

                currentNode.Position = new Vector3(row, 0, column);
                currentNode.Walkable = true;

                board.TotalItems++;
            }
            else if (nodeString == "k")
            {
                currentNode.Position = new Vector3(row, 0, column);
                currentNode.Walkable = false;

                var pos = new int[2];
                pos[0] = row;
                pos[1] = column;

                board.GhostSpawnPoints.Add(pos);
            }

            else
            {
                currentNode.Position = new Vector3(row, 0, column);
                currentNode.Walkable = false;
            }
        }