public bool GetWinningPlayer(out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition) { bool hasWinner; for (var xPosition = TTTMoveXPosition.Left; xPosition <= TTTMoveXPosition.Right; xPosition++) { hasWinner = GetWinningPlayer (out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPosition); if (hasWinner) return hasWinner; } for (var yPosition = TTTMoveYPosition.Top; yPosition <= TTTMoveYPosition.Bottom; yPosition++) { hasWinner = GetWinningPlayer (out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, yPosition); if (hasWinner) return hasWinner; } hasWinner = GetWinningPlayer (out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, 1); if (hasWinner) return hasWinner; hasWinner = GetWinningPlayer (out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, -1); return hasWinner; }
public TTTMove (TTTMovePlayer player, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { Player = player; XPosition = xPosition; YPosition = yPosition; }
void tapGame(UITapGestureRecognizer gestureRecognizer) { if (gestureRecognizer.State == UIGestureRecognizerState.Recognized && DidSelect != null) { CGPoint point = gestureRecognizer.LocationInView(this); CGRect bounds = Bounds; CGPoint normalizedPoint = point; normalizedPoint.X -= bounds.X + bounds.Size.Width / 2; normalizedPoint.X *= 3 / bounds.Size.Width; normalizedPoint.X = (float)Math.Round(normalizedPoint.X); normalizedPoint.X = (float)Math.Max(normalizedPoint.X, -1); normalizedPoint.X = (float)Math.Min(normalizedPoint.X, 1); TTTMoveXPosition xPosition = (TTTMoveXPosition)(int)normalizedPoint.X; normalizedPoint.Y -= bounds.Y + bounds.Size.Height / 2; normalizedPoint.Y *= 3 / bounds.Size.Height; normalizedPoint.Y = (float)Math.Round(normalizedPoint.Y); normalizedPoint.Y = (float)Math.Max(normalizedPoint.Y, -1); normalizedPoint.Y = (float)Math.Min(normalizedPoint.Y, 1); TTTMoveYPosition yPosition = (TTTMoveYPosition)(int)normalizedPoint.Y; if (CanSelect == null || CanSelect(this, xPosition, yPosition)) { DidSelect(this, xPosition, yPosition); } } }
public TTTMove(TTTMovePlayer player, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { Player = player; XPosition = xPosition; YPosition = yPosition; }
public void DidSelect(TTTGameView gameView, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { UIView.Animate (0.3, delegate { gameView.Game.AddMove (xPosition, yPosition); gameView.UpdateGameState (); saveProfile (); updateBackground (); }); }
public bool CanAddMove (TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { if (Result != TTTGameResult.InProgress) return false; TTTMovePlayer player = TTTMovePlayer.None; return !hasMove (xPosition, yPosition, ref player); }
public void DidSelect(TTTGameView gameView, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { UIView.Animate(0.3, delegate { gameView.Game.AddMove(xPosition, yPosition); gameView.UpdateGameState(); saveProfile(); updateBackground(); }); }
PointF pointForPosition(TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { RectangleF bounds = Bounds; PointF point = new PointF(bounds.X + bounds.Size.Width / 2, bounds.Y + bounds.Size.Height / 2); point.X += (int)xPosition * bounds.Size.Width / 3; point.Y += (int)yPosition * bounds.Size.Height / 3; return(point); }
CGPoint pointForPosition(TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { CGRect bounds = Bounds; CGPoint point = new CGPoint(bounds.X + bounds.Size.Width / 2, bounds.Y + bounds.Size.Height / 2); point.X += (int)xPosition * bounds.Size.Width / 3; point.Y += (int)yPosition * bounds.Size.Height / 3; return(point); }
bool GetWinningPlayer(out TTTMovePlayer playerOut, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, TTTMoveXPosition[] xPositions, TTTMoveYPosition[] yPositions) { bool moveExists = false; TTTMovePlayer player = TTTMovePlayer.None; for (int n = 0; n < TTTMove.SidePositionsCount; n++) { TTTMovePlayer newPlayer = TTTMovePlayer.None; bool newHasMove = hasMove(xPositions [n], yPositions [n], ref newPlayer); if (newHasMove) { if (moveExists) { if (player != newPlayer) { moveExists = false; break; } } else { moveExists = true; player = newPlayer; } } else { moveExists = false; break; } } if (moveExists) { playerOut = player; startXPosition = xPositions [0]; startYPosition = yPositions [0]; endXPosition = xPositions [TTTMove.SidePositionsCount - 1]; endYPosition = yPositions [TTTMove.SidePositionsCount - 1]; } else { playerOut = TTTMovePlayer.None; startXPosition = TTTMoveXPosition.Center; startYPosition = TTTMoveYPosition.Center; endXPosition = TTTMoveXPosition.Center; endYPosition = TTTMoveYPosition.Center; } return(moveExists); }
public bool CanAddMove(TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { if (Result != TTTGameResult.InProgress) { return(false); } TTTMovePlayer player = TTTMovePlayer.None; return(!hasMove(xPosition, yPosition, ref player)); }
bool hasMove (TTTMoveXPosition xPosition, TTTMoveYPosition yPosition, ref TTTMovePlayer player) { foreach (var move in Moves) { if (move.XPosition == xPosition && move.YPosition == yPosition) { player = move.Player; return true; } } return false; }
public void AddMove (TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { if (!CanAddMove (xPosition, yPosition)) return; TTTMove move = new TTTMove (currentPlayer, xPosition, yPosition); Moves.Add (move); currentPlayer = currentPlayer == TTTMovePlayer.Me ? TTTMovePlayer.Enemy : TTTMovePlayer.Me; updateGameResult (); }
bool hasMove(TTTMoveXPosition xPosition, TTTMoveYPosition yPosition, ref TTTMovePlayer player) { foreach (var move in Moves) { if (move.XPosition == xPosition && move.YPosition == yPosition) { player = move.Player; return(true); } } return(false); }
public void AddMove(TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { if (!CanAddMove(xPosition, yPosition)) { return; } TTTMove move = new TTTMove(currentPlayer, xPosition, yPosition); Moves.Add(move); currentPlayer = currentPlayer == TTTMovePlayer.Me ? TTTMovePlayer.Enemy : TTTMovePlayer.Me; updateGameResult(); }
bool GetWinningPlayer(out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, TTTMoveYPosition yPosition) { TTTMoveYPosition[] yPositions = new TTTMoveYPosition[TTTMove.SidePositionsCount]; for (int n = 0; n < TTTMove.SidePositionsCount; n++) { yPositions [n] = yPosition; } TTTMoveXPosition[] xPositions = new TTTMoveXPosition[TTTMove.SidePositionsCount]; xPositions [0] = TTTMoveXPosition.Left; xPositions [1] = TTTMoveXPosition.Center; xPositions [2] = TTTMoveXPosition.Right; return(GetWinningPlayer(out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPositions, yPositions)); }
bool GetWinningPlayer(out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, int direction) { TTTMoveXPosition[] xPositions = new TTTMoveXPosition[TTTMove.SidePositionsCount]; TTTMoveYPosition[] yPositions = new TTTMoveYPosition[TTTMove.SidePositionsCount]; int n = 0; for (var xPosition = TTTMoveXPosition.Left; xPosition <= TTTMoveXPosition.Right; xPosition++) { xPositions [n] = xPosition; yPositions [n] = (TTTMoveYPosition)((int)xPosition * direction); n++; } return(GetWinningPlayer(out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPositions, yPositions)); }
bool GetWinningPlayer (out TTTMovePlayer playerOut, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, TTTMoveXPosition[] xPositions, TTTMoveYPosition[] yPositions) { bool moveExists = false; TTTMovePlayer player = TTTMovePlayer.None; for (int n = 0; n < TTTMove.SidePositionsCount; n++) { TTTMovePlayer newPlayer = TTTMovePlayer.None; bool newHasMove = hasMove (xPositions [n], yPositions [n], ref newPlayer); if (newHasMove) { if (moveExists) { if (player != newPlayer) { moveExists = false; break; } } else { moveExists = true; player = newPlayer; } } else { moveExists = false; break; } } if (moveExists) { playerOut = player; startXPosition = xPositions [0]; startYPosition = yPositions [0]; endXPosition = xPositions [TTTMove.SidePositionsCount - 1]; endYPosition = yPositions [TTTMove.SidePositionsCount - 1]; } else { playerOut = TTTMovePlayer.None; startXPosition = TTTMoveXPosition.Center; startYPosition = TTTMoveYPosition.Center; endXPosition = TTTMoveXPosition.Center; endYPosition = TTTMoveYPosition.Center; } return moveExists; }
bool GetWinningPlayer(out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, TTTMoveXPosition xPosition) { TTTMoveXPosition[] xPositions = new TTTMoveXPosition[TTTMove.SidePositionsCount]; for (int n = 0; n < TTTMove.SidePositionsCount; n++) { xPositions [n] = xPosition; } TTTMoveYPosition[] yPositions = new TTTMoveYPosition[TTTMove.SidePositionsCount]; yPositions [0] = TTTMoveYPosition.Top; yPositions [1] = TTTMoveYPosition.Center; yPositions [2] = TTTMoveYPosition.Bottom; return(GetWinningPlayer(out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPositions, yPositions)); }
public bool GetWinningPlayer(out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition) { bool hasWinner; for (var xPosition = TTTMoveXPosition.Left; xPosition <= TTTMoveXPosition.Right; xPosition++) { hasWinner = GetWinningPlayer(out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPosition); if (hasWinner) { return(hasWinner); } } for (var yPosition = TTTMoveYPosition.Top; yPosition <= TTTMoveYPosition.Bottom; yPosition++) { hasWinner = GetWinningPlayer(out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, yPosition); if (hasWinner) { return(hasWinner); } } hasWinner = GetWinningPlayer(out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, 1); if (hasWinner) { return(hasWinner); } hasWinner = GetWinningPlayer(out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, -1); return(hasWinner); }
public bool CanSelect(TTTGameView gameView, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { return(gameView.Game.CanAddMove(xPosition, yPosition)); }
public bool CanSelect (TTTGameView gameView, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { return gameView.Game.CanAddMove (xPosition, yPosition); }
PointF pointForPosition(TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { RectangleF bounds = Bounds; PointF point = new PointF (bounds.X + bounds.Size.Width / 2, bounds.Y + bounds.Size.Height / 2); point.X += (int)xPosition * bounds.Size.Width / 3; point.Y += (int)yPosition * bounds.Size.Height / 3; return point; }
bool GetWinningPlayer (out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, int direction) { TTTMoveXPosition[] xPositions = new TTTMoveXPosition[TTTMove.SidePositionsCount]; TTTMoveYPosition[] yPositions = new TTTMoveYPosition[TTTMove.SidePositionsCount]; int n = 0; for (var xPosition = TTTMoveXPosition.Left; xPosition <= TTTMoveXPosition.Right; xPosition++) { xPositions [n] = xPosition; yPositions [n] = (TTTMoveYPosition)((int)xPosition * direction); n++; } return GetWinningPlayer (out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPositions, yPositions); }
bool GetWinningPlayer (out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, TTTMoveYPosition yPosition) { TTTMoveYPosition[] yPositions = new TTTMoveYPosition[TTTMove.SidePositionsCount]; for (int n = 0; n < TTTMove.SidePositionsCount; n++) yPositions [n] = yPosition; TTTMoveXPosition[] xPositions = new TTTMoveXPosition[TTTMove.SidePositionsCount]; xPositions [0] = TTTMoveXPosition.Left; xPositions [1] = TTTMoveXPosition.Center; xPositions [2] = TTTMoveXPosition.Right; return GetWinningPlayer (out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPositions, yPositions); }
bool GetWinningPlayer (out TTTMovePlayer player, out TTTMoveXPosition startXPosition, out TTTMoveYPosition startYPosition, out TTTMoveXPosition endXPosition, out TTTMoveYPosition endYPosition, TTTMoveXPosition xPosition) { TTTMoveXPosition[] xPositions = new TTTMoveXPosition[TTTMove.SidePositionsCount]; for (int n = 0; n < TTTMove.SidePositionsCount; n++) xPositions [n] = xPosition; TTTMoveYPosition[] yPositions = new TTTMoveYPosition[TTTMove.SidePositionsCount]; yPositions [0] = TTTMoveYPosition.Top; yPositions [1] = TTTMoveYPosition.Center; yPositions [2] = TTTMoveYPosition.Bottom; return GetWinningPlayer (out player, out startXPosition, out startYPosition, out endXPosition, out endYPosition, xPositions, yPositions); }
CGPoint pointForPosition (TTTMoveXPosition xPosition, TTTMoveYPosition yPosition) { CGRect bounds = Bounds; CGPoint point = new CGPoint (bounds.X + bounds.Size.Width / 2, bounds.Y + bounds.Size.Height / 2); point.X += (int)xPosition * bounds.Size.Width / 3; point.Y += (int)yPosition * bounds.Size.Height / 3; return point; }