private static void CalculateRockCollisions(Board board, CollisionResults results) { board.PlayerOneShip.XPos = 2; if (PlayerOneIsTurningLeft(board)) { results.Collisions.Add(new Collision { CollisionPhase = CollisionPhase.PhaseTwo }); } }
public static CollisionResults Calculate(Board board) { var results = new CollisionResults() { ResultingBoard = board }; if (board.Rock != null) { CalculateRockCollisions(board, results); } if (PlayerOneIsTurningLeft(board)) { RotateShipLeft(board.PlayerOneShip); } var shipsMovingThroughOtherShipsPosition = GetShipsMovingThroughOtherShipsPosition(board); if (shipsMovingThroughOtherShipsPosition.Any()) { results.Collisions.Add(new Collision { CollisionPhase = CollisionPhase.PhaseOne }); if (shipsMovingThroughOtherShipsPosition.Count() == 1) { var shipMoving = shipsMovingThroughOtherShipsPosition.Single(); if (SpaceToBeBumpedToForPlayerTwoIsEmpty(board) && shipMoving == board.PlayerOneShip && shipMoving.Moving == Move.Forward) { if (PlayerOneIsBigger(board)) { PlayerOneWinsPlayerTwosSpace(board); } if (!PlayerTwoIsBigger(board)) { BumpPlayerTwo(board); } } } } else if (BothShipsContendingSameSquare(board)) { Ship winningShip = null; if (PlayerOneIsBigger(board)) { winningShip = board.PlayerOneShip; } if (PlayerTwoIsBigger(board)) { winningShip = board.PlayerTwoShip; } results.Collisions.Add( new Collision { CollisionPhase = CollisionPhase.PhaseOne, WinningShip = winningShip } ); } if (!results.Collisions.Any(x => x.WinningShip != board.PlayerOneShip)) { if (board.PlayerOneShip.Moving == Move.Forward) { board.PlayerOneShip.YPos++; } if (PlayerOneIsTurningLeft(board)) { SuccesfullyMovePlayerOneLeft(board); } } if (board.PlayerTwoShip != null && !results.Collisions.Any(x => x.WinningShip != board.PlayerTwoShip)) { if (board.PlayerTwoShip.Moving == Move.Forward) { board.PlayerTwoShip.YPos--; } } return(results); }