public override void LoadView ()
		{
			UIView view = new UIView ();
			view.BackgroundColor = UIColor.White;

			gameView = new TTTGameView () {
				ImageForPlayer = ImageForPlayer,
				ColorForPlayer = ColorForPlayer,
				UserInteractionEnabled = false,
				TranslatesAutoresizingMaskIntoConstraints = false
			};

			view.AddSubview (gameView);
			gameView.Game = Game;

			nfloat topHeight = UIApplication.SharedApplication.StatusBarFrame.Size.Height +
				NavigationController.NavigationBar.Frame.Size.Height;

			view.AddConstraints (NSLayoutConstraint.FromVisualFormat ("|-margin-[gameView]-margin-|",
				(NSLayoutFormatOptions)0,
				"margin", Margin,
				"gameView", gameView));

			view.AddConstraints (NSLayoutConstraint.FromVisualFormat ("V:|-topHeight-[gameView]-bottomHeight-|",
				(NSLayoutFormatOptions)0,
				"topHeight", topHeight + Margin,
				"gameView", gameView,
				"bottomHeight", Margin));

			View = view;
		}
예제 #2
0
        public override void LoadView()
        {
            UIView view = new UIView();

            view.BackgroundColor = UIColor.White;

            gameView = new TTTGameView()
            {
                ImageForPlayer         = ImageForPlayer,
                ColorForPlayer         = ColorForPlayer,
                UserInteractionEnabled = false,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            view.AddSubview(gameView);
            gameView.Game = Game;

            nfloat topHeight = UIApplication.SharedApplication.StatusBarFrame.Size.Height +
                               NavigationController.NavigationBar.Frame.Size.Height;

            view.AddConstraints(NSLayoutConstraint.FromVisualFormat("|-margin-[gameView]-margin-|",
                                                                    (NSLayoutFormatOptions)0,
                                                                    "margin", Margin,
                                                                    "gameView", gameView));

            view.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-topHeight-[gameView]-bottomHeight-|",
                                                                    (NSLayoutFormatOptions)0,
                                                                    "topHeight", topHeight + Margin,
                                                                    "gameView", gameView,
                                                                    "bottomHeight", Margin));

            View = view;
        }
 public void DidSelect(TTTGameView gameView, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition)
 {
     UIView.Animate(0.3, delegate {
         gameView.Game.AddMove(xPosition, yPosition);
         gameView.UpdateGameState();
         saveProfile();
         updateBackground();
     });
 }
 public void DidSelect(TTTGameView gameView, TTTMoveXPosition xPosition, TTTMoveYPosition yPosition)
 {
     UIView.Animate (0.3, delegate {
         gameView.Game.AddMove (xPosition, yPosition);
         gameView.UpdateGameState ();
         saveProfile ();
         updateBackground ();
     });
 }
        public override void LoadView()
        {
            UIView view = new UIView();

            view.BackgroundColor = UIColor.White;

            gameView = new TTTGameView()
            {
                ImageForPlayer         = ImageForPlayer,
                ColorForPlayer         = ColorForPlayer,
                UserInteractionEnabled = false,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            view.AddSubview(gameView);
            gameView.Game = Game;

            float topHeight = UIApplication.SharedApplication.StatusBarFrame.Size.Height +
                              NavigationController.NavigationBar.Frame.Size.Height;
            NSDictionary bindings = NSDictionary.FromObjectAndKey(gameView, new NSString("gameView"));
            NSDictionary metrics  = NSDictionary.FromObjectsAndKeys(
                new NSObject[] { new NSNumber(topHeight + Margin),
                                 new NSNumber(Margin), new NSNumber(Margin) },
                new NSString [] {
                new NSString("topHeight"),
                new NSString("bottomHeight"),
                new NSString("margin")
            });

            view.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                    "|-margin-[gameView]-margin-|", (NSLayoutFormatOptions)0,
                                    metrics, bindings));
            view.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                    "V:|-topHeight-[gameView]-bottomHeight-|", (NSLayoutFormatOptions)0,
                                    metrics, bindings));

            View = view;
        }
		public override void LoadView ()
		{
			UIView view = new UIView ();
			view.BackgroundColor = UIColor.White;

			gameView = new TTTGameView () {
				ImageForPlayer = ImageForPlayer,
				ColorForPlayer = ColorForPlayer,
				UserInteractionEnabled = false,
				TranslatesAutoresizingMaskIntoConstraints = false
			};

			view.AddSubview (gameView);
			gameView.Game = Game;

			float topHeight = UIApplication.SharedApplication.StatusBarFrame.Size.Height +
				NavigationController.NavigationBar.Frame.Size.Height;
			NSDictionary bindings = NSDictionary.FromObjectAndKey (gameView, new NSString ("gameView"));
			NSDictionary metrics = NSDictionary.FromObjectsAndKeys (
				new NSObject[] { new NSNumber (topHeight + Margin),
				new NSNumber (Margin), new NSNumber (Margin)
			},
				new NSString [] { 
				new NSString ("topHeight"), 
				new NSString ("bottomHeight"),
				new NSString ("margin")
			});

			view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
				"|-margin-[gameView]-margin-|", (NSLayoutFormatOptions)0,
				metrics, bindings));
			view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
				"V:|-topHeight-[gameView]-bottomHeight-|", (NSLayoutFormatOptions)0,
				metrics, bindings));

			View = view;
		}
		public override void LoadView ()
		{
			UIView view = new UIView ();

			UIButton newButton = UIButton.FromType (UIButtonType.System);
			newButton.TranslatesAutoresizingMaskIntoConstraints = false;
			newButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
			newButton.SetTitle ("New Game", UIControlState.Normal);
			newButton.TitleLabel.Font = UIFont.PreferredBody;
			newButton.TouchUpInside += newGame;
			view.AddSubview (newButton);

			UIButton pauseButton = UIButton.FromType (UIButtonType.System);
			pauseButton.TranslatesAutoresizingMaskIntoConstraints = false;
			pauseButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
			pauseButton.SetTitle ("Pause", UIControlState.Normal);
			pauseButton.TitleLabel.Font = UIFont.PreferredBody;
			pauseButton.TouchUpInside += togglePause;
			view.AddSubview (pauseButton);

			gameView = new TTTGameView () {
				ImageForPlayer = ImageForPlayer,
				ColorForPlayer = ColorForPlayer,
				CanSelect = CanSelect,
				DidSelect = DidSelect,
				TranslatesAutoresizingMaskIntoConstraints = false,
				Game = Profile.CurrentGame
			};
			view.AddSubview (gameView);

			float topHeight = UIApplication.SharedApplication.StatusBarFrame.Size.Height;
			UITabBar tabBar = TabBarController.TabBar;
			float bottomHeight = tabBar.Translucent ? tabBar.Frame.Size.Height : 0;
			NSDictionary metrics = NSDictionary.FromObjectsAndKeys (
				new NSNumber[] { new NSNumber (topHeight + ControllerMargin),
				new NSNumber (bottomHeight + ControllerMargin),
				new NSNumber (ControllerMargin)
			},
				new NSString[] { new NSString ("topHeight"), new NSString ("bottomHeight"),
				new NSString ("margin")
			}
			);
			NSDictionary bindings = NSDictionary.FromObjectsAndKeys (
				new NSObject[] { newButton, pauseButton, gameView },
				new NSString [] { 
				new NSString ("newButton"), new NSString ("pauseButton"),
				new NSString ("gameView")
			}
			);
			view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
				"|-margin-[gameView]-margin-|", (NSLayoutFormatOptions)0,
				metrics, bindings
			));
			view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
				"|-margin-[pauseButton(==newButton)]-[newButton]-margin-|",
				(NSLayoutFormatOptions)0, metrics, bindings
			));
			view.AddConstraints (NSLayoutConstraint.FromVisualFormat (
				"V:|-topHeight-[gameView]-margin-[newButton]-bottomHeight-|",
				(NSLayoutFormatOptions)0, metrics, bindings
			));
			view.AddConstraint (NSLayoutConstraint.Create (pauseButton,
			                                               NSLayoutAttribute.Baseline,
			                                               NSLayoutRelation.Equal,
			                                               newButton,
			                                               NSLayoutAttribute.Baseline,
			                                               1f,
			                                               0f));

			View = view;
		}
		public bool CanSelect (TTTGameView gameView, TTTMoveXPosition xPosition,
		                       TTTMoveYPosition yPosition)
		{
			return gameView.Game.CanAddMove (xPosition, yPosition);
		}
		public UIColor ColorForPlayer (TTTGameView gameView, TTTMovePlayer player)
		{
			return Profile.ColorForPlayer (player);
		}
		public UIImage ImageForPlayer (TTTGameView gameView, TTTMovePlayer player)
		{
			return Profile.ImageForPlayer (player);
		}
 public UIColor ColorForPlayer(TTTGameView gameView, TTTMovePlayer player)
 {
     return(Profile.ColorForPlayer(player));
 }
 public UIImage ImageForPlayer(TTTGameView gameView, TTTMovePlayer player)
 {
     return(Profile.ImageForPlayer(player));
 }
        public override void LoadView()
        {
            UIView view = new UIView();

            UIButton newButton = UIButton.FromType(UIButtonType.System);

            newButton.TranslatesAutoresizingMaskIntoConstraints = false;
            newButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
            newButton.SetTitle("New Game", UIControlState.Normal);
            newButton.TitleLabel.Font = UIFont.PreferredBody;
            newButton.TouchUpInside  += newGame;
            view.AddSubview(newButton);

            UIButton pauseButton = UIButton.FromType(UIButtonType.System);

            pauseButton.TranslatesAutoresizingMaskIntoConstraints = false;
            pauseButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
            pauseButton.SetTitle("Pause", UIControlState.Normal);
            pauseButton.TitleLabel.Font = UIFont.PreferredBody;
            pauseButton.TouchUpInside  += togglePause;
            view.AddSubview(pauseButton);

            gameView = new TTTGameView()
            {
                ImageForPlayer = ImageForPlayer,
                ColorForPlayer = ColorForPlayer,
                CanSelect      = CanSelect,
                DidSelect      = DidSelect,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Game = Profile.CurrentGame
            };
            view.AddSubview(gameView);

            float    topHeight    = UIApplication.SharedApplication.StatusBarFrame.Size.Height;
            UITabBar tabBar       = TabBarController.TabBar;
            float    bottomHeight = tabBar.Translucent ? tabBar.Frame.Size.Height : 0;

            var mTopHeight    = new NSNumber(topHeight + ControllerMargin);
            var mBottomHeight = new NSNumber(bottomHeight + ControllerMargin);
            var mMargin       = new NSNumber(ControllerMargin);

            view.AddConstraints(NSLayoutConstraint.FromVisualFormat("|-margin-[gameView]-margin-|",
                                                                    (NSLayoutFormatOptions)0,
                                                                    "margin", mMargin,
                                                                    "gameView", gameView));
            view.AddConstraints(NSLayoutConstraint.FromVisualFormat("|-margin-[pauseButton(==newButton)]-[newButton]-margin-|",
                                                                    (NSLayoutFormatOptions)0,
                                                                    "margin", mMargin,
                                                                    "pauseButton", pauseButton,
                                                                    "newButton", newButton));
            view.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-topHeight-[gameView]-margin-[newButton]-bottomHeight-|",
                                                                    (NSLayoutFormatOptions)0,
                                                                    "topHeight", mTopHeight,
                                                                    "gameView", gameView,
                                                                    "margin", mMargin,
                                                                    "newButton", newButton,
                                                                    "bottomHeight", mBottomHeight));
            view.AddConstraint(NSLayoutConstraint.Create(
                                   pauseButton, NSLayoutAttribute.Baseline,
                                   NSLayoutRelation.Equal,
                                   newButton, NSLayoutAttribute.Baseline,
                                   1f, 0f));

            View = view;
        }
 public bool CanSelect(TTTGameView gameView, TTTMoveXPosition xPosition,
                       TTTMoveYPosition yPosition)
 {
     return(gameView.Game.CanAddMove(xPosition, yPosition));
 }