Ejemplo n.º 1
0
        public GamePieceVisualInfo GetInfoObject(GameBoardController controller)
        {
            GamePieceVisualInfo info = new GamePieceVisualInfo();

            info.PieceState    = this.PieceState;
            info.PieceType     = this.PieceType;
            info.XMaterial     = this.xModel.Material;
            info.EmptyMaterial = this.emptyModel.Material;
            info.Coordinate    = controller.GetCoordinateFromGamePiece(this);
            info.GamePiece     = this;
            return(info);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the window.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            this.trackball.Enabled        = false;
            this.mainViewport.MouseDown  += new MouseButtonEventHandler(mainViewport_MouseDown);
            this.mainViewport.MouseMove  += new MouseEventHandler(mainViewport_MouseMove);
            this.mainViewport.MouseLeave += new MouseEventHandler(mainViewport_MouseLeave);
            this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);
            this.KeyUp   += new KeyEventHandler(MainWindow_KeyUp);

            this.controller            = new GameBoardController(this.boardVisual);
            this.controller.MoveMade  += new EventHandler <MoveMadeEventArgs>(controller_MoveMade);
            this.controller.GameReset += new EventHandler <EventArgs>(controller_GameReset);
            this.controller.Reset();
            this.moveHistory.Controller = this.controller;
            this.currentUpDirection     = ((PerspectiveCamera)this.mainViewport.Camera).UpDirection;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Takes user interface input in the form of a mouse pointer location and the containing
        /// 3D viewport and attempts to "select" the piece that exists at that location.  If a piece is
        /// found, the appropriate game operation is performed, such as highlighting a valid source, or
        /// executing a move.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="viewport"></param>
        public void SelectPiece(Point location, Viewport3D viewport)
        {
            if (this.GameOver || this.showingOnlyPlacedPieces)
            {
                return;
            }

            ModelVisual3D   hitTestResult = GameBoardController.GetHitTestResult(viewport, location);
            GamePieceVisual targetPiece   = GameBoardController.ConvertHitTestResultToGamePieceVisual(hitTestResult);

            if (this.currentShowValidMoveOperation != null)
            {
                if (targetPiece != null && this.currentShowValidMoveOperation.ValidDestinationPieces.Contains(targetPiece))
                {
                    //execute move
                    ExecuteMoveOperation operation = new ExecuteMoveOperation(this, this.currentShowValidMoveOperation.SourcePiece, targetPiece);
                    this.currentShowValidMoveOperation.Hide();
                    this.currentShowValidMoveOperation = null;
                    operation.Execute();
                    this.moveOperations.Add(operation);
                    this.BuildBoardFromMoveHistory();
                    this.OnMoveMade(operation);
                    this.CheckForEngineMove();
                    this.isDirty = true;
                }
            }
            else
            {
                if (targetPiece != null)
                {
                    if (targetPiece.IsValidSource)
                    {
                        this.currentShowValidMoveOperation = new ShowValidMoveOperation(this, targetPiece);
                        this.currentShowValidMoveOperation.Show();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new instance of the class.
        /// </summary>
        /// <param name="controller"></param>
        public ObservableMoveCollection(GameBoardController controller)
            : base()
        {
            controller.MoveMade  += new EventHandler <MoveMadeEventArgs>(controller_MoveMade);
            controller.GameReset += new EventHandler <EventArgs>(controller_GameReset);

            if (controller.Board.MoveHistory.Count > 0)
            {
                Players player = Players.X;
                foreach (Move move in controller.Board.MoveHistory)
                {
                    this.Add(new MoveHistoryInformation(player, move));
                    if (player == Players.X)
                    {
                        player = Players.O;
                    }
                    else
                    {
                        player = Players.X;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// A helper method used to find a <see cref="GamePieceVisual"/> object by either direct
        /// casting or walking the visual tree.
        /// </summary>
        /// <param name="hitTestResult"></param>
        /// <returns></returns>
        static GamePieceVisual ConvertHitTestResultToGamePieceVisual(ModelVisual3D hitTestResult)
        {
            if (hitTestResult == null)
            {
                return(null);
            }

            PlanarText textResult = hitTestResult as PlanarText;

            if (textResult != null)
            {
                return(GameBoardController.GetGamePieceVisualFromText(textResult));
            }

            GamePieceVisual pieceResult = hitTestResult as GamePieceVisual;

            if (pieceResult != null)
            {
                return(pieceResult);
            }

            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Attempts to highlight a game piece at the specified mouse pointer location.
        /// </summary>
        /// <remarks>
        /// This method is primarily used for mouse "rollover" actions.
        /// </remarks>
        /// <param name="location"></param>
        /// <param name="viewport"></param>
        public void HighlightPiece(Point location, Viewport3D viewport)
        {
            if (this.GameOver || this.currentShowValidMoveOperation != null || this.showingOnlyPlacedPieces)
            {
                return;
            }

            ModelVisual3D selectedItem = GameBoardController.GetHitTestResult(viewport, location);

            if (selectedItem == null)
            {
                if (this.highlightedPiece != null)
                {
                    this.highlightedPiece.Highlighted = false;
                }
                return;
            }

            GamePieceVisual targetPiece = GameBoardController.ConvertHitTestResultToGamePieceVisual(selectedItem);

            if (targetPiece != null)
            {
                if (targetPiece != this.highlightedPiece)
                {
                    if (this.highlightedPiece != null)
                    {
                        this.highlightedPiece.Highlighted = false;
                    }
                }

                this.highlightedPiece = targetPiece;
                if (targetPiece.IsValidSource)
                {
                    this.highlightedPiece.Highlighted = true;
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a new instance of a <see cref="ExecuteMoveOperation"/>.
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="move"></param>
 public ExecuteMoveOperation(GameBoardController controller, Move move)
 {
     this.controller = controller;
     this.move       = move;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new instance of a <see cref="ExecuteMoveOperation"/>.
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="sourcePiece"></param>
 /// <param name="destinationPiece"></param>
 public ExecuteMoveOperation(GameBoardController controller, GamePieceVisual sourcePiece, GamePieceVisual destinationPiece)
 {
     this.controller       = controller;
     this.sourcePiece      = sourcePiece;
     this.destinationPiece = destinationPiece;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new instance of the class.
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="sourcePiece"></param>
 public ShowValidMoveOperation(GameBoardController controller, GamePieceVisual sourcePiece)
 {
     this.sourcePiece = sourcePiece;
     this.controller  = controller;
 }