Exemplo n.º 1
0
 public Position AtDirection(CardinalDirection direction)
 {
     Position position = new Position();
     if (direction == CardinalDirection.North)
     {
         position.Row = this.Row - 1;
         position.Column = this.Column;
     }
     else if (direction == CardinalDirection.South)
     {
         position.Row = this.Row + 1;
         position.Column = this.Column;
     }
     else if (direction == CardinalDirection.East)
     {
         position.Row = this.Row;
         position.Column = this.Column + 1;
     }
     else if (direction == CardinalDirection.West)
     {
         position.Row = this.Row;
         position.Column = this.Column - 1;
     }
     else if (direction == CardinalDirection.Northwest)
     {
         position.Row = this.Row - 1;
         position.Column = this.Column - 1;
     }
     else if (direction == CardinalDirection.Northeast)
     {
         position.Row = this.Row - 1;
         position.Column = this.Column + 1;
     }
     else if (direction == CardinalDirection.Southeast)
     {
         position.Row = this.Row + 1;
         position.Column = this.Column + 1;
     }
     else if (direction == CardinalDirection.Southwest)
     {
         position.Row = this.Row + 1;
         position.Column = this.Column - 1;
     }
     return position;
 }
Exemplo n.º 2
0
        public static void WhiteWin(CreeperBoard board)
        {
            Position startPosition;
            Position endPosition;
            Move move;
            bool pausePrint = false;

            for (int i = 0; i < 4; i++)
            {
                startPosition = new Position(i, i + 1);
                endPosition = new Position(i + 1, i + 2);
                move = new Move(startPosition, endPosition, CreeperColor.Fire);
                board.Move(move);
                board.PrintToConsole(pausePrint);
            }
            for (int i = 0; i < 3; i++)
            {
                startPosition = new Position(i, i + 2);
                endPosition = new Position(i + 1, i + 3);
                move = new Move(startPosition, endPosition, CreeperColor.Fire);
                board.Move(move);
                board.PrintToConsole(pausePrint);
            }

            startPosition = new Position(4, 6);
            endPosition = new Position(5, 5);
            move = new Move(startPosition, endPosition, CreeperColor.Fire);
            board.Move(move);
            board.PrintToConsole(pausePrint);

            startPosition = new Position(4, 5);
            endPosition = new Position(5, 4);
            move = new Move(startPosition, endPosition, CreeperColor.Fire);
            board.Move(move);
            board.PrintToConsole(pausePrint);

            if(board.GetGameState(CreeperColor.Fire) == CreeperGameState.Complete)
            {
                Console.WriteLine("White wins!");
            }
        }
Exemplo n.º 3
0
 public Position(Position position)
 {
     Column = position.Column;
     Row = position.Row;
 }
Exemplo n.º 4
0
 public bool Equals(Position position)
 {
     return (Column == position.Column && Row == position.Row);
 }
Exemplo n.º 5
0
        public Move[] AllPossibleMoves(CreeperColor color)
        {
            if (color == CreeperColor.Invalid || color == CreeperColor.Empty) throw new ArgumentOutOfRangeException(color.ToString());

            Position startPosition = new Position();
            Move[] possibleMoves = new Move[100];
            int index = 0;
            foreach (AIBoardNode peg in (color == CreeperColor.Ice) ? BlackPegs : WhitePegs)
            {
                startPosition = new Position(peg.Row, peg.Column);

                Move[] movesForPeg = new Move[]
                    {
                        new Move(startPosition, new Position(peg.Row + 1, peg.Column), color),
                        new Move(startPosition, new Position(peg.Row - 1, peg.Column), color),
                        new Move(startPosition, new Position(peg.Row, peg.Column + 1), color),
                        new Move(startPosition, new Position(peg.Row, peg.Column - 1), color),
                        new Move(startPosition, new Position(peg.Row + 1, peg.Column + 1), color),
                        new Move(startPosition, new Position(peg.Row + 1, peg.Column - 1), color),
                        new Move(startPosition, new Position(peg.Row - 1, peg.Column + 1), color),
                        new Move(startPosition, new Position(peg.Row - 1, peg.Column - 1), color),
                        new Move(startPosition, new Position(peg.Row + 2, peg.Column), color),
                        new Move(startPosition, new Position(peg.Row - 2, peg.Column), color),
                        new Move(startPosition, new Position(peg.Row, peg.Column + 2), color),
                        new Move(startPosition, new Position(peg.Row, peg.Column - 2), color),
                    };

                for (int i = 0; i < movesForPeg.Length; i++)
                {
                    if (IsValidMove(movesForPeg[i]))
                    {
                        possibleMoves[index++] = movesForPeg[i];
                    }
                }
            }

            Array.Resize(ref possibleMoves, index);
            return possibleMoves;
        }
Exemplo n.º 6
0
 public Move(Position startPosition, Position endPosition, CreeperColor playerColor)
 {
     StartPosition = startPosition;
     EndPosition = endPosition;
     PlayerColor = playerColor;
 }
Exemplo n.º 7
0
        public void MoveTo(MoveInfo info, System.Action callback)
        {
            if (PegType != CreeperPegType.Possible)
            {
                ParticleEmitter emitter = (ParticleEmitter)Parent.Find<ParticleEffect>().Emitter;
                emitter.Duration = 1f;
                float newDirectionRadian = (float)Math.Atan2(-(info.EndPoint.X - Parent.Transform.Translation.X), -(info.EndPoint.Z - Parent.Transform.Translation.Z));

                Parent.Transform = Matrix.CreateRotationY(newDirectionRadian)
                    * Matrix.CreateTranslation(Parent.Transform.Translation);

                TweenAnimation<Matrix> moveAnimation = new TweenAnimation<Matrix>
                    {
                        Target = Parent,
                        TargetProperty = "Transform",
                        Duration = TimeSpan.FromSeconds(1),
                        From = Parent.Transform,
                        To = Matrix.CreateRotationY(newDirectionRadian) * Matrix.CreateTranslation(info.EndPoint),
                        Curve = Curves.Smooth,
                    };

                moveAnimation.Completed += new EventHandler((s, e) =>
                    {
                        _pegModel.Animations["Run"].Stop();
                        _pegModel.Animations.Play("Idle");
                        Parent.Animations.Remove(Resources.AnimationNames.PegMove);
                        _graphicalPosition = info.EndPoint;
                        Position = info.Position;
                        emitter.Duration = 0f;
                        callback();
                    });
                if (info.Type != MoveType.PegJump)
                {

                    Parent.Animations.Add("move", moveAnimation);
                    Parent.Animations.Play("move");
                    if (_pegModel != null)
                        _pegModel.Animations.Play("Run");
                }
                else
                {

                    Vector3 distance = info.EndPoint - Parent.Transform.Translation;
                    distance /= 1.4f;

                    Parent.Transform = Matrix.CreateRotationY(newDirectionRadian)
                        * Matrix.CreateTranslation(Parent.Transform.Translation);

                    TweenAnimation<Matrix> killAnimation = new TweenAnimation<Matrix>
                    {
                        Target = Parent,
                        TargetProperty = "Transform",
                        Duration = TimeSpan.FromSeconds(1),
                        From = Parent.Transform,
                        To = Matrix.CreateRotationY(newDirectionRadian) * Matrix.CreateTranslation(info.EndPoint - distance),
                        Curve = Curves.Smooth,
                    };

                    killAnimation.Completed += new EventHandler((s, e) =>
                    {

                        _pegModel.Animations["Chop"].Stop();
                        _pegModel.Animations["Attack"].Stop();
                        Parent.Animations.Remove("kill");
                        moveAnimation.From = Parent.Transform;
                        if (info.JumpedPeg != null)
                        {
                            info.JumpedPeg.Die();
                        }
                        _pegModel.Animations.Play("Run");
                        Parent.Animations.Play("move");
                        _graphicalPosition = info.EndPoint;
                        Position = info.Position;
                    });

                    Parent.Animations.Add("move", moveAnimation);
                    Parent.Animations.Add("kill", killAnimation);
                    Parent.Animations.Play("kill");

                    int nextValue = r.Next(2);
                    if (nextValue == 0)
                    {
                        _pegModel.Animations.Play("Attack");
                    }
                    else
                    {
                        _pegModel.Animations.Play("Chop");
                    }
                }
            }
        }
Exemplo n.º 8
0
 public Piece(Piece piece)
 {
     Position = new Position(piece.Position);
     Color = piece.Color;
 }
Exemplo n.º 9
0
 public Piece(CreeperColor color, Position position)
 {
     Color = color;
     Position = position;
 }
Exemplo n.º 10
0
        public static bool IsValidPosition(Position position, PieceType pieceType)
        {
            int rows = (pieceType == PieceType.Tile) ? TileRows : PegRows;

            return (position.Column >= 0 && position.Column < rows && position.Row >= 0 && position.Row < rows);
        }
Exemplo n.º 11
0
 public static Piece At(this IEnumerable<Piece> pieces, Position position)
 {
     return pieces.First(x => x.Position == position);
 }
Exemplo n.º 12
0
 private static bool IsPegOnBoard(Position position)
 {
     return position.Row >= 0 && position.Row <= 6 && position.Column >= 0 && position.Column <= 6;
 }