private void CapsuleClicked(object sender, EventArgs e) { CapsuleView cv = (CapsuleView)sender; if (cv.GetDotState() == DotState.Empty && GameManager.GetGameManager().GetIsPlayerTurn()) { cv.SetCapsuleState(DotState.Player); GameManager.GetGameManager().GetGameGraph().GetFlowerByBoardCordinate( cv.GetCordinate().BoardX, cv.GetCordinate().BoardY).SetFlowerState(DotState.Player); Task.Run(() => { GameManager.GetGameManager().SwitchTurn(); tvMovesCounter.Text = "Moves: " + GameManager.GetGameManager().GetMovesConter(); }); } }
private void DrawSingleCapsuleView(int x, int y, int radius, RelativeLayout boardLayout) { CapsuleView cv = new CapsuleView(this, radius, x, y); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( 2 * cv.Radius, 2 * cv.Radius); lp.LeftMargin = x * (2 * cv.Radius + CapsuleView.SPACE) + cv.Radius; lp.TopMargin = y * (2 * cv.Radius) + cv.Radius; if (y % 2 == 1) { lp.LeftMargin += cv.Radius; } lp.TopMargin += CapsuleView.OFFSET_TOP; cv.LayoutParameters = lp; boardLayout.AddView(cv); cv.Click += CapsuleClicked; board[x, y] = cv; }
private void DrawBoard() { board = new CapsuleView[9, 9]; GameManager.GetGameManager().GetGameGraph().ConnectBoardFlowers(); RelativeLayout boardLayout = (RelativeLayout)FindViewById(Resource.Id.BoardLayout); //9 spaces and 9 circles(18 radius) + 3 radius for spacing the line, //spacing 2 radius for big, 1 for small DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager.DefaultDisplay.GetRealMetrics(displayMetrics); int screenWidth = displayMetrics.WidthPixels; int radius = (screenWidth - 9 * CapsuleView.SPACE) / 21; for (int y = 0; y < board.GetLength(1); y++) { for (int x = 0; x < board.GetLength(0); x++) { //async drawing //Task.Run( () => { // DrawSingleCapsuleView(x, y, radius, boardLayout); //}); //DrawSingleCapsuleView(x, y, radius, boardLayout); CapsuleView cv = new CapsuleView(this, radius, x, y); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( 2 * cv.Radius, 2 * cv.Radius); lp.LeftMargin = x * (2 * cv.Radius + CapsuleView.SPACE) + cv.Radius; lp.TopMargin = y * (2 * cv.Radius) + cv.Radius; if (y % 2 == 1) { lp.LeftMargin += cv.Radius; } lp.TopMargin += CapsuleView.OFFSET_TOP; cv.LayoutParameters = lp; boardLayout.AddView(cv); cv.Click += CapsuleClicked; board[x, y] = cv; } } }