Exemplo n.º 1
0
        /// <summary>
        /// Called on activity creation.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            GameProfile gp = new GameProfile(Intent);

            SetContentView(Resource.Layout.CreateTable);

            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

            DisplayMetrics metrics   = Resources.DisplayMetrics;
            int            widthInDp = metrics.WidthPixels;

            #region Display Management
            _pl [0] = FindViewById <EditText> (Resource.Id.player1);
            _pl [1] = FindViewById <EditText> (Resource.Id.player2);
            _pl [2] = FindViewById <EditText> (Resource.Id.player3);
            _pl [3] = FindViewById <EditText> (Resource.Id.player4);
            _pl [4] = FindViewById <EditText> (Resource.Id.player5);

            _titCol1 = FindViewById <TextView> (Resource.Id.textView1);
            _titCol2 = FindViewById <TextView> (Resource.Id.textView7);
            _titCol3 = FindViewById <TextView> (Resource.Id.textView9);

            _radioDealer [0] = FindViewById <RadioButton> (Resource.Id.Dealer1);
            _radioDealer [1] = FindViewById <RadioButton> (Resource.Id.Dealer2);
            _radioDealer [2] = FindViewById <RadioButton> (Resource.Id.Dealer3);
            _radioDealer [3] = FindViewById <RadioButton> (Resource.Id.Dealer4);
            _radioDealer [4] = FindViewById <RadioButton> (Resource.Id.Dealer5);

            _spinner [0] = FindViewById <Spinner> (Resource.Id.spinner1);
            _spinner [1] = FindViewById <Spinner> (Resource.Id.spinner2);
            _spinner [2] = FindViewById <Spinner> (Resource.Id.spinner3);
            _spinner [3] = FindViewById <Spinner> (Resource.Id.spinner4);

            adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.Type, Android.Resource.Layout.SimpleSpinnerItem);

            _start = FindViewById <Button> (Resource.Id.Start);
            _back  = FindViewById <Button> (Resource.Id.back);

            _radioDealer [gp.Dealer].Checked = true;

            for (int i = 0; i < 5; ++i)
            {
                _pl [i].Text             = gp.getPlayerName(i);
                _radioDealer [i].Enabled = gp.DealerEnabled;
                if (i < 4)
                {
                    _addr [i] = gp.getPlayerAddress(i);
                    _spinner [i].ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (spinner_Itemselected);
                    _spinner [i].Adapter       = adapter;
                    _spinner [i].SetSelection((_addr [i] == Resources.GetString(Resource.String.none_add)) ? 0 : 1);
                }
            }


            _titCol1.LayoutParameters.Width = (int)(widthInDp * _FIRST_FRACTION_WIDTH);
            _titCol2.LayoutParameters.Width = (int)(widthInDp * _SECOND_FRACTION_WIDTH);
            _titCol3.LayoutParameters.Width = (int)(widthInDp * _THIRD_FRACTION_WIDTH);

            _start.Click += Start_Game;
            _back.Click  += Back;

            #endregion

            BTManager.Instance.setActivity(this);

            SetTitle(Resource.String.create_title);

            BTManager.Instance.eventLocalMessageReceived += handleLocalMessage;
            BTManager.Instance.eventPackageReceived      += handlePackage;
            BTManager.Instance.RegisterReceivers();
        }
Exemplo n.º 2
0
        /// <param name="requestCode">The integer request code originally supplied to
        ///  startActivityForResult(), allowing you to identify who this
        ///  result came from.</param>
        /// <param name="resultCode">The integer result code returned by the child activity
        ///  through its setResult().</param>
        /// <param name="data">An Intent, which can return result data to the caller
        ///  (various data can be attached to Intent "extras").</param>
        /// <summary>
        /// Called when an activity you launched exits, giving you the requestCode
        ///  you started it with, the resultCode it returned, and any additional
        ///  data from it.
        /// </summary>
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            _playerControllerList.Clear();

            if (requestCode == 2 && resultCode == Result.Ok)
            {
                BTManager.Instance.eventLocalMessageReceived += handleLocalMessage;
                if (!BTManager.Instance.isSlave())
                {
                    _gameProfile = new GameProfile(data);

                    using (CriptoRandom rnd = new CriptoRandom())
                        Board.Instance.InitializeMaster(_gameProfile.PlayerNames, _gameProfile.Dealer, rnd);

                    BTManager.Instance.initializeCommunication();

                    if (BTManager.Instance.getNumConnected() > 0)
                    {
                        BTManager.Instance.WriteToAllSlave(new PackageBoard());
                    }

                    _playerControllerList = new List <IPlayerController> (Board.PLAYER_NUMBER);

                    for (int i = 1; i < Board.PLAYER_NUMBER; i++)
                    {
                        if (_gameProfile.getPlayerAddress(i - 1) == Resources.GetString(Resource.String.none_add))
                        {
                            _playerControllerList.Add(new AIPlayerController((Player)i, new AIBMobileJump(3, 1, 1), new AISQuality(), new AICProva()));
                        }
                        else
                        {
                            BTPlayerController bt = new BTPlayerController(i);
                            _playerControllerList.Add(bt);
                            ((Player)i).SetController(bt);
                        }
                    }
                }


                if (primo)
                {
                    var application = new CCApplication();
                    application.ApplicationDelegate = new GameAppDelegate(_terminateMsg);

                    SetContentView(application.AndroidContentView);

                    application.StartGame();
                    primo = false;
                }
                else
                {
                    lock (_terminateMsg) {
                        Monitor.Pulse(_terminateMsg);
                    }
                }

                if (BTManager.Instance.isSlave())
                {
                    BTManager.Instance.eventPackageReceived += terminateHandle;
                }
                else
                {
                    new Thread(finisher).Start();
                }
            }
        }