/// <summary> /// Starts the create table activity. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> void createClick(object sender, EventArgs e) { _create.Enabled = false; string [] names = new string[5]; names [0] = BTManager.Instance.GetLocalName(); if (names [0].Length > MainActivity.MAX_NAME_LENGHT) { names [0] = names [0].Substring(0, MainActivity.MAX_NAME_LENGHT); } names [1] = Resources.GetText(Resource.String.Default1); names [2] = Resources.GetText(Resource.String.Default2); names [3] = Resources.GetText(Resource.String.Default3); names [4] = Resources.GetText(Resource.String.Default4); string [] address = new string[4]; for (int i = 0; i < 4; ++i) { address [i] = Resources.GetText(Resource.String.none_add); } Intent inte = new Intent(this, typeof(CreateTabActivity)); GameProfile gp = new GameProfile(names, address, 0); gp.setIntent(inte); StartActivityForResult(inte, 1); }
/// <summary> /// Called on activity creation. /// </summary> /// <param name="bundle">Bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); int res = Intent.GetIntExtra("NewGame", 0); if (res == 1) { if (BTManager.Instance.isSlave()) { Intent serverIntent = new Intent(this, typeof(JoinTableActivity)); StartActivityForResult(serverIntent, 1); } else { Intent inte = new Intent(this, typeof(CreateTabActivity)); GameProfile gp = new GameProfile(Intent); gp.setIntent(inte); StartActivityForResult(inte, 1); } } else { BTManager.Instance.Reset(); } RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.Main); Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen); DisplayMetrics metrics = Resources.DisplayMetrics; int widthInDp = metrics.WidthPixels; int heightInDp = metrics.HeightPixels; _create = FindViewById <Button> (Resource.Id.create); _join = FindViewById <Button> (Resource.Id.select); _history = FindViewById <Button> (Resource.Id.history); _textLayout = FindViewById <RelativeLayout> (Resource.Id.TitleLayout); _buttonLayout = FindViewById <RelativeLayout> (Resource.Id.ButtonLatout); _imageLayout = FindViewById <RelativeLayout> (Resource.Id.ImageLayout); _imageLayout.LayoutParameters.Width = (int)(widthInDp * _FRACTION_WIDTH); _buttonLayout.LayoutParameters.Width = (int)(widthInDp * _FRACTION_WIDTH); _imageLayout.LayoutParameters.Height = (int)(heightInDp * _FRACTION_HEIGH); _buttonLayout.LayoutParameters.Height = (int)(heightInDp * _FRACTION_HEIGH); _textLayout.LayoutParameters.Height = heightInDp - _buttonLayout.LayoutParameters.Height; _create.Enabled = true; _join.Enabled = true; _history.Enabled = true; _create.Click += createClick; _join.Click += joinClick; _history.Click += historyClick; }
/// <summary> /// Starts the game. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> void Start_Game(object sender, EventArgs e) { if (getBTNumber() - BTManager.Instance.getNumConnected() == 0) { SetTitle(Resource.String.starting); BTManager.Instance.eventLocalMessageReceived -= handleLocalMessage; BTManager.Instance.eventPackageReceived -= handlePackage; string [] names = new string[5]; for (int i = 0; i < 5; ++i) { names [i] = _pl [i].Text; } int dealer = 0; for (int i = 0; i < 5; ++i) { if (_radioDealer [i].Checked) { dealer = i; break; } } Intent inte = new Intent(); GameProfile gp = new GameProfile(names, _addr, dealer); gp.setIntent(inte); SetResult(Result.Ok, inte); BTManager.Instance.StopListen(); Finish(); } else { Toast.MakeText(this, "Waiting for missing connection", ToastLength.Short).Show(); } }
/// <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(); }
/// <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(); } } }