示例#1
0
        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;
        }
示例#2
0
		public TTTMove (TTTMovePlayer player, TTTMoveXPosition xPosition,
		                TTTMoveYPosition yPosition)
		{
			Player = player;
			XPosition = xPosition;
			YPosition = yPosition;
		}
示例#3
0
        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);
                }
            }
        }
示例#4
0
 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 ();
     });
 }
示例#6
0
		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();
     });
 }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        public bool CanAddMove(TTTMoveXPosition xPosition, TTTMoveYPosition yPosition)
        {
            if (Result != TTTGameResult.InProgress)
            {
                return(false);
            }

            TTTMovePlayer player = TTTMovePlayer.None;

            return(!hasMove(xPosition, yPosition, ref player));
        }
示例#12
0
		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;
		}
示例#13
0
		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 ();
		}
示例#14
0
        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);
        }
示例#15
0
        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();
        }
示例#16
0
        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));
        }
示例#17
0
        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));
        }
示例#18
0
		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;
		}
示例#19
0
        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));
        }
示例#20
0
        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;
 }
示例#24
0
		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);
		}
示例#25
0
		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);
		}
示例#26
0
		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);
		}
示例#27
0
		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;
		}