public ActionResult Load(int id) { /*incarcam tabla*/ ActiveBoard board = BoardManager.Instance.GetBoard(id); return(Json(board)); }
void newPanel_Click(object sender, EventArgs e) { if (VsAI[2] || (VsAI[0] && VsAI[1] == ActiveBoard.WTurn)) { return; } Panel pan = sender as Panel; if (pan is null) { return; } Piece pic = ActiveBoard.Pieces[pan.Location.Y / tilesize, pan.Location.X / tilesize]; //Select piece if valid if (!(pic is Empty) && pic.Player.IsW == ActiveBoard.WTurn) { SelectedPiece = new int[] { pic.PosX, pic.PosY }; PossibleBoards = ActiveBoard.GenMoveByType(pic, true); PossibleMoves = new List <int[]>(); foreach (Board b in PossibleBoards) { PossibleMoves.Add(new int[] { b.RecentMove[0], b.RecentMove[1] }); } PanelUpdate(); return; } //Move if valid if (SelectedPiece != null) { for (int i = 0; i < PossibleMoves.Count; i++) { if ((pic.PosX != PossibleMoves[i][0]) || (pic.PosY != PossibleMoves[i][1])) { continue; } //Only update panels as needed UpdateImages(PossibleBoards[i]); SelectedPiece = null; PossibleMoves = null; ActiveBoard = PossibleBoards[i]; break; } return; } }
/// <summary> /// Changes the open leaderboard to the specified board /// </summary> /// <param name="changeTo"></param> void ChangeBoard(ActiveBoard changeTo) { Transform content = LeaderboardView.GetComponentInChildren <ContentSizeFitter>().transform; if (entries == null) { entries = new List <GameObject>(); } for (int i = entries.Count - 1; i >= 0; i--) { Destroy(entries[i]); entries.RemoveAt(i); } Leaderboard current; switch (changeTo) { case ActiveBoard.All: if (allBut) { allBut.GetComponent <Image>().color = SelectedStyle.ActiveColor; } if (weekBut) { weekBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } if (dayBut) { dayBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } current = OpenGroup.AllTime; break; case ActiveBoard.Week: if (allBut) { allBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } if (weekBut) { weekBut.GetComponent <Image>().color = SelectedStyle.ActiveColor; } if (dayBut) { dayBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } current = OpenGroup.Weekly; break; case ActiveBoard.Day: if (allBut) { allBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } if (weekBut) { weekBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } if (dayBut) { dayBut.GetComponent <Image>().color = SelectedStyle.ActiveColor; } current = OpenGroup.Daily; break; default: if (allBut) { allBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } if (weekBut) { weekBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } if (dayBut) { dayBut.GetComponent <Image>().color = SelectedStyle.InactiveColor; } current = OpenGroup.AllTime; break; } positionToSet = 0; for (int i = 0; i < current.board.Count; i++) { GameObject go = Instantiate(SelectedStyle.Prefab_Entry, content); Text[] texts = go.GetComponentsInChildren <Text>(); if (i == 0) { texts[0].color = Color.black; texts[0].transform.parent.GetComponent <Image>().color = SelectedStyle.GoldColor; } else if (i == 1) { texts[0].color = Color.black; texts[0].transform.parent.GetComponent <Image>().color = SelectedStyle.SilverColor; } else if (i == 2) { texts[0].color = Color.black; texts[0].transform.parent.GetComponent <Image>().color = SelectedStyle.BronzeColor; } else { texts[0].color = Color.white; texts[0].transform.parent.GetComponent <Image>().color = SelectedStyle.BasicColor; } if (current.board[i].ID == LBM.playerEntry.ID) { for (int k = 0; k < texts.Length; k++) { texts[k].color = Color.green; } float height = SelectedStyle.Prefab_Entry.GetComponent <RectTransform>().sizeDelta.y; positionToSet = 5 + (i * height + 5); } texts[0].text = (i + 1).ToString(); texts[1].text = current.board[i].Name; switch (SelectedStyle.OutputFormat) { case outputForm.Time: float score = current.board[i].Score; int m = Mathf.FloorToInt(score / 60); int s = Mathf.RoundToInt(score - (m * 60)); texts[2].text = m.ToString() + ":" + s.ToString("d2"); break; case outputForm.Score: texts[2].text = current.board[i].Score.ToString("n0"); break; default: break; } entries.Add(go); } Invoke("SetScroll", 0.1f); }
private void Button_Click(object sender, EventArgs e) { if (!(currentSquare is null && priorSquare is null)) { Board board; try { if (ActiveBoard.WTurn != ActiveBoard.Pieces[priorSquare[1], priorSquare[0]].Player.IsW) { throw new Exception("Not your turn"); } List <Board> possibilities = ActiveBoard.GenMoves(ActiveBoard.WTurn, false); //Need to redo (the pieces can't be the same if they're on different squares lol) foreach (Board b in possibilities) { if (b.Pieces[priorSquare[1], priorSquare[0]] is Empty && b.Pieces[currentSquare[1], currentSquare[0]].ValidMoveType(ActiveBoard.Pieces[priorSquare[1], priorSquare[0]])) //If the piece moved is the same on both boards then the boards are the same { board = b; goto noerror; } } //If the board was not generated, it is invalid throw new Exception("Not a valid move"); noerror: //If king is in check the move is invalid foreach (Piece p in board.Pieces) { if (p is King && p.Player.IsW == ActiveBoard.WTurn) { if ((p as King).Check(board)) { board = null; throw new Exception("Can't leave king in check"); } } } } catch (Exception ex) { MessageBox.Show("Invalid move: " + ex.ToString()); return; } ActiveBoard = board; //Reset colors and then the prior/current squares if (priorSquare[0] % 2 == 0) { BoardPanel[priorSquare[0], priorSquare[1]].BackColor = priorSquare[1] % 2 != 0 ? Color.Black : Color.White; } else { BoardPanel[priorSquare[0], priorSquare[1]].BackColor = priorSquare[1] % 2 != 0 ? Color.White : Color.Black; } if (currentSquare[0] % 2 == 0) { BoardPanel[currentSquare[0], currentSquare[1]].BackColor = currentSquare[1] % 2 != 0 ? Color.Black : Color.White; } else { BoardPanel[currentSquare[0], currentSquare[1]].BackColor = currentSquare[1] % 2 != 0 ? Color.White : Color.Black; } priorSquare = null; currentSquare = null; PanelUpdate(); } }
/// <summary> /// Loads the leaderboard ui to the specified board /// </summary> /// <param name="Board"></param> void LoadLeaderboard(LeaderboardGroup Board) { OpenGroup = Board; if ((Board.EnableAllTime ? 1 : 0) + (Board.EnableWeekly ? 1 : 0) + (Board.EnableDaily ? 1 : 0) == 1) { if (viewButtonHolder == null) { viewButtonHolder = LeaderboardView.GetComponentInChildren <HorizontalLayoutGroup>().gameObject; } viewButtonHolder.SetActive(false); } else { if (viewButtonHolder == null) { viewButtonHolder = LeaderboardView.GetComponentInChildren <HorizontalLayoutGroup>().gameObject; } viewButtonHolder.SetActive(true); } for (int i = viewButtonHolder.transform.childCount - 1; i >= 0; i--) { Destroy(viewButtonHolder.transform.GetChild(i).gameObject); } if (Board.EnableAllTime) { Button but = Instantiate(SelectedStyle.Prefab_Button, viewButtonHolder.transform).GetComponent <Button>(); but.GetComponentInChildren <Text>().text = SelectedStyle.AllName; but.onClick.AddListener(() => ChangeBoard(0)); but.GetComponent <Image>().color = SelectedStyle.ActiveColor; allBut = but; } if (Board.EnableWeekly) { Button but = Instantiate(SelectedStyle.Prefab_Button, viewButtonHolder.transform).GetComponent <Button>(); but.GetComponentInChildren <Text>().text = SelectedStyle.WeekName; but.onClick.AddListener(() => ChangeBoard(1)); weekBut = but; if (!Board.EnableAllTime) { activeLeaderboard = ActiveBoard.Week; but.GetComponent <Image>().color = SelectedStyle.ActiveColor; } } if (Board.EnableDaily) { Button but = Instantiate(SelectedStyle.Prefab_Button, viewButtonHolder.transform).GetComponent <Button>(); but.GetComponentInChildren <Text>().text = SelectedStyle.DayName; but.onClick.AddListener(() => ChangeBoard(2)); dayBut = but; if (!Board.EnableAllTime && !Board.EnableWeekly) { activeLeaderboard = ActiveBoard.Day; but.GetComponent <Image>().color = SelectedStyle.ActiveColor; } } Button[] allButtons = LeaderboardView.GetComponentsInChildren <Button>(); if (LBM.Leaderboards.Count > 1) { allButtons[allButtons.Length - 1].onClick.AddListener(() => OpenSelect()); allButtons[allButtons.Length - 1].GetComponentInChildren <Text>().text = "Back"; } else { allButtons[allButtons.Length - 1].onClick.AddListener(() => CloseLeaderboard()); allButtons[allButtons.Length - 1].GetComponentInChildren <Text>().text = "Exit"; } ChangeBoard((int)activeLeaderboard); }