コード例 #1
0
ファイル: Games.cs プロジェクト: alibingol/King
        /// <summary>Oyunu Komple Yükler ve de bazı verileri de pratiklik olsun diye set eder</summary>
        public static bool GameView(ciFramework frameW, csGameView game, short key)
        {
            csPlayers players = null;
            if (!King.UtilPlayers.Load(frameW, ref players)) return false;
            XDocument docGames = null;
            if (!King.Utils.LoadDb(frameW, ref docGames, "Games")) return false;
            XElement nodeGame = null;
            if (!King.Utils.FindGameNode(frameW, ref nodeGame, docGames, key)) return false;
            //
            game.Key = key;
            game.Date = Convert.ToString(nodeGame.Attribute("date").Value);

            game.IsKing = nodeGame.Attribute("king") != null && nodeGame.Attribute("king").Value == "1";
            // Players                    
            foreach (XElement nodePlayer in nodeGame.Element("players").Descendants("player"))
            {
                var player = new csGamePlayer();// 
                player.Key = Convert.ToInt16(nodePlayer.Attribute("key").Value);
                player.Name = players.FirstOrDefault(f => f.Key == player.Key).Name;
                game.Players.Add(player);
                //
            }
            // oynanan turnler
            var nodeTurns = nodeGame.Element("turns");
            if (nodeTurns != null)
            {
                foreach (XElement nodeTurn in nodeTurns.Descendants("turn"))
                {
                    var turn = new csGameTurn();// 
                    turn.Key = Convert.ToInt16(nodeTurn.Attribute("key").Value);
                    turn.Type = (enmGameType)Convert.ToByte(nodeTurn.Attribute("type").Value);
                    turn.Player = Convert.ToInt16(nodeTurn.Attribute("player").Value);
                    turn.IsKing = nodeTurn.Attribute("king") != null && nodeTurn.Attribute("king").Value == "1";

                    // kimler almış elleri
                    foreach (XElement nodeMove in nodeTurn.Element("moves").Descendants("move"))
                    {
                        var move = new csGameTurn.csGameMove();// 
                        move.Player = Convert.ToInt16(nodeMove.Attribute("player").Value);
                        move.Quantity = Convert.ToByte(nodeMove.Attribute("quantity").Value);
                        turn.Moves.Add(move);
                        //
                    }
                    game.Turns.Add(turn);
                    //
                }
            }
            // olası OyunTiplerini de ekleyelim
            var gameTypes = GameTypes();
            foreach (var gameType in gameTypes)
            {
                game.AvailTurns.Add(new csAvailTurn { GameType = gameType });
            }

            // oynanmış turnlerden data bulalım
            foreach (var turn in game.Turns)
            {
                var gameType = game.AvailTurns.FirstOrDefault(f => f.GameType.Key == turn.Type);
                gameType.Played += 1;
                // oynayan kim
                var playerDef = game.Players.FirstOrDefault(f => f.Key == turn.Player);
                playerDef.Played += 1;
                if (gameType.GameType.Key == enmGameType.Trump)
                {
                    playerDef.PlayedTrump += 1;
                }
                else
                {
                    playerDef.PlayedPenalty += 1;
                }
                // her oyundaki her eli playerlara paylaştıralım
                foreach (var move in turn.Moves)
                {
                    var playerMove = game.Players.FirstOrDefault(f => f.Key == move.Player);
                    if (gameType.GameType.Key == enmGameType.Trump)
                    {
                        playerMove.TotalUp += move.Quantity * gameType.GameType.Value;
                    }
                    else
                    {
                        playerMove.TotalDown += move.Quantity * gameType.GameType.Value;
                    }
                    playerMove.Total = playerMove.TotalUp - playerMove.TotalDown;
                }

            }
            return true;

        }
コード例 #2
0
ファイル: GameModel.cs プロジェクト: alibingol/King
 public bool LoadModel(ciFramework frameW)
 {
     Game = new csGameView();
     return King.UtilGames.GameView(frameW, Game, Key);
 }
コード例 #3
0
ファイル: Games.cs プロジェクト: alibingol/King
 public static bool GameSummarySave(ciFramework frameW, csGameView gameView)
 {
     XDocument docGames = null;
     if (!King.Utils.LoadDb(frameW, ref docGames, "Games")) return false;
     XElement nodeGame = null;
     if (!King.Utils.FindGameNode(frameW, ref nodeGame, docGames, gameView.Key)) return false;
     // roota summary de ekleyelim            
     XAttribute attrPlayed = nodeGame.Attribute("played");
     if (attrPlayed == null)
     {
         attrPlayed = new XAttribute("played", "0");
         nodeGame.Add(attrPlayed);
     }
     attrPlayed.Value = gameView.Turns.Count().ToString();
     // king ise kim yapmış
     short? kingPlayer = null;
     gameView.IsKing = false;
     foreach (var turn in gameView.Turns)
     {
         if (turn.IsKing)
         {
             // eğer king ise game nodu'una da set edelim
             gameView.IsKing = true;
             kingPlayer = turn.Player;
             break;
         }
     }
     King.Utils.UpdateAttribute(nodeGame, "king", gameView.IsKing?"1":"0");
     XAttribute upPlayers = nodeGame.Attribute("ups");
     XAttribute downPlayers = nodeGame.Attribute("downs");
     if (upPlayers == null)
     {
         upPlayers = new XAttribute("ups", "");
         nodeGame.Add(upPlayers);
     }
     else
     {
         upPlayers.Value = "";
     }
     if (downPlayers == null)
     {
         downPlayers = new XAttribute("downs", "");
         nodeGame.Add(downPlayers);
     }
     else
     {
         downPlayers.Value = "";
     }
     //
     if (gameView.Turns.Count() == 20 || gameView.IsKing)
     {
         foreach (var player in gameView.Players)
         {
             if ((kingPlayer != null && Convert.ToInt16(player.Key) == kingPlayer) || (kingPlayer == null && player.Total > 0))
             {
                 upPlayers.Value += (string.IsNullOrEmpty(upPlayers.Value) ? "" : ",") + player.Name;
             }
             else
             {
                 downPlayers.Value += (string.IsNullOrEmpty(downPlayers.Value) ? "" : ",") + player.Name;
             }
         }
     }
     //            
     King.Utils.SaveDb(docGames, "Games");
     return true;
 }