void Awake() { cubeScript = cube.GetComponent<MoveTest>(); bookScript = book.GetComponent<BookMove>(); foodScript = food.GetComponent<FoodMove>(); foodScript.mainScipt = this; cubeAnim = cube.GetComponentInChildren<Animation>(); foreach (AnimationState state in cubeAnim) { state.speed = 0.5f; } }
private string GetMoveDisplay(BookMove bm) { string moveDisplay = string.Empty; App.Model.Move m = App.Model.Move.NewMove(); m.Game = this.Game; m.From = bm.FromSquare; m.To = bm.ToSquare; m.PieceStr = bm.MovePiece; m.MoveFlags = bm.BookMoveFlags; moveDisplay = m.Notation; moveDisplay = moveDisplay.Substring(moveDisplay.IndexOf(".") + 1); return(moveDisplay); }
private void tsDontPlayTournamentMove_Click(object sender, EventArgs e) { // Mark Red int rowIndex = dgvOpeningBook.SelectedCells[0].RowIndex; if (IsValidOpeningBookCellSelected(rowIndex, 0)) { this.Game.Book.IsOpeningBookChanged = true; DataRow dr = this.Game.Book.BookMoves.DataTable.DefaultView[rowIndex].Row; BookMove m = new BookMove(dr); if (m.Flags.NotInTournament) { m.Flags.NotInTournament = false; } else { m.Flags.NotInTournament = true; m.Flags.IsMainMove = false; } } }
private void UpdateCurrentCell(DataGridViewCellFormattingEventArgs e) { try { //// set columns other than first column, to be seems like un-selectable if (dgvOpeningBook.Columns[e.ColumnIndex].DataPropertyName != BookMove.ColumnTo) { e.CellStyle.BackColor = SystemColors.Control; e.CellStyle.ForeColor = Color.Black; e.CellStyle.SelectionBackColor = SystemColors.Control; e.CellStyle.SelectionForeColor = Color.Black; } if (this.Game.Book == null || this.Game.Book.BookMoves == null) { return; } if (e.RowIndex >= this.Game.Book.BookMoves.DataTable.DefaultView.Count) { return; } BookMove bm = new BookMove(this.Game.Book.BookMoves.DataTable.DefaultView[e.RowIndex].Row); if (bm == null) { return; } bool isItalic = bm.BookMoveFlags.Contains("T"); if (isItalic) { if (e.RowIndex >= 0 && dgvOpeningBook.Columns[e.ColumnIndex].DataPropertyName == BookMove.ColumnTo) { e.CellStyle.Font = new Font(e.CellStyle.Font, FontStyle.Italic); if (bm.IsWhite) { e.Value = bm.MoveNumber + "." + GetMoveDisplay(bm); } else { e.Value = bm.MoveNumber + "..." + GetMoveDisplay(bm); } } else { e.Value = ""; } return; } if (e.RowIndex >= 0 && dgvOpeningBook.Columns[e.ColumnIndex].DataPropertyName == BookMove.ColumnTo) // for Notations(move) column { if (bm.IsWhite) { e.Value = bm.MoveNumber + "." + GetMoveDisplay(bm); } else { e.Value = bm.MoveNumber + "..." + GetMoveDisplay(bm); } bool isMainMove = bm.Flags.IsMainMove; bool dontPlayInTournament = bm.Flags.NotInTournament; if (isMainMove) { e.CellStyle.ForeColor = Color.Green; } else if (dontPlayInTournament) { e.CellStyle.ForeColor = Color.Red; } switch (bm.MoveType) { case "": if (!isMainMove && !dontPlayInTournament) { e.CellStyle.ForeColor = Color.Black; } break; case "?": if (!isMainMove && !dontPlayInTournament) { e.CellStyle.ForeColor = Color.Blue; } e.Value = e.Value + " ?"; break; default: break; } } else if (e.RowIndex >= 0 && dgvOpeningBook.Columns[e.ColumnIndex].DataPropertyName == BookMove.ColumnWinCount) // for "N" column { if (updateNoOfGamesHeaderRequired) { int totalGames = bm.WinCount + Convert.ToInt32(bm.DrawCount) + Convert.ToInt32(bm.LostCount); string noOfGames = totalGames.ToString(); updateNoOfGamesHeaderRequired = false; } } else if (e.RowIndex >= 0 && dgvOpeningBook.Columns[e.ColumnIndex].DataPropertyName == BookMove.ColumnPercentage)// for first "%" column { int whiteWin = 0; double whiteDraw = 0; if (bm.DrawCount.ToString() == "0.5") { bm.DrawCount = 1; } int noOfGames = bm.WinCount + Convert.ToInt32(bm.DrawCount) + Convert.ToInt32(bm.LostCount); string strWhiteWin = bm.WinCount.ToString(); string strWhiteDraw = bm.DrawCount.ToString(); double whitePercentage = 0; double blackPercentage; if (!string.IsNullOrEmpty(strWhiteWin)) { whiteWin = Convert.ToInt32(strWhiteWin); } if (!string.IsNullOrEmpty(strWhiteDraw)) { whiteDraw = Convert.ToDouble(strWhiteDraw); } bool isWhite; if (this.Game.Flags.IsFirtMove) { isWhite = this.Game.InitialIsWhite; } else { isWhite = this.Game.InitialIsWhite; } if (isWhite) { if ((whiteWin + whiteDraw) < 1) { whitePercentage = 0; } else { whitePercentage = Math.Round(((whiteWin + whiteDraw) / noOfGames) * 100, 0); } e.Value = whitePercentage; if (updatePercentageHeaderRequired) { updatePercentageHeaderRequired = false; } } else { if ((noOfGames - (whiteWin + whiteDraw)) == 0) { blackPercentage = 0; } else { blackPercentage = Math.Round(((noOfGames - (whiteWin + whiteDraw)) / noOfGames) * 100, 0); } e.Value = blackPercentage; if (updatePercentageHeaderRequired) { dgvOpeningBook.Columns[e.ColumnIndex].HeaderText = "%" + "(" + blackPercentage + ")"; updatePercentageHeaderRequired = false; } } } else if (e.RowIndex >= 0 && dgvOpeningBook.Columns[e.ColumnIndex].DataPropertyName == BookMove.ColumnFact) // for "Fact" column { int fact = Convert.ToInt32(e.Value); if (fact < 0) { e.CellStyle.ForeColor = Color.Red; } else if (fact == 0) { e.CellStyle.ForeColor = Color.Black; } else if (fact > 0) { e.CellStyle.ForeColor = Color.Green; } } } catch (Exception ex) { TestDebugger.Instance.WriteError(ex); throw ex; } }