コード例 #1
0
        public static string GetPlayers(string json_userID)

        {
            long userID = long.Parse(GetSingleValueFromJson(json_userID, "userID"));

            TPlayerDataObj tPlayer = new TPlayerDataObj();

            tPlayer.UserID = userID;

            DataTable dtPlayers = new TPlayersReps().GetPlayers(tPlayer);

            return(CnvDataTableToJsonString(dtPlayers));
        }
コード例 #2
0
        public string IsPlayerAlreadyIn(string json_userID)

        {
            long userID = long.Parse(JSonUtil_Server.GetSingleValueFromJson(json_userID, "userID"));

            TPlayerDataObj tPlayer = new TPlayerDataObj();

            tPlayer.UserID = userID;


            string retValue = new TPlayersReps().IsPlayerAlreadyIn(tPlayer);

            return(retValue);
        }
コード例 #3
0
        public static string StartToPlay()
        {
            if (BattleSupport.log != string.Empty)
            {
                return(BattleSupport.log);
            }

            new UserReps().ResetAllAdmin();

            string log = " \r\n";

            string padLeft = "";

            TPlayerDataObj tPlayer = new TPlayerDataObj();

            tPlayer.UserID = 0;

            DataTable dtPlayers = new TPlayersReps().GetPlayers(tPlayer);

            dtPlayers.Columns.Add("score", typeof(int));

            foreach (DataRow dr in dtPlayers.Rows)
            {
                dr["score"] = 0;
            }

            int cnt = dtPlayers.Rows.Count;

            for (int i = 1; i < cnt; i++)
            {
                for (int j = 1; i + j < cnt + 1; j++)
                {
                    int result = Fight(dtPlayers.Rows[i - 1]["set"].ToString(), dtPlayers.Rows[i - 1 + j]["set"].ToString());

                    if (result == 1)
                    {
                        dtPlayers.Rows[i - 1]["score"] = int.Parse(dtPlayers.Rows[i - 1]["score"].ToString()) + 1;

                        log += dtPlayers.Rows[i - 1]["username"].ToString() + " defeated " + dtPlayers.Rows[i - 1 + j]["username"].ToString() + " \r\n";
                    }
                    else if (result == 2)
                    {
                        dtPlayers.Rows[i - 1 + j]["score"] = int.Parse(dtPlayers.Rows[i - 1 + j]["score"].ToString()) + 1;

                        log += padLeft + padLeft + dtPlayers.Rows[i - 1 + j]["username"].ToString() + " defeated " + dtPlayers.Rows[i - 1]["username"].ToString() + " \r\n";
                    }
                    else // 0
                    {
                        log += padLeft + "draw between " + dtPlayers.Rows[i - 1 + j]["username"].ToString() + " and " + dtPlayers.Rows[i - 1]["username"].ToString() + " \r\n";
                    }
                }
            }



            int indexOfMaxScore = 0;


            int maxScore = int.Parse(dtPlayers.Rows[0]["score"].ToString());

            for (int i = 1; i < dtPlayers.Rows.Count; i++)

            {
                int nextScore = int.Parse(dtPlayers.Rows[i]["score"].ToString());

                if (nextScore > maxScore)
                {
                    maxScore = nextScore;

                    indexOfMaxScore = i;
                }
            }

            string winerUserID = dtPlayers.Rows[indexOfMaxScore]["userID"].ToString();

            UserDataObj user = new UserDataObj();

            user.UserID = long.Parse(winerUserID);

            new UserReps().SetAdminUpdatePoint(user, 5);

            log += Environment.NewLine;

            log += "---------------------------------------------------------------" + Environment.NewLine;

            log += padLeft + dtPlayers.Rows[indexOfMaxScore]["username"].ToString() + " has won the Tournament and is now the Administator" + Environment.NewLine;

            log += "---------------------------------------------------------------" + Environment.NewLine;

            //  Players.EmptyTournament();

            BattleSupport.log = log;

            return(log);
        }