// returns true if koan valid, false if koan invalid. NOTE: Takes care of toupper public static bool FillKoanDisplay(Context pContext, FlowLayout pFlow, string sKoan) { bool bValid = true; // reset layout pFlow.RemoveAllViews(); // get the image for each piece and add it List <string> lPieces = GetPieceParts(sKoan); foreach (string sPiece in lPieces) { int iRes = GetPieceImage(sPiece); if (iRes == 0) { bValid = false; continue; } ImageView pImageView = new ImageView(pContext); pImageView.SetImageResource(iRes); pFlow.AddView(pImageView); } // return whether koan was valid or naw return(bValid); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.SetContentView(Resource.Layout.Game_ZendoDisprove); // get data string sRule = this.Intent.GetStringExtra("Rule"); string sGuess = this.Intent.GetStringExtra("Guess"); // fill the elements TextView pRule = FindViewById <TextView>(Resource.Id.txtRule); pRule.Text = "Your rule - '" + sRule + "'"; TextView pRuleGuess = FindViewById <TextView>(Resource.Id.txtRuleGuess); pRuleGuess.Text = "Guessed rule - '" + sGuess + "'"; // get other important gui elements m_pKoanDisplay = FindViewById <FlowLayout>(Resource.Id.flowKoan); m_pKoanTextEditor = FindViewById <EditText>(Resource.Id.txtKoanBuilder); m_pKoanTextEditor.TextChanged += delegate { this.FillKoan(); }; Button pYes = FindViewById <Button>(Resource.Id.btnHasBuddhaNature); Button pNo = FindViewById <Button>(Resource.Id.btnHasNotBuddhaNature); Button pGrant = FindViewById <Button>(Resource.Id.btnGrantEnlightenment); pYes.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "disprove"); pIntent.PutExtra("Koan", m_pKoanTextEditor.Text.ToUpper()); pIntent.PutExtra("HasBuddhaNature", true); pIntent.PutExtra("Disprove", true); this.SetResult(Result.Ok, pIntent); this.Finish(); }; pNo.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "disprove"); pIntent.PutExtra("Koan", m_pKoanTextEditor.Text.ToUpper()); pIntent.PutExtra("HasBuddhaNature", false); pIntent.PutExtra("Disprove", true); this.SetResult(Result.Ok, pIntent); this.Finish(); }; pGrant.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "disprove"); pIntent.PutExtra("Disprove", false); this.SetResult(Result.Ok, pIntent); this.Finish(); }; FillKoan(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.SetContentView(Resource.Layout.Game_ZendoPredict); // Create your application here string sKoan = this.Intent.GetStringExtra("Koan"); string sKoans = this.Intent.GetStringExtra("Koans"); // xml // fill the primary koan thing FlowLayout pPredictFlow = FindViewById <FlowLayout>(Resource.Id.flowKoan); Master.FillKoanDisplay(this, pPredictFlow, sKoan); // fill the list of koans LinearLayout pKoansLayout = FindViewById <LinearLayout>(Resource.Id.lstKoans); pKoansLayout.RemoveAllViews(); XElement pKoansXml = XElement.Parse(sKoans); List <XElement> pKoans = pKoansXml.Elements("Koan").ToList(); for (int i = pKoans.Count - 1; i >= 0; i--) { XElement pKoan = pKoans[i]; // create the row view View pView = LayoutInflater.From(this).Inflate(Resource.Layout.Game_ZendoKoanRow, pKoansLayout, false); FlowLayout pFlow = pView.FindViewById <FlowLayout>(Resource.Id.lstKoanImages); string sKoanText = pKoan.Value; Master.FillKoanDisplay(this, pFlow, sKoanText); pKoansLayout.AddView(pView); } // buttons Button pYes = FindViewById <Button>(Resource.Id.btnHasBuddhaNature); Button pNo = FindViewById <Button>(Resource.Id.btnHasNotBuddhaNature); pYes.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "predict"); pIntent.PutExtra("Prediction", true); this.SetResult(Result.Ok, pIntent); this.Finish(); }; pNo.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "predict"); pIntent.PutExtra("Prediction", false); this.SetResult(Result.Ok, pIntent); this.Finish(); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.SetContentView(Resource.Layout.Game_ZendoCreateRule); // Create your application here EditText pRule = FindViewById <EditText>(Resource.Id.txtRule); Button pSubmit = FindViewById <Button>(Resource.Id.btnSubmitInitial); // get the good koan elements m_pImageRowGood = FindViewById <FlowLayout>(Resource.Id.lstKoanImagesGood); m_pGoodKoan = FindViewById <EditText>(Resource.Id.txtGoodKoan); // get the bad koan elements m_pImageRowBad = FindViewById <FlowLayout>(Resource.Id.lstKoanImagesBad); m_pBadKoan = FindViewById <EditText>(Resource.Id.txtBadKoan); // add element event handlers m_pGoodKoan.TextChanged += delegate { this.FillGoodKoan(); }; m_pBadKoan.TextChanged += delegate { this.FillBadKoan(); }; pSubmit.Click += delegate { if (m_pGoodKoan.Text == "" || m_pBadKoan.Text == "" || pRule.Text == "") { var pBuilder = new AlertDialog.Builder(this); pBuilder.SetMessage("No fields can be blank."); pBuilder.SetPositiveButton("Ok", (e, s) => { return; }); pBuilder.Show(); } else { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "initial"); pIntent.PutExtra("Rule", pRule.Text); pIntent.PutExtra("CorrectKoan", "T" + m_pGoodKoan.Text.ToUpper()); pIntent.PutExtra("IncorrectKoan", "F" + m_pBadKoan.Text.ToUpper()); SetResult(Result.Ok, pIntent); this.Finish(); } }; Button pExampleButton = FindViewById <Button>(Resource.Id.btnExampleRules); pExampleButton.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoExampleRulesActivity)); StartActivity(pIntent); this.SetResult(Result.Canceled); }; // put the initial truth/false stones this.FillGoodKoan(); this.FillBadKoan(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.SetContentView(Resource.Layout.Game_ZendoGuess); // get extras string sKoans = this.Intent.GetStringExtra("Koans"); XElement pKoansXml = XElement.Parse(sKoans); // 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 pFlow = pView.FindViewById <FlowLayout>(Resource.Id.lstKoanImages); string sKoanText = pKoan.Value; Master.FillKoanDisplay(this, pFlow, sKoanText); pKoansLayout.AddView(pView); } // submit button Button pSubmit = FindViewById <Button>(Resource.Id.btnGuess); pSubmit.Click += delegate { EditText pGuessText = FindViewById <EditText>(Resource.Id.txtGuess); Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "guess"); pIntent.PutExtra("Guess", pGuessText.Text); this.SetResult(Result.Ok, pIntent); this.Finish(); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.SetContentView(Resource.Layout.Game_ZendoAnalyzeKoan); // display the koan FlowLayout pFlow = FindViewById <FlowLayout>(Resource.Id.flowKoan); string sKoan = this.Intent.GetStringExtra("Koan"); string sRule = this.Intent.GetStringExtra("Rule"); Master.FillKoanDisplay(this, pFlow, sKoan); TextView pRuleText = FindViewById <TextView>(Resource.Id.txtRule); pRuleText.Text = "Your rule - '" + sRule + "'"; Button pYes = FindViewById <Button>(Resource.Id.btnHasBuddhaNature); Button pNo = FindViewById <Button>(Resource.Id.btnHasNotBuddhaNature); pYes.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "analysis"); pIntent.PutExtra("HasBuddhaNature", true); this.SetResult(Result.Ok, pIntent); this.Finish(); }; pNo.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "analysis"); pIntent.PutExtra("HasBuddhaNature", false); this.SetResult(Result.Ok, pIntent); this.Finish(); }; }
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); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Game_ZendoBuildKoan); // Create your application here // gui elements m_pKoanTextEditor = FindViewById <EditText>(Resource.Id.txtKoanBuilder); m_pKoanDisplay = FindViewById <FlowLayout>(Resource.Id.lstKoanImages); Button pMondo = FindViewById <Button>(Resource.Id.btnSubmitMondo); Button pMaster = FindViewById <Button>(Resource.Id.btnSubmitMaster); m_pKoanTextEditor.TextChanged += delegate { this.FillKoan(); }; pMondo.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "build"); pIntent.PutExtra("Koan", m_pKoanTextEditor.Text.ToUpper()); pIntent.PutExtra("Mondo", true); this.SetResult(Result.Ok, pIntent); this.Finish(); }; pMaster.Click += delegate { Intent pIntent = new Intent(this, typeof(ZendoActivity)); pIntent.PutExtra("Type", "build"); pIntent.PutExtra("Koan", m_pKoanTextEditor.Text.ToUpper()); pIntent.PutExtra("Mondo", false); this.SetResult(Result.Ok, pIntent); this.Finish(); }; string sKoans = this.Intent.GetStringExtra("Koans"); XElement pKoansXml = XElement.Parse(sKoans); // TODO: error handling? // 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 pFlow = pView.FindViewById <FlowLayout>(Resource.Id.lstKoanImages); string sKoanText = pKoan.Value; Master.FillKoanDisplay(this, pFlow, 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); } this.FillKoan(); }