public IMove CreateByToken(Token token, IEnumerable<Field> gameBoardFields) { if (token is AdvocatToken) { return new Winkelzug(gameBoardFields); } return new Paragraphenzug(gameBoardFields); }
public override MoveResult PerformMove(Field field) { MoveResult result = MoveResult.CreateValidResult(); this.moves.Add(field); this.IsFinished = false; if (this.MovesFromStartPosition()) { if (field.HasToken) { this.IsValid = true; this.playingAdvocatToken = field.Token; this.moves.ElementAt(0).Token = new NoToken(); } else { this.IsValid = false; this.ClearMoves(); } } else if (this.MovedToCornerPosition()) { if (this.CheckIsValid()) { this.IsValid = true; this.moves.ElementAt(1).Token = new ParagraphToken {Color = this.playingAdvocatToken.Color}; } else { this.IsValid = false; this.SetPlayingAdvocatTokenAt(this.moves[0]); result = MoveResult.CreateInvalidResult("Winkelzug ist nicht gültig!"); this.ClearMoves(); } } else if (this.MovedToEndPosition()) { if (this.CheckIsValid()) { this.IsValid = true; this.moves.ElementAt(2).Token = new AdvocatToken {Color = this.playingAdvocatToken.Color}; } else { this.IsValid = false; this.SetPlayingAdvocatTokenAt(this.moves[0]); this.RemoveTokenFrom(this.moves[1]); result = MoveResult.CreateInvalidResult("Winkelzug ist nicht gültig!"); } this.ClearMoves(); this.IsFinished = true; } return result; }
public override MoveResult PerformMove(Field field) { MoveResult result = MoveResult.CreateValidResult(); if (this.MovedToPossibleEndPosition() && this.MoveCanBeContinued() && FinishMoveRequested(field)) { this.IsFinished = true; this.ClearMoves(); return result; } this.moves.Add(field); this.IsFinished = false; if (this.MovesFromStartPosition()) { if (field.HasToken) { this.playingParagraphToken = field.Token; this.RemoveTokenFrom(this.moves.ElementAt(0)); } else { this.ClearMoves(); } } else if (this.MovedToPossibleEndPosition()) { var actualPosition = this.moves.Last(); var previousPosition = this.moves.ElementAt(this.moves.Count - 2); if (this.CheckIsValid(previousPosition, actualPosition)) { this.SetPlayingParagraphTokenAt(actualPosition); this.RemoveTokenFrom(previousPosition); this.RemoveTokenFrom(this.GetJumpedOverField(previousPosition, actualPosition)); } else { this.SetPlayingParagraphTokenAt(previousPosition); result = MoveResult.CreateInvalidResult("Paragraphenzug ist nicht gültig!"); } if (!this.MoveCanBeContinued()) { this.IsFinished = true; this.playingParagraphToken = new NoToken(); this.ClearMoves(); } } return result; }