/// <summary> /// Convierte el resultado final del juego /// </summary> private MovementGameEndModel ConvertResultMovement(ResultMovementModel movement) { MovementGameEndModel movementEnd = new MovementGameEndModel(ConvertTurn(movement.Turn), movement.Content); // Convierte los datos básicos ConvertMovementBase(movement, movementEnd); // Devuelve el movimiento return(movementEnd); }
/// <summary> /// Lee los movimientos /// </summary> private SentenceBaseModel ReadMovements(IEnumerator <SentenceBaseModel> sentenceEnumerator, SentenceBaseModel previousSentence, List <BaseMovementModel> movements) { SentenceBaseModel sentence = previousSentence; BaseMovementModel lastMovement = null; TurnModel lastTurn = null; // Añade los movimientos do { // Trata la sentencia switch (sentence) { case SentenceTurnNumberModel sentenceTurn: lastMovement = null; lastTurn = new TurnModel(sentenceTurn.Content, TurnModel.TurnType.White); break; case SentenceTurnPlayModel sentencePlay: if (lastTurn == null) { sentence = new SentenceErrorModel($"There is not turn to add the play {sentencePlay.Content}"); } else { // Crea el movimiento lastMovement = new PieceMovementModel(lastTurn, sentencePlay.Content); // Añade el movimiento movements.Add(lastMovement); } break; case SentenceTurnResultModel sentenceResult: if (lastTurn == null) { sentence = new SentenceErrorModel($"There is not turn to add the result {sentenceResult.Content}"); } else { // Crea el movimiento lastMovement = new ResultMovementModel(lastTurn, sentence.Content); // Añade el movimiento movements.Add(lastMovement); } break; case SentenceTurnInformationModel sentenceInformation: if (lastMovement == null) { sentence = new SentenceErrorModel($"There is not movement to add the information {sentenceInformation.Content}"); } else { lastMovement.Info.Add(new InfoMovementModel(sentence.Content)); } break; case SentenceCommentModel sentenceComment: if (lastMovement == null) { sentence = new SentenceErrorModel($"There is not sentence to add the comment {sentenceComment.Content}"); } else { lastMovement.Comments.Add(sentenceComment.Content); } break; case SentenceTurnStartVariationModel sentenceVariation: if (lastMovement == null) { sentence = new SentenceErrorModel("There is not sentence to add a variation"); } else { VariationModel variation = new VariationModel(lastMovement); // Limpia esta sentencia del enumerado sentence = GetNextSentence(sentenceEnumerator); // Añade los comentarios y la información a la variación while (sentence is SentenceTurnInformationModel || sentence is SentenceCommentModel) { // Añade la información de la sentencia switch (sentence) { case SentenceTurnInformationModel sentenceInfo: variation.Info.Add(new InfoMovementModel(sentenceInfo.Content)); break; case SentenceCommentModel sentenceComment: variation.Comments.Add(sentenceComment.Content); break; } // Pasa a la siguiente sentencia sentence = GetNextSentence(sentenceEnumerator); } // Lee los movimientos de la variación sentence = ReadMovements(sentenceEnumerator, sentence, variation.Movements); // Añade la variación a la colección if (variation.Movements.Count > 0) { lastMovement.Variations.Add(variation); } // Pasa a la siguiente sentencia if (!(sentence is SentenceTurnEndVariationModel)) { sentence = new SentenceErrorModel("Can't find the end variation sentence"); } } break; } // Pasa a la siguiente sentencia if (!(sentence is SentenceErrorModel)) { sentence = GetNextSentence(sentenceEnumerator); } }while (!(sentence is SentenceEndModel) && !(sentence is SentenceErrorModel) && !(sentence is SentenceTagModel) && !(sentence is SentenceTurnEndVariationModel)); // Devuelve la última sentencia leída return(sentence); }