Exemple #1
0
        /// <summary>
        /// Handles the movement animation of the pawns & tiles
        /// </summary>
        /// <param name="positionFrom">Move from</param>
        /// <param name="positionTo">Move to</param>
        /// <param name="tileFrom">Tile from</param>
        private void ShowMove(Point positionFrom, Point positionTo, Point tileFrom)
        {
            didLastMove = didLastMove ? false : true;

            if (engine.GetGameState() == KaroEngine.GameState.INSERTION || this.StartingPieces.Count != 0)
            {
                if (this.selectedStartingPiece >= 0)
                {
                    Piece p = this.StartingPieces[this.selectedStartingPiece];
                    p.IsSelected = false;
                    this.ClearSelectedItems();
                    StartingPieces.Remove(p);
                    p.rotateDegrees = 1000;
                    p.MoveTo(this.TileComponents[positionTo.Y * BOARDWIDTH + positionTo.X]);
                    this.PieceComponents.Add(positionTo.Y * BOARDWIDTH + positionTo.X, p);
                }
            }
            else
            {
                this.ClearSelectedItems();
                if (tileFrom.X > 0)
                {
                    Tile movedTile = this.TileComponents[tileFrom.Y * BOARDWIDTH + tileFrom.X];
                    this.TileComponents.Remove(tileFrom.Y * BOARDWIDTH + tileFrom.X);
                    movedTile.Location = positionTo;
                    movedTile.moveTo(Matrix.CreateTranslation(new Vector3(positionTo.X * 5.5f, 0, positionTo.Y * 5.5f)));
                    this.TileComponents.Add(positionTo.Y * BOARDWIDTH + positionTo.X, movedTile);
                }
                Piece movedPiece = this.PieceComponents[positionFrom.Y * BOARDWIDTH + positionFrom.X];
                this.PieceComponents.Remove(positionFrom.Y * BOARDWIDTH + positionFrom.X);
                movedPiece.MoveTo(this.TileComponents[(positionTo.Y * BOARDWIDTH) + positionTo.X]);
                KaroEngine.Tile t = engine.GetByXY(positionTo.X, positionTo.Y);
                bool            flipping;

                int direction = (int)Math.Floor(MathHelper.ToDegrees((float)Math.Atan2(positionFrom.Y - positionTo.Y, positionFrom.X - positionTo.X)));

                if (t == KaroEngine.Tile.REDMARKED || t == KaroEngine.Tile.WHITEMARKED)
                {
                    flipping = true;
                }
                else
                {
                    flipping = false;
                }

                if (flipping != movedPiece.IsFlipped)
                {
                    movedPiece.IsFlipped     = flipping;
                    movedPiece.rotateDegrees = direction;
                }
                else
                {
                    movedPiece.rotateDegrees = 360;
                }

                this.PieceComponents.Add(positionTo.Y * BOARDWIDTH + positionTo.X, movedPiece);
            }
        }
Exemple #2
0
        /// <summary>
        /// Undo the move from the tile.
        /// </summary>
        /// <param name="tileFrom"></param>
        /// <param name="positionTo"></param>
        private void UndoTileMove(Point tileFrom, Point positionTo, Point positionFrom)
        {
            int to       = positionTo.Y * BOARDWIDTH + positionTo.X;     //De tile waar de pawn eerst op stond.
            int from     = positionFrom.Y * BOARDWIDTH + positionFrom.X; // De bewogen tile, ook plaats van de pawn
            int fromTile = tileFrom.Y * BOARDWIDTH + tileFrom.X;         // de locatie waar de bewogen tile eerst stond.

            #region Beweeg de oorspronkelijke tile terug var: movedTile
            Tile movedTile = this.TileComponents[from];
            this.TileComponents.Remove(from);
            movedTile.Location = tileFrom;
            this.TileComponents.Add(fromTile, movedTile);
            #endregion

            #region Beweeg de pawn var: piece
            Piece piece = this.PieceComponents[from];
            PieceComponents.Remove(from);
            piece.MoveTo(this.TileComponents[to]);
            KaroEngine.Tile t = engine.GetByXY(positionTo.X, positionTo.Y);
            bool            flipping;
            int             direction = (int)Math.Floor(MathHelper.ToDegrees((float)Math.Atan2(positionFrom.Y - positionTo.Y, positionFrom.X - positionTo.X)));
            if (t == KaroEngine.Tile.REDMARKED || t == KaroEngine.Tile.WHITEMARKED)
            {
                flipping = true;
            }
            else
            {
                flipping = false;
            }
            if (flipping != piece.IsFlipped)
            {
                piece.IsFlipped     = flipping;
                piece.rotateDegrees = direction;
            }
            else
            {
                piece.rotateDegrees = 360;
            }
            this.PieceComponents.Add(to, piece);
            #endregion

            //Nadat de pawn gestart is met bewegen, verplaats de tile
            movedTile.moveTo(Matrix.CreateTranslation(new Vector3(tileFrom.X * 5.5f, 0, tileFrom.Y * 5.5f)));
        }
Exemple #3
0
        /// <summary>
        /// Starts a new game
        /// </summary>
        public void NewGame()
        {
            engine                     = new KaroEngineWrapper();
            this.selectedPiece         = 0;
            this.selectedTile          = 0;
            this.selectedStartingPiece = -1;
            computerIsThinking         = false;
            undoTimer                  = 0;
            moveUndone                 = false;
            startUndoTimer             = false;
            didLastMove                = false;

            // clear tiles
            foreach (var tile in TileComponents)
            {
                Components.Remove(tile.Value);
            }
            TileComponents.Clear();

            // clear pieces
            foreach (var piece in PieceComponents)
            {
                Components.Remove(piece.Value);
            }
            PieceComponents.Clear();

            // add the tiles
            for (int x = 0; x < BOARDWIDTH; x++)
            {
                for (int y = 0; y < BOARDWIDTH; y++)
                {
                    KaroEngine.Tile tile = engine.GetByXY(x, y);
                    if (tile != KaroEngine.Tile.BORDER && tile != KaroEngine.Tile.EMPTY)
                    {
                        Tile t = new Tile(this, tileModel, false, new Point(x, y));
                        this.TileComponents.Add(y * BOARDWIDTH + x, t);
                        Components.Add(t);
                    }
                }
            }
            StartingPieces.Clear();

            //White pawns
            for (int i = 0; i < 3; i += 1)
            {
                Tile t = new Tile(this, tileModel, false, new Point(i + 7, 3));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                Piece p = new Piece(this, pieceModel, true, t, Color.White.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
                t             = new Tile(this, tileModel, false, new Point(i + 7, 4));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                p             = new Piece(this, pieceModel, true, t, Color.White.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
            }

            //Red pawns
            for (int i = 0; i < 3; i += 1)
            {
                Tile t = new Tile(this, tileModel, false, new Point(i + 7, 9));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                Piece p = new Piece(this, pieceModel, true, t, Color.Tomato.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
                t             = new Tile(this, tileModel, false, new Point(i + 7, 10));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                p             = new Piece(this, pieceModel, true, t, Color.Tomato.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
            }
        }