コード例 #1
0
        public static ZendoUser Load(XElement pXml)
        {
            ZendoUser pUser = new ZendoUser();

            pUser.Xml = pXml;
            return(pUser);
        }
コード例 #2
0
        public string SubmitPendingKoanAnalysis(string sGameID, string sClanName, string sUserName, string sUserPassPhrase, bool bHasBuddhaNature)
        {
            string sResult = this.Prepare(sGameID, sClanName, sUserName, sUserPassPhrase, AuthenticationType.Master);

            if (sResult != "")
            {
                return(sResult);
            }

            // make sure the state is 'pending master'
            if (m_sStateStatus != "pending master")
            {
                return(Master.MessagifyError("There is no pending koan for you to analyze"));
            }

            // get the specified koan
            ZendoKoan pKoan = m_pPendingKoan;

            // set the koans buddha-nature and add it to the list
            pKoan.HasBuddhaNature = bHasBuddhaNature;
            pKoan.Koan            = pKoan.StringKoan;
            m_lKoans.Add(pKoan);

            // handle if the koan was a mondo
            if (m_bMondo)
            {
                foreach (string sUser in m_dMondoPredictions.Keys)
                {
                    if (m_dMondoPredictions[sUser] == bHasBuddhaNature)
                    {
                        ZendoUser pUser = this.GetStudentByName(sUser);
                        if (pUser == null) /* fail silently for now, we don't want this to stop execution. */ } {
                        pUser.GuessingStones++;

                        m_pServer.AddNotification(sClanName, sUser, "The master has answered the mondo, your prediction was correct!", m_sGameID, m_sGameName);
                }
                else
                {
                    m_pServer.AddNotification(sClanName, sUser, "The master has answered the mondo, your prediction was incorrect.", m_sGameID, m_sGameName);
                }
            }
コード例 #3
0
        public string StartGame(string sGameID)
        {
            this.Initialize();
            this.Load(sGameID);

            if (this.m_sStateStatus == "final")             // make the next game with all the same people and stuff
            {
                // add a number to the game name

                string sCurrentName    = m_sGameName;
                string sNewName        = "";
                string sNameWithoutNum = sCurrentName;

                int iLastSpace = sCurrentName.LastIndexOf(' ');
                int iNum       = 1;
                if (iLastSpace != -1)
                {
                    string sNumAtEnd = sCurrentName.Substring(iLastSpace + 1);
                    try
                    {
                        iNum            = Convert.ToInt32(sNumAtEnd);
                        sNameWithoutNum = sCurrentName.Substring(0, iLastSpace);
                    }
                    catch (Exception e) { iNum = 1; }
                }
                iNum++;

                sNewName = sNameWithoutNum + " " + iNum.ToString();

                // retain old winner and players
                string        sPrevWinner = m_sWinningUser;
                List <string> lOldPlayers = new List <string>();
                foreach (string sPlayer in m_lPlayerNames)
                {
                    lOldPlayers.Add(sPlayer);
                }

                this.InitializeNewGame(m_sClanName, sNewName);

                // set the new master
                if (sPrevWinner != "")
                {
                    this.SetMaster(sPrevWinner);
                }
                m_lPlayerNames = lOldPlayers;

                // add active game to the server
                m_pServer.AddActiveGame(m_sClanName, m_sGameID, "Zendo", sNewName);

                this.Save();
                return("");
            }
            if (this.m_sStateStatus != "setup")
            {
                return(Master.MessagifyError("The game has already been started."));
            }

            // choose a master if one wasn't already chosen
            if (m_sMaster == "" || m_sMaster == null)
            {
                m_sMaster = this.ChooseRandomName();
            }
            this.m_sStateStatus = "initial";

            // make everyone else the students
            foreach (string sUser in m_lPlayerNames)
            {
                if (sUser == m_sMaster)
                {
                    continue;
                }
                ZendoUser pUser = new ZendoUser(sUser);
                pUser.GuessingStones = 0;
                m_lStudents.Add(pUser);
            }

            // add event log and notify the master
            m_pServer.AddNotification(m_sClanName, m_sMaster, "You have been chosen as the master! Create your rule and initial koans!", m_sGameID, m_sGameName);
            m_lEventLog.Add(new ZendoLogEvent(m_sMaster + " has been chosen as the master"));

            this.Save();
            return(Master.MessagifySimple("The Zendo game has been started!"));
        }