Exemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            this.SetContentView(Resource.Layout.Login);

            EditText pEmail = FindViewById <EditText>(Resource.Id.txtEmail);
            EditText pPass  = FindViewById <EditText>(Resource.Id.txtUserPassword);

            Button pSubmit = FindViewById <Button>(Resource.Id.btnLogin);

            pSubmit.Click += delegate
            {
                string   sBody     = "<params><param name='sEmail'>" + pEmail.Text.ToString() + "</param><param name='sPassword'>" + Security.Sha256Hash(pPass.Text.ToString()) + "</param></params>";
                string   sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "ReturningUser", sBody, true);
                XElement pResponse = Master.ReadResponse(sResponse);

                string sResponseMessage = pResponse.Element("Text").Value;

                if (pResponse.Attribute("Type").Value == "Error")
                {
                    this.Popup(sResponseMessage);
                }
                else
                {
                    Master.HandleUserRegistrationData(pResponse);
                    this.Finish();
                }
            };
        }
Exemplo n.º 2
0
        private bool CheckVersion()
        {
            if (!Master.VERSION_CHECKED)
            {
                string   sResponse = WebCommunications.SendGetRequest(Master.GetBaseURL() + Master.GetServerURL() + "RequiredAppVersion", true);
                XElement pResponse = Master.ReadResponse(sResponse);

                if (pResponse.Element("Text").Value != Master.APP_VERSION)
                {
                    var pBuilder = new AlertDialog.Builder(this);
                    pBuilder.SetMessage("You have an outdated version of this app. Please reinstall the app from http://digitalwarriorlabs.com/games/game_clans\n(" + Master.APP_VERSION + " -> " + pResponse.Element("Text").Value + ")");
                    pBuilder.SetPositiveButton("Ok", (e, s) =>
                    {
                        //Intent pBrowserIntent = new Intent(this, Intent.ActionView, new Uri("http://digitalwarriorlabs.com/games/game_clans"));
                        Intent pBrowserIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://digitalwarriorlabs.com/games/game_clans"));
                        StartActivity(pBrowserIntent);
                        System.Environment.Exit(0);
                    });
                    pBuilder.SetNegativeButton("Cancel", (e, s) => { System.Environment.Exit(0); });
                    pBuilder.Show();
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.JoinGroup);

            EditText pClan = FindViewById <EditText>(Resource.Id.txtClanName);
            EditText pPass = FindViewById <EditText>(Resource.Id.txtClanPassword);
            EditText pUser = FindViewById <EditText>(Resource.Id.txtUserName);
            Button   pJoin = FindViewById <Button>(Resource.Id.btnSubmitJoin);

            pJoin.Click += delegate
            {
                // TODO: SANITIZATION!
                _hidden.InitializeWeb();
                //string sUserPass = File.ReadAllText(Master.GetBaseDir() + "_key.dat");
                string sUserPass = Master.GetKey();
                string sBody     = "<params><param name='sEmail'>" + Master.GetEmail() + "</param><param name='sClanName'>" + pClan.Text.ToString() + "</param><param name='sClanPassPhrase'>" + pPass.Text.ToString() + "</param><param name='sUserName'>" + pUser.Text.ToString() + "</param><param name='sUserPassPhrase'>" + sUserPass + "</param></params>";
                //string sResponse = WebCommunications.SendPostRequest("http://dwlapi.azurewebsites.net/api/reflection/GameClansServer/GameClansServer/ClanServer/JoinClan", sBody, true);
                string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "JoinClan", sBody, true);

                XElement pResponse = Master.ReadResponse(sResponse);

                //Master.Popup(this, pResponse.Element("Text").Value);
                string sResponseMessage = pResponse.Element("Text").Value;


                // TODO: even if user is already part of clan, need to check local clans file and make sure the data is there (and add it if not)



                var pBuilder = new AlertDialog.Builder(this);
                pBuilder.SetMessage(sResponseMessage);

                if (pResponse.Attribute("Type").Value == "Error" || pResponse.Element("Data").Element("ClanStub") == null)
                {
                    pBuilder.SetPositiveButton("Ok", (e, s) => { return; });
                }
                else
                {
                    pBuilder.SetPositiveButton("Ok", (e, s) =>
                    {
                        XElement pClanStub = pResponse.Element("Data").Element("ClanStub");
                        string sClanName   = pClanStub.Attribute("ClanName").Value;
                        string sUserName   = pClanStub.Attribute("UserName").Value;

                        File.AppendAllLines(Master.GetBaseDir() + "_clans.dat", new List <string>()
                        {
                            sClanName + "|" + sUserName
                        });
                        this.SetResult(Result.Ok);
                        this.Finish();
                    });
                }
                pBuilder.Create().Show();
            };
        }
Exemplo n.º 4
0
        private void CheckServerNotifications(Context pContext, string sClan, string sName)
        {
            XElement pResponse = null;
            //try
            //{
            string sPrevClan = Master.GetActiveClan();
            string sPrevUser = Master.GetActiveUserName();

            Master.SetActiveClan(sClan);
            Master.SetActiveUserName(sName);
            string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetUnseenNotifications", Master.BuildCommonBody(), true);

            pResponse = Master.ReadResponse(sResponse);
            Master.SetActiveClan(sPrevClan);
            Master.SetActiveUserName(sPrevUser);
            //}
            //catch (Exception e) { return; }

            if (pResponse.Element("Data") != null && pResponse.Element("Data").Element("Notifications").Value != "")
            {
                List <XElement> pNotifications = pResponse.Element("Data").Element("Notifications").Elements("Notification").ToList();
                foreach (XElement pNotification in pNotifications)
                {
                    string sContent  = pNotification.Value;
                    string sGameID   = pNotification.Attribute("GameID").Value;
                    string sGameName = pNotification.Attribute("GameName").Value;

                    Notification.Builder pBuilder = new Notification.Builder(pContext);
                    pBuilder.SetContentTitle(sClan + " - " + sGameName);
                    pBuilder.SetContentText(sContent);
                    pBuilder.SetSmallIcon(Resource.Drawable.Icon);
                    pBuilder.SetVibrate(new long[] { 200, 50, 200, 50 });
                    pBuilder.SetVisibility(NotificationVisibility.Public);
                    pBuilder.SetPriority((int)NotificationPriority.Default);

                    Intent pIntent = null;
                    if (sGameID.Contains("Zendo"))
                    {
                        pIntent = new Intent(pContext, typeof(ZendoActivity));
                    }
                    pIntent.SetAction(sGameID);
                    pIntent.PutExtra("GameName", sGameName);

                    pBuilder.SetContentIntent(PendingIntent.GetActivity(pContext, 0, pIntent, 0));
                    pBuilder.SetStyle(new Notification.BigTextStyle().BigText(sContent));

                    Notification        pNotif   = pBuilder.Build();
                    NotificationManager pManager = (NotificationManager)pContext.GetSystemService(Context.NotificationService);
                    pManager.Notify((int)Java.Lang.JavaSystem.CurrentTimeMillis(), pNotif);                     // using time to make different ID every time, so doesn't replace old notification
                    //pManager.Notify(DateTime.Now.Millisecond, pNotif); // using time to make different ID every time, so doesn't replace old notification
                }
            }
        }
Exemplo n.º 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Key);

            EditText pEmail = FindViewById <EditText>(Resource.Id.txtEmail);
            EditText pPass1 = FindViewById <EditText>(Resource.Id.txtUserPassword);
            EditText pPass2 = FindViewById <EditText>(Resource.Id.txtUserPassword2);

            Button pSubmit = FindViewById <Button>(Resource.Id.btnSetPassword);

            pSubmit.Click += delegate
            {
                if (pEmail.Text == "")
                {
                    Master.Popup(this, "Your email cannot be blank.");
                }
                if (pPass1.Text == "")
                {
                    Master.Popup(this, "Your password cannot be blank.");
                    return;
                }

                if (pPass1.Text != pPass2.Text)
                {
                    Master.Popup(this, "The password fields do not match.");
                    return;
                }


                string   sBody     = "<params><param name='sEmail'>" + pEmail.Text.ToString() + "</param><param name='sPassword'>" + Security.Sha256Hash(pPass1.Text.ToString()) + "</param></params>";
                string   sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "RegisterUser", sBody, true);
                XElement pResponse = Master.ReadResponse(sResponse);

                string sResponseMessage = pResponse.Element("Text").Value;

                if (pResponse.Attribute("Type").Value == "Error")
                {
                    Popup(sResponseMessage);
                    return;
                }
                else
                {
                    //MessageBox.Show(sResponseMessage);
                    Master.HandleUserRegistrationData(pResponse);
                    this.Finish();
                }
            };
        }
Exemplo n.º 6
0
        private void RefreshGameList()
        {
            string   sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "ListActiveGames", Master.BuildCommonBody(), true);
            XElement pResponse = Master.ReadResponse(sResponse);

            List <string> lGames     = new List <string>();
            List <string> lGameIDs   = new List <string>();
            List <string> lGameNames = new List <string>();
            List <string> lDisplay   = new List <string>();

            if (pResponse.Element("Data").Element("Games") != null)
            {
                foreach (XElement pGame in pResponse.Element("Data").Element("Games").Elements("Game"))
                {
                    lGameIDs.Add(pGame.Value);
                    lGames.Add(pGame.Attribute("GameType").Value);
                    lGameNames.Add(pGame.Attribute("GameName").Value);

                    lDisplay.Add(pGame.Attribute("GameName").Value + " (" + pGame.Attribute("GameType").Value + ")");
                }
            }

            ListView pGamesList = FindViewById <ListView>(Resource.Id.gamesList);

            pGamesList.Adapter = new DrawerItemCustomAdapter(this, Resource.Layout.ListViewItemRow, lDisplay.ToArray());

            pGamesList.ItemClick += (object sender, Android.Widget.AdapterView.ItemClickEventArgs e) =>
            {
                int iChoice = e.Position;

                Intent pIntent = null;
                if (lGames[iChoice] == "Zendo")
                {
                    pIntent = new Intent(this, (new ZendoActivity()).Class);
                }
                pIntent.SetAction(lGameIDs[iChoice]);
                pIntent.PutExtra("GameName", lGameNames[iChoice]);
                this.Finish();
                StartActivity(pIntent);
            };
        }
Exemplo n.º 7
0
        private void BuildHomeDashboard()
        {
            // get the scoreboard from the server
            string   sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetClanLeaderboard", Master.BuildCommonBody(), true);
            XElement pResponse = Master.ReadResponse(sResponse);

            // build the scoreboard
            if (pResponse.Element("Data").Element("Leaderboard") != null)
            {
                XElement pLeaderboard = pResponse.Element("Data").Element("Leaderboard");

                TextView pMyUser  = FindViewById <TextView>(Resource.Id.lblMyStatsName);
                TextView pMyScore = FindViewById <TextView>(Resource.Id.lblMyStatsScore);
                TextView pMyPlace = FindViewById <TextView>(Resource.Id.lblMyStatsPlace);

                pMyUser.Text  = Master.GetActiveUserName();
                pMyScore.Text = pLeaderboard.Attribute("Score").Value;
                pMyPlace.Text = pLeaderboard.Attribute("Place").Value;

                LinearLayout pScoreboardLayout = FindViewById <LinearLayout>(Resource.Id.lstScoreBoard);
                pScoreboardLayout.RemoveAllViews();

                foreach (XElement pScoreXml in pLeaderboard.Elements("Score"))
                {
                    View pScoreRow = LayoutInflater.From(this).Inflate(Resource.Layout.ScoreRow, pScoreboardLayout, false);

                    TextView pUser  = pScoreRow.FindViewById <TextView>(Resource.Id.lblScoreName);
                    TextView pPlace = pScoreRow.FindViewById <TextView>(Resource.Id.lblScorePlace);
                    TextView pScore = pScoreRow.FindViewById <TextView>(Resource.Id.lblScoreScore);

                    pUser.Text  = pScoreXml.Attribute("User").Value;
                    pPlace.Text = pScoreXml.Attribute("Place").Value;
                    pScore.Text = pScoreXml.Attribute("Score").Value;

                    pScoreboardLayout.AddView(pScoreRow);
                }
            }

            // get the notifcations list from the server
            sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetUnreadNotifications", Master.BuildCommonBody(), true);
            pResponse = Master.ReadResponse(sResponse);

            LinearLayout pNotifLayout = FindViewById <LinearLayout>(Resource.Id.lstNotifications);

            pNotifLayout.RemoveAllViews();
            if (pResponse.Element("Data").Element("Notifications") != null)
            {
                foreach (XElement pNotif in pResponse.Element("Data").Element("Notifications").Elements("Notification"))
                {
                    // make the datarow layout
                    View pDataRow = LayoutInflater.From(this).Inflate(Resource.Layout.DataRow, pNotifLayout, false);

                    TextView pDataText = pDataRow.FindViewById <TextView>(Resource.Id.txtText);
                    pDataText.Text = pNotif.Attribute("GameName").Value + " - " + pNotif.Value;

                    // reset event handler
                    pDataText.Click    -= m_pDataTextDelegate;
                    m_pDataTextDelegate = delegate
                    {
                        string sGameID = pNotif.Attribute("GameID").Value;
                        Intent pIntent = null;
                        if (sGameID.Contains("Zendo"))
                        {
                            pIntent = new Intent(this, typeof(ZendoActivity));
                        }
                        pIntent.SetAction(sGameID);
                        pIntent.PutExtra("GameName", pNotif.Attribute("GameName").Value);
                        this.Finish();
                        StartActivity(pIntent);
                    };
                    pDataText.Click += m_pDataTextDelegate;

                    /*pDataText.Click += delegate
                     * {
                     *      string sGameID = pNotif.Attribute("GameID").Value;
                     *      Intent pIntent = null;
                     *      if (sGameID.Contains("Zendo")) { pIntent = new Intent(this, typeof(ZendoActivity)); }
                     *      pIntent.SetAction(sGameID);
                     *      pIntent.PutExtra("GameName", pNotif.Attribute("GameName").Value);
                     *      this.Finish();
                     *      StartActivity(pIntent);
                     * };*/

                    pNotifLayout.AddView(pDataRow);
                }
            }

            Button pMarkRead = FindViewById <Button>(Resource.Id.btnMarkRead);

            pMarkRead.Click += delegate
            {
                WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "MarkUnreadNotificationsRead", Master.BuildCommonBody(), true);
                this.BuildHomeDashboard();
            };
        }
Exemplo n.º 8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            this.SetContentView(Resource.Layout.NewGame);

            // Create your application here

            EditText pName = FindViewById <EditText>(Resource.Id.txtGameName);

            // games list
            ListView pGamesList = FindViewById <ListView>(Resource.Id.gamesList);

            pGamesList.Adapter = new DrawerItemCustomAdapter(this, Resource.Layout.ListViewItemRow, m_lGameTypes.ToArray());

            pGamesList.ItemClick += (object sender, Android.Widget.AdapterView.ItemClickEventArgs e) =>
            {
                int iChoice = e.Position;
                m_sSelectedType = m_lGameTypes[iChoice];

                TextView pGameType = FindViewById <TextView>(Resource.Id.txtGameType);
                pGameType.Text = "Game type - " + m_sSelectedType;
            };

            Button pSubmit = FindViewById <Button>(Resource.Id.btnSubmitGame);

            pSubmit.Click += delegate
            {
                if (m_sSelectedType == "")
                {
                    var pBuilder = new AlertDialog.Builder(this);
                    pBuilder.SetMessage("You must select a game type");
                    pBuilder.SetPositiveButton("Ok", (e, s) => { return; });
                    pBuilder.Show();
                }
                else if (pName.Text == "")
                {
                    var pBuilder = new AlertDialog.Builder(this);
                    pBuilder.SetMessage("Please enter a name for your game");
                    pBuilder.SetPositiveButton("Ok", (e, s) => { return; });
                    pBuilder.Show();
                }
                else
                {
                    string   sBody            = Master.BuildCommonBody("<param name='sGameName'>" + pName.Text.ToString() + "</param>");
                    string   sResponse        = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL(m_sSelectedType) + "CreateNewGame", sBody, true);
                    XElement pResponse        = Master.ReadResponse(sResponse);
                    string   sResponseMessage = pResponse.Element("Text").Value;

                    var pBuilder = new AlertDialog.Builder(this);
                    pBuilder.SetMessage(sResponseMessage);

                    if (pResponse.Attribute("Type").Value == "Error")
                    {
                        pBuilder.SetPositiveButton("Ok", (e, s) => { return; });
                    }
                    else
                    {
                        pBuilder.SetPositiveButton("Ok", (e, s) =>
                        {
                            this.SetResult(Result.Ok);
                            this.Finish();
                        });
                    }
                    pBuilder.Create().Show();
                }
            };
        }
Exemplo n.º 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            this.SetContentView(Resource.Layout.Notifications);

            base.CreateDrawer();

            // get the notifcations list from the server
            string   sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetLastNNotifications", Master.BuildCommonBody(), true);
            XElement pResponse = Master.ReadResponse(sResponse);

            List <string> lDisplay   = new List <string>();
            List <string> lIDs       = new List <string>();
            List <string> lGameNames = new List <string>();

            if (pResponse.Element("Data").Element("Notifications") != null)
            {
                foreach (XElement pNotif in pResponse.Element("Data").Element("Notifications").Elements("Notification"))
                {
                    lDisplay.Add(pNotif.Attribute("GameName").Value + " - " + pNotif.Value);
                    lIDs.Add(pNotif.Attribute("GameID").Value);
                    lGameNames.Add(pNotif.Attribute("GameName").Value);
                }
            }

            ListView pNotifList = FindViewById <ListView>(Resource.Id.lstNotifications);

            pNotifList.Adapter = new DrawerItemCustomAdapter(this, Resource.Layout.ListViewItemRow, lDisplay.ToArray());

            pNotifList.ItemClick += (object sender, Android.Widget.AdapterView.ItemClickEventArgs e) =>
            {
                int iChoice = e.Position;

                Intent pIntent = null;
                if (lIDs[iChoice].Contains("Zendo"))
                {
                    pIntent = new Intent(this, typeof(ZendoActivity));
                }
                pIntent.SetAction(lIDs[iChoice]);
                pIntent.PutExtra("GameName", lGameNames[iChoice]);
                this.Finish();
                StartActivity(pIntent);
            };

            /*LinearLayout pNotifLayout = FindViewById<LinearLayout>(Resource.Id.lstNotifications);
             * pNotifLayout.RemoveAllViews();
             * if (pResponse.Element("Data").Element("Notifications") != null)
             * {
             *      foreach (XElement pNotif in pResponse.Element("Data").Element("Notifications").Elements("Notification"))
             *      {
             *              // make the datarow layout
             *              View pDataRow = LayoutInflater.From(this).Inflate(Resource.Layout.DataRow, pNotifLayout, false);
             *
             *              TextView pDataText = pDataRow.FindViewById<TextView>(Resource.Id.txtText);
             *              pDataText.Text = pNotif.Attribute("GameName").Value + " - " + pNotif.Value;
             *
             *              pDataText.Click += delegate
             *              {
             *                      string sGameID = pNotif.Attribute("GameID").Value;
             *                      Intent pIntent = null;
             *                      if (sGameID.Contains("Zendo")) { pIntent = new Intent(this, typeof(ZendoActivity)); }
             *                      pIntent.SetAction(sGameID);
             *                      pIntent.PutExtra("GameName", pNotif.Attribute("GameName").Value);
             *                      this.Finish();
             *                      StartActivity(pIntent);
             *              };
             *
             *              pNotifLayout.AddView(pDataRow);
             *      }
             * }*/
        }
Exemplo n.º 10
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (resultCode == Result.Ok)
            {
                // TODO: HANDLE EXTRA HERE
                string sType = data.GetStringExtra("Type");

                XElement pResponse         = null;
                bool     bRestartRequested = false;


                if (sType == "initial")
                {
                    string sRule = data.GetStringExtra("Rule");
                    string sInitialCorrectKoan   = data.GetStringExtra("CorrectKoan");
                    string sInitialIncorrectKoan = data.GetStringExtra("IncorrectKoan");

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sRule'>" + sRule + "</param><param name='sBuddhaNatureKoan'>" + sInitialCorrectKoan + "</param><param name='sNonBuddhaNatureKoan'>" + sInitialIncorrectKoan + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitInitialKoans", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                }
                else if (sType == "build")
                {
                    string sKoan  = data.GetStringExtra("Koan");
                    bool   bMondo = data.GetBooleanExtra("Mondo", false);

                    string sBody = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sKoan'>" + sKoan + "</param>");

                    string sResponse = "";
                    if (!bMondo)
                    {
                        sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitKoan", sBody, true);
                    }
                    else
                    {
                        sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitMondo", sBody, true);
                    }
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                    bRestartRequested = true;
                }
                else if (sType == "analysis")
                {
                    bool bHasBuddhaNature = data.GetBooleanExtra("HasBuddhaNature", false);

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='bHasBuddhaNature'>" + bHasBuddhaNature + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitPendingKoanAnalysis", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                }
                else if (sType == "predict")
                {
                    bool bPrediction = data.GetBooleanExtra("Prediction", false);

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='bPrediction'>" + bPrediction + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitMondoPrediction", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                    bRestartRequested = true;
                }
                else if (sType == "guess")
                {
                    string sGuess = data.GetStringExtra("Guess");

                    string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sGuess'>" + Master.EncodeXML(sGuess) + "</param>");
                    string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "SubmitGuess", sBody, true);
                    if (Master.CleanResponse(sResponse) != "")
                    {
                        pResponse = Master.ReadResponse(sResponse);
                    }
                    bRestartRequested = true;
                }
                else if (sType == "disprove")
                {
                    bool bSuccessfullyDisproved = data.GetBooleanExtra("Disprove", false);
                    if (!bSuccessfullyDisproved)
                    {
                        string sAltResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "GrantEnlightenment", Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID)), true);
                        if (Master.CleanResponse(sAltResponse) != "")
                        {
                            pResponse = Master.ReadResponse(sAltResponse);
                        }
                    }
                    else
                    {
                        string sKoan            = data.GetStringExtra("Koan");
                        bool   bHasBuddhaNature = data.GetBooleanExtra("HasBuddhaNature", false);

                        string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID) + "<param name='sKoan'>" + sKoan + "</param><param name='bHasBuddhaNature'>" + bHasBuddhaNature + "</param>");
                        string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "DisproveGuess", sBody, true);
                        if (Master.CleanResponse(sResponse) != "")
                        {
                            pResponse = Master.ReadResponse(sResponse);
                        }
                    }
                }

                if (pResponse != null)
                {
                    var pBuilder = new AlertDialog.Builder(this);
                    pBuilder.SetMessage(pResponse.Element("Text").Value);
                    pBuilder.SetPositiveButton("Ok", (e, s) => { return; });
                    pBuilder.Show();
                }
                else if (bRestartRequested)
                {
                    this.ForceRestart();
                }
                else
                {
                    this.GetUserBoard();
                }
            }
        }
Exemplo n.º 11
0
        private void GetUserBoard()
        {
            // send the request to the server
            string sBody     = Master.BuildCommonBody(Master.BuildGameIDBodyPart(m_sGameID));
            string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "GetUserBoard", sBody, true);

            XElement pResponse = Master.ReadResponse(sResponse);

            if (pResponse.Attribute("Type").Value == "Error")
            {
                throw new Exception(pResponse.ToString());
            }

            // get the specific parts
            XElement pStatusXml     = pResponse.Element("Data").Element("Status");
            XElement pActionXml     = pResponse.Element("Data").Element("Action");
            XElement pNumGuessesXml = pResponse.Element("Data").Element("NumGuesses");
            XElement pMasterXml     = pResponse.Element("Data").Element("Master");
            XElement pPlayersXml    = pResponse.Element("Data").Element("Players");
            XElement pEventsXml     = pResponse.Element("Data").Element("Events");
            XElement pKoansXml      = pResponse.Element("Data").Element("Koans");

            TextView pGameStatusText = FindViewById <TextView>(Resource.Id.txtGameStatus);

            pGameStatusText.Text = pStatusXml.Element("Text").Value;

            // TODO: handle data tag in status
            FlowLayout pFlow = FindViewById <FlowLayout>(Resource.Id.flowStatusKoan);

            if (pStatusXml.Element("Data").Value != "")
            {
                string sKoan = pStatusXml.Element("Data").Element("Koan").Value;

                Master.FillKoanDisplay(this, pFlow, sKoan);
                LinearLayout.LayoutParams pParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams(LayoutParams.FillParent, LayoutParams.WrapContent));
                pParams.SetMargins(30, 0, 30, 30);
                pFlow.LayoutParameters = pParams;
            }
            else
            {
                pFlow.RemoveAllViews();
                LinearLayout.LayoutParams pParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams(LayoutParams.FillParent, LayoutParams.WrapContent));
                pParams.SetMargins(0, 0, 0, 0);
                pFlow.LayoutParameters = pParams;
            }

            // set the action button accordingly
            Button pActionButton = FindViewById <Button>(Resource.Id.btnAction);
            Button pGiveUpButton = FindViewById <Button>(Resource.Id.btnGiveUp);

            pGiveUpButton.Enabled = true;
            pActionButton.Enabled = true;
            string sAction = pActionXml.Value;

            pActionButton.Click -= m_pActionButtonDelegate;
            if (sAction == "join")
            {
                pActionButton.Text      = "Join Game";
                m_pActionButtonDelegate = delegate
                {
                    string   sResponse2 = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetGameURL("Zendo") + "JoinGame", sBody, true);
                    XElement pResponse2 = Master.ReadResponse(sResponse2);

                    var pBuilder = new AlertDialog.Builder(this);
                    pBuilder.SetMessage(pResponse2.Element("Text").Value);
                    pBuilder.SetPositiveButton("Ok", (e, s) => { this.GetUserBoard(); });
                    pBuilder.Show();
                };
            }
            else if (sAction == "initial")
            {
                pActionButton.Text      = "Create Initial Koans";
                m_pActionButtonDelegate = delegate
                {
                    Intent pIntent = new Intent(this, (new ZendoCreateRuleActivity()).Class);
                    this.StartActivityForResult(pIntent, 0);
                };
            }
            else if (sAction == "build")
            {
                pActionButton.Text      = "Build Koan";
                m_pActionButtonDelegate = delegate
                {
                    Intent pIntent = new Intent(this, (new ZendoBuildKoanActivity()).Class);
                    pIntent.PutExtra("Koans", pKoansXml.ToString());
                    this.StartActivityForResult(pIntent, 0);
                };
            }
            else if (sAction == "judge")
            {
                pActionButton.Text      = "Analyze Koan";
                m_pActionButtonDelegate = delegate
                {
                    Intent pIntent = new Intent(this, (new ZendoJudgeKoanActivity()).Class);
                    pIntent.PutExtra("Koan", pStatusXml.Element("Data").Element("Koan").Value);
                    pIntent.PutExtra("Rule", pMasterXml.Attribute("Rule").Value);
                    this.StartActivityForResult(pIntent, 0);
                };
            }
            else if (sAction == "predict")
            {
                pActionButton.Text      = "Predict Master's Analysis";
                m_pActionButtonDelegate = delegate
                {
                    Intent pIntent = new Intent(this, (new ZendoPredictActivity()).Class);
                    pIntent.PutExtra("Koan", pStatusXml.Element("Data").Element("Koan").Value);
                    pIntent.PutExtra("Koans", pKoansXml.ToString());
                    this.StartActivityForResult(pIntent, 0);
                };
            }
            else if (sAction == "disprove")
            {
                pActionButton.Text      = "Disprove Guess";
                m_pActionButtonDelegate = delegate
                {
                    Intent pIntent = new Intent(this, typeof(ZendoDisproveActivity));
                    pIntent.PutExtra("Guess", pStatusXml.Attribute("Guess").Value);
                    pIntent.PutExtra("Rule", pMasterXml.Attribute("Rule").Value);
                    this.StartActivityForResult(pIntent, 0);
                };
            }
            else if (sAction == "final")
            {
                pActionButton.Text    = "Game Over!";
                pActionButton.Enabled = false;
                pGiveUpButton.Enabled = false;
            }
            else if (sAction == "waiting")
            {
                pActionButton.Text    = "Waiting...";
                pActionButton.Enabled = false;
            }
            pActionButton.Click += m_pActionButtonDelegate;

            // set number of guesses
            int    iNumGuesses  = Convert.ToInt32(pNumGuessesXml.Value);
            Button pGuessButton = FindViewById <Button>(Resource.Id.btnGuess);

            pGuessButton.Text = "Guess (" + iNumGuesses.ToString() + " guess tokens)";
            if (iNumGuesses > 0 && sAction == "build")
            {
                pGuessButton.Enabled = true;
            }
            else
            {
                pGuessButton.Enabled = false;
            }
            pGuessButton.Click    -= m_pGuessButtonDelegate;
            m_pGuessButtonDelegate = delegate
            {
                Intent pIntent = new Intent(this, typeof(ZendoGuessActivity));
                pIntent.PutExtra("Koans", pKoansXml.ToString());
                this.StartActivityForResult(pIntent, 0);
            };
            pGuessButton.Click += m_pGuessButtonDelegate;

            // set master label
            string   sMaster = pMasterXml.Value;
            TextView pMaster = FindViewById <TextView>(Resource.Id.txtMaster);

            pMaster.Text = "Master - " + sMaster;

            // fill players box
            LinearLayout pPlayersLayout = FindViewById <LinearLayout>(Resource.Id.lstPlayers);

            pPlayersLayout.RemoveAllViews();
            foreach (string sPlayer in pPlayersXml.Elements("Player"))
            {
                View pDataRow = LayoutInflater.From(this).Inflate(Resource.Layout.DataRow, pPlayersLayout, false);

                TextView pDataText = pDataRow.FindViewById <TextView>(Resource.Id.txtText);
                pDataText.Text = sPlayer;

                pPlayersLayout.AddView(pDataRow);
            }

            // fill log event box
            LinearLayout pLogLayout = FindViewById <LinearLayout>(Resource.Id.lstLog);

            pLogLayout.RemoveAllViews();
            //foreach (XElement pEvent in pEventsXml.Elements("LogEvent"))
            List <XElement> pEventsXmlChildren = pEventsXml.Elements("LogEvent").ToList();

            for (int i = pEventsXmlChildren.Count - 1; i >= 0; i--)
            {
                XElement pEvent = pEventsXmlChildren[i];
                string   sMsg   = pEvent.Element("Message").Value;

                // make the datarow layout
                View pDataRow = LayoutInflater.From(this).Inflate(Resource.Layout.DataRow, pLogLayout, false);

                TextView pDataText = pDataRow.FindViewById <TextView>(Resource.Id.txtText);
                pDataText.Text = sMsg;

                // check the data tag
                XElement pData = pEvent.Element("Data");
                if (pData.Value != "")
                {
                    string sKoanContents = pEvent.Element("Data").Element("Koan").Value;

                    FlowLayout pDataRowFlow = pDataRow.FindViewById <FlowLayout>(Resource.Id.flowDataRowKoan);
                    Master.FillKoanDisplay(this, pDataRowFlow, sKoanContents);

                    LinearLayout.LayoutParams pParams = new LinearLayout.LayoutParams(new ViewGroup.LayoutParams(LayoutParams.FillParent, LayoutParams.WrapContent));
                    pParams.SetMargins(20, 0, 20, 20);
                    pDataRowFlow.LayoutParameters = pParams;
                }

                // add the data row
                pLogLayout.AddView(pDataRow);
            }

            // fill koans box
            LinearLayout pKoansLayout = FindViewById <LinearLayout>(Resource.Id.lstKoans);

            pKoansLayout.RemoveAllViews();
            List <XElement> pKoansXmlChildren = pKoansXml.Elements("Koan").ToList();

            for (int i = pKoansXmlChildren.Count - 1; i >= 0; i--)
            {
                XElement pKoan = pKoansXmlChildren[i];

                View pView = LayoutInflater.From(this).Inflate(Resource.Layout.Game_ZendoKoanRow, pKoansLayout, false);

                FlowLayout pKoanBoxFlow = pView.FindViewById <FlowLayout>(Resource.Id.lstKoanImages);

                string sKoanText = pKoan.Value;
                Master.FillKoanDisplay(this, pKoanBoxFlow, sKoanText);

                /*List<string> lPieces = Master.GetPieceParts(sKoanText);
                 * foreach (string sPiece in lPieces)
                 * {
                 *      int iRes = Master.GetPieceImage(sPiece);
                 *      if (iRes == 0) { continue; } // TODO: error handling?Jk;lw
                 *
                 *      ImageView pKoanView = new ImageView(this);
                 *      pKoanView.SetImageResource(iRes);
                 *      pFlow.AddView(pKoanView);
                 * }*/

                pKoansLayout.AddView(pView);
            }
        }