コード例 #1
0
ファイル: LoadXml.cs プロジェクト: alibingol/King
 public static bool LoadDb(ciFramework frameW, ref XDocument ret, string file)
 {
     var fi = new System.IO.FileInfo(FullFileName(file));
     if (!fi.Exists)
     {
         return frameW.ErrorAdd(fi.FullName);
     }
     try
     {
         ret = XDocument.Load(fi.FullName);
     }
     catch (Exception ex)
     {
         return frameW.ErrorAdd(ex.Message);
     }
     return true;
 }
コード例 #2
0
ファイル: LoadXml.cs プロジェクト: alibingol/King
 public static bool FindTurnNode(ciFramework frameW, ref XElement nodeTurn, XElement nodeGame, int turnKey)
 {
     foreach (XElement lcNode in nodeGame.Element("turns").Descendants("turn"))
     {
         if (turnKey == Convert.ToInt16(lcNode.Attribute("key").Value))
         {
             nodeTurn = lcNode;
             return true;
         }
     }
     return frameW.ErrorAdd("Oyun Turu Yüklenemedi");
 }
コード例 #3
0
ファイル: LoadXml.cs プロジェクト: alibingol/King
 public static bool FindGameNode(ciFramework frameW, ref XElement nodeGame, XDocument games, short gameKey)
 {
     foreach (XElement lcNode in games.Element("games").Descendants("game"))
     {
         if (gameKey == Convert.ToInt16(lcNode.Attribute("key").Value))
         {
             nodeGame = lcNode;
             return true;
         }
     }
     return frameW.ErrorAdd("Oyun Yüklenemedi");
 }
コード例 #4
0
ファイル: Players.cs プロジェクト: alibingol/King
 public static bool PlayerSave(ciFramework frameW, csPlayer player)
 {
     if (string.IsNullOrEmpty(player.Name)) return frameW.ErrorAdd("İsim girilmeli");
     //
     csPlayers players = null;
     if (!Load(frameW, ref players)) return false;
     XDocument docPlayers = null;
     if (!King.Utils.LoadDb(frameW, ref docPlayers, "Players")) return false;
     player.Key =Convert.ToInt16( players.Count+1);
     var playNode = new XElement("player");
     playNode.Add(new XAttribute("id",player.Key));
     playNode.Add(new XAttribute("name", player.Name));
     docPlayers.Element("players").Add(playNode);
     King.Utils.SaveDb(docPlayers, "Players");
     return true;
 }
コード例 #5
0
ファイル: Games.cs プロジェクト: alibingol/King
        public static bool Add(ciFramework frameW, csGameList game)
        {
            if (game.Players == null || game.Players.Count != 4)
            {
                return frameW.ErrorAdd("4 oyuncu olmalı");
            }
            //
            var unks = new HashSet<int>();
            foreach (var player in game.Players)
            {
                if (player.Key == 0)
                {
                    return frameW.ErrorAdd("Bütün oyuncular seçilmeli");
                }
                unks.Add(player.Key);
            }
            if (unks.Count != 4) return frameW.ErrorAdd("Bir Oyuncu 2 defa seçilemez");
            csGames games = null;
            if (!Load(frameW, ref games)) return false;

            game.Key = Convert.ToInt16(games.Count + 1);
            XDocument docGames = null;
            if (!King.Utils.LoadDb(frameW, ref docGames, "Games")) return false;
            var nodeGames = docGames.Element("games");
            var nodeGame = new XElement("game");

            nodeGames.Add(nodeGame);
            game.Date = DateTime.Now.ToString("dd/MM/yy HH:mm");
            nodeGame.Add(new XAttribute("key", game.Key));
            nodeGame.Add(new XAttribute("date", game.Date));
            var nodePlayers = new XElement("players");
            nodeGame.Add(nodePlayers);
            foreach (var player in game.Players)
            {
                var nodePlayer = new XElement("player");
                nodePlayer.Add(new XAttribute("key", player.Key));
                //turnleri şimdi açmaya gerek yok(zaten yok da)
                nodePlayers.Add(nodePlayer);
            }
            King.Utils.SaveDb(docGames, "Games");
            return true;
        }
コード例 #6
0
ファイル: Games.cs プロジェクト: alibingol/King
        public static bool GameTurnSave(ciFramework frameW, short gameKey, csGameTurn turn)
        {
            // toplam el ile seçilen uyuyor mu diye bakalım
            var gameTypeDef = GameType(turn.Type);
            int totalMove = 0;
            foreach (var itemMove in turn.Moves)
            {
                totalMove += itemMove.Quantity;
            }
            if (totalMove != gameTypeDef.HowMany) return frameW.ErrorAdd("Toplam " + gameTypeDef.HowMany + " El Seçilmeli");
            //
            XDocument docGames = null;
            if (!King.Utils.LoadDb(frameW, ref docGames, "Games")) return false;
            XElement nodeGame = null;
            if (!King.Utils.FindGameNode(frameW, ref nodeGame, docGames, gameKey)) return false;
            //turns node
            var nodeTurns = nodeGame.Element("turns");
            if (nodeTurns == null)
            {
                nodeTurns = new XElement("turns");
                nodeGame.Add(nodeTurns);
            }
            // turn oluştur veya bul
            XElement nodeTurn = null;
            if (turn.Key == 0)
            {
                turn.Key = nodeTurns.Nodes().Count() + 1;
                nodeTurn = new XElement("turn");
                nodeTurn.Add(new XAttribute("key", turn.Key));
                nodeTurns.Add(nodeTurn);
            }
            else
            {
                if (!King.Utils.FindTurnNode(frameW, ref nodeTurn, nodeGame, turn.Key)) return false;
            }
            // update veya insert
            King.Utils.UpdateAttribute(nodeTurn, "player", Convert.ToString(turn.Player));
            King.Utils.UpdateAttribute(nodeTurn, "type", Convert.ToByte(turn.Type).ToString());
            King.Utils.UpdateAttribute(nodeTurn, "king", (turn.IsKing ? 1 : 0).ToString());
            //eski move varsa da silelim
            if (nodeTurn.Element("moves") != null) nodeTurn.Element("moves").Remove();
            //
            var nodeMoves = new XElement("moves");
            nodeTurn.Add(nodeMoves);
            foreach (var itemMove in turn.Moves)
            {
                if (itemMove.Quantity > 0)
                {
                    var nodeMove = new XElement("move");
                    nodeMoves.Add(nodeMove);
                    nodeMove.Add(new XAttribute("player", itemMove.Player.ToString()));
                    nodeMove.Add(new XAttribute("quantity", itemMove.Quantity.ToString()));
                }
            }

            King.Utils.SaveDb(docGames, "Games");
            return true;
        }