Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "gameplay" layout resource
            SetContentView(Resource.Layout.gameplay);

            // Get our button from the layout resource,
            // and attach an event to it
            scoreField = FindViewById<EditText>(Resource.Id.scoreText);

            Button button_score1 = FindViewById<Button>(Resource.Id.button_score1);
            button_score1.Click += delegate { addScore(1); };

            Button button_score10 = FindViewById<Button>(Resource.Id.button_score10);
            button_score10.Click += delegate { addScore(10); };

            Button button_score100 = FindViewById<Button>(Resource.Id.button_score100);
            button_score100.Click += delegate { addScore(100); };

            Button button_game_over = FindViewById<Button>(Resource.Id.button_game_over);
            button_game_over.Click += delegate {
                // read score from text field
                double scoreResult;
                try {
                    scoreResult = double.Parse(scoreField.Text);
                } catch(Exception) {
                    scoreResult = 0;
                }

                // this is where you should input your game's score
                Score score = new Score((Java.Lang.Double)scoreResult, null);

                // set up an observer for our request
                SubmitScoreRequestControllerObserver observer = new SubmitScoreRequestControllerObserver(this);

                // with the observer, we can create a ScoreController to submit the score
                ScoreController scoreController = new ScoreController(observer);

                // show a progress dialog while we are submitting
                ShowDialog(DIALOG_PROGRESS);

                // this is the call that submits the score
                scoreController.SubmitScore(score);
                // please note that the above method will return immediately and reports to
                // the RequestControllerObserver when it's done/failed
            };
        }