Ejemplo n.º 1
0
        private static XElement CreateSave(GameRecreation recreation)
        {
            var save = new XElement("game",
                new XAttribute("mode", recreation.GameMode),
                new XAttribute("isRedHuman", recreation.IsRedHuman),
                new XElement("board", from point in recreation.Board.Points
                    select new XElement("point",
                                new XAttribute("checkers", (point == null) ? 0 : point.CheckersAmount),
                                new XAttribute("color", (point == null) ?  GameColor.None : point.CheckersColor)),
                            new XElement("bar",
                                new XAttribute("checkers", recreation.Board.EatenChekers(GameColor.White)),
                                new XAttribute("color", GameColor.White)),
                                new XElement("bar",
                                    new XAttribute("checkers", recreation.Board.EatenChekers(GameColor.Red)),
                                    new XAttribute("color", GameColor.Red))),
            new XElement("turn",
                new XAttribute("color", recreation.CurrentColor),
                new XElement("moves", from move in recreation.CurrentTurn.PossibleMoves
                                           select new XElement("move",
                                               new XAttribute("size", move))),
                                               new XElement("dice",
                                                   new XAttribute("result1", recreation.CurrentTurn.DiceResult1),
                                                   new XAttribute("result2", recreation.CurrentTurn.DiceResult2))));

            return save;
        }
Ejemplo n.º 2
0
        internal static void SaveGame(GameRecreation recreation)
        {
            var currentDirectory = Environment.CurrentDirectory;
            var savePath = currentDirectory.Replace(@"\BackgammonView\bin\Debug", @"\BackgammonController") + @"\save.xml";

            var save = CreateSave(recreation);

            save.Save(savePath);
        }
Ejemplo n.º 3
0
        internal static GameRecreation RecreateGame()
        {
            _recreation = new GameRecreation();

            var currentDirectory = Environment.CurrentDirectory;
            var savePath = currentDirectory.Replace(@"\BackgammonView\bin\Debug", @"\BackgammonController") + @"\save.xml";

            var save = XDocument.Load(savePath);

            RecreateTurn(save);
            RecreateBoard(save);
            RecreateCurrentColor(save);
            RecreateGameMode(save);
            RecreateComputer(save);

            return _recreation;
        }