public void SetPlayer(Player player) { // Associate the new instance _player = player; player._grid.NextPieceChangedEvent += PostInvalidate; _nextPiece = new PieceView(player._grid._nextPiece, false); }
public void SetPlayer(Player player) { // Associate the new instance _player = player; // Recreate the proposed pieces for(int i = 0; i < Constants.NbProposedPiece; i++) { _proposedPieces[i] = new PieceView(player._proposedPieces[i], false); } // Now we can select one piece to send to the other player selectPiece(0); }
//-------------------------------------------------------------- // PROTECTED METHODS //-------------------------------------------------------------- // Init the model and the view for a one player game protected void initGame() { LinearLayout gameLayout = FindViewById<LinearLayout>(Resource.Id.layoutGame); // Test if the view is created so we can resize the buttons if(gameLayout.ViewTreeObserver.IsAlive) { gameLayout.ViewTreeObserver.AddOnGlobalLayoutListener(this); } // Creation of the model _player1 = new Player(User.Instance.UserName); // And the view _player1View = new PlayerView(_player1); GridView myGrid = FindViewById<GridView>(Resource.Id.PlayerGridView); myGrid.Init(_player1._grid); _player1View._gridView = myGrid; TextView player1name = FindViewById<TextView> (Resource.Id.player1name); TextView player1score = FindViewById<TextView> (Resource.Id.player1score); TextView player1level = FindViewById<TextView> (Resource.Id.player1level); TextView player1rows = FindViewById<TextView> (Resource.Id.player1rows); _player1View.SetViews(player1name, player1score, player1level, player1rows); associateButtonsEvent(); }
//-------------------------------------------------------------- // EVENT CATCHING METHODS //-------------------------------------------------------------- protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetResult(Result.Ok); if(!Network.Instance.Connected) { // If we are trying to start a multi activity and we are not connected to someone, we stop Finish(); } // Creation of the model _player2 = new Player(Intent.GetStringExtra(Utils.OpponentNameExtra)); // And the view _player2View = new PlayerView(_player2); // Set our view from the "main" layout resource SetContentView(Resource.Layout.GameMulti); initGame(); GridView gridOpponent = FindViewById<GridView>(Resource.Id.OpponentGridView); gridOpponent.Init(_player2._grid); _player2View._gridView = gridOpponent; TextView player2name = FindViewById<TextView> (Resource.Id.player2name); TextView player2score = FindViewById<TextView> (Resource.Id.player2score); TextView player2level = FindViewById<TextView> (Resource.Id.player2level); TextView player2rows = FindViewById<TextView> (Resource.Id.player2rows); _player2View.SetViews(player2name, player2score, player2level, player2rows); ProposedPieceView viewProposed = FindViewById<ProposedPieceView>(Resource.Id.player2piece); viewProposed.SetPlayer(_player1); // Hook on network event Network.Instance.EraseAllEvent(); Network.Instance.UsualGameMessage += UpdateOpponentView; Network.Instance.PiecePutMessage += OpponentPiecePut; Network.Instance.NextPieceMessage += _player1.interpretMessage; Network.Instance.PauseMessage += pauseGame; Network.Instance.ResumeMessage += resumeGame; Network.Instance.ScoreMessage += OnReceiveScoreMessage; Network.Instance.EndMessage += OnReceiveEndMessage; Network.Instance.ConnectionLostEvent += OnLostConnection; Network.Instance.NewGameMessage += OnReceiveNewGame; Network.Instance.WriteEvent += WriteMessageEventReceived; _gameState = GameState.Play; startGame(); }
//-------------------------------------------------------------- // CONSTRUCTORS //-------------------------------------------------------------- public PlayerView(Player player) { // Associate the instance _player = player; }