public void Set(ChessGame g) { idx = -1; move = null; total_moves = 0; if (g == null) { player = ChessGamePlayer. CreatePlayer (); return; } player = g.HasTag ("FEN") ? ChessGamePlayer. CreateFromFEN (g. GetTagValue ("FEN", null)) : ChessGamePlayer.CreatePlayer (); game = g; int n = game.Moves.Count; if (n > 0) { total_moves = n; } if (total_moves == 0) hasNext = false; else hasNext = true; }
private void WriteGame(ChessGame game) { GameSession session = new GameSession (); session.Set (game); string white = game.White; string black = game.Black; string result = game.Result; if (white == null) white = Catalog.GetString ("[White]"); if (black == null) black = Catalog.GetString ("[Black]"); if (result == null) result = Catalog. GetString ("Unknown"); printer.Font = fonts.titleFont; printer.PrintText (white + Catalog. GetString (" vs ") + black + "\n\n"); printer.Font = fonts.regularFont; printer.PrintText (Catalog. GetString ("Result: ") + result + "\n\n"); printer.Font = fonts.moveFont; int moveno = 1; if (game.HasTag ("FEN")) PrintImageForPosition (session.player); bool whitesTurn = true; bool whiteMoveComment = false; foreach (PGNChessMove move in game.Moves) { // print move if (move.Move == null) break; if (!session.HasNext ()) break; session.Next (); session.player.Move (session. CurrentMove); if (whitesTurn) { printer.PrintText (moveno + ". "); whitesTurn = false; } else { // black moveno++; whitesTurn = true; if (whiteMoveComment) { printer.PrintText ("\n" + moveno + "... "); whiteMoveComment = false; } } printer.PrintText (move.DetailedMove + " "); if (move.comment != null) { printer.LineBreak (); PrintImageForPosition (session.player); printer.Font = fonts.commentFont; printer.PrintText (move. comment); printer.Font = fonts.moveFont; whiteMoveComment = true; } } }