Esempio n. 1
0
        public EngineLvl2Test()
        {
            // seteamos una instancia "falsa" del adapter para usar en los tests.
            OneAdapter.Adapter = new FalseAdapterContain(true);

            // creamos el diccionario de paginas y niveles para los tests.
            Dictionary <string, List <string> > dicc = new Dictionary <string, List <string> >();
            List <string> list = new List <string>();

            list.Add("Page1");
            dicc.Add("Menu", list);
            Creator.UnityPages = dicc;

            // creamos el mundo necesario para testear el motor.
            Singleton <GeneralEngine> .Instance.ActualLevel = "Menu";

            level  = new Level("level", world);
            screen = new Screen("screen", level);

            destination1 = new BlankSpace("destination1", 10, 10, 50, 50, screen, "path");
            source1      = new DragAndDropSource("source1", 50, 50, 50, 50, screen, "path");
            destination2 = new BlankSpace("destination2", 20, 20, 50, 50, screen, "path");
            source2      = new DragAndDropSource("source2", 50, 50, 50, 50, screen, "path");

            word1 = new Word("word1", 10, 10, 50, 50, screen, "path1", source1, destination1);
            word2 = new Word("word2", 10, 10, 50, 50, screen, "path2", source2, destination2);

            screen.Add(word1);
            screen.Add(word2);
            screen.Add(destination1);
            screen.Add(destination2);
        }
Esempio n. 2
0
        private void ProcessMove(IMatrixPosition newPosition)
        {
            IMatrixPosition oldNinjaPosition = this.currentNinja.Position;

            this.currentNinja.Move(newPosition);

            if (this.Database.Vegetables.Any(veg => veg.Position.Equals(newPosition)))
            {
                IVegetable currentVegetable = this.Database.Vegetables.First(veg => veg.Position.Equals(newPosition));

                this.Database.RemoveVegetable(currentVegetable);
                this.currentNinja.CollectVegetable(currentVegetable);

                IBlankSpace newBlankSpace = new BlankSpace(this.currentNinja.Position,
                                                           currentVegetable.TimeToGrow,
                                                           (VegetableType)Enum.Parse(typeof(VegetableType), currentVegetable.GetType().Name));

                this.Database.AddGrowingVegetable(newBlankSpace);

                IBlankSpace oldFieldPositionElement = new BlankSpace(oldNinjaPosition, -1, VegetableType.Blank);

                if (this.Database.GrowingVegetables.Any(growingVegetable => growingVegetable.Position.Equals(oldNinjaPosition)))
                {
                    oldFieldPositionElement = this.Database.GrowingVegetables.First(growingVegetable =>
                                                                                    growingVegetable.Position.Equals(oldNinjaPosition));
                }

                this.Database.SetGameFieldObject(oldNinjaPosition, oldFieldPositionElement);
                this.Database.SetGameFieldObject(this.currentNinja.Position, this.currentNinja);
                return;
            }

            INinja otherNinja = this.Database.GetOtherPlayer(this.currentNinja.Name);

            if (this.currentNinja.Position.Equals(otherNinja.Position))
            {
                this.Fight();
            }
        }
        private void ProcessMove(IMatrixPosition newPosition)
        {
            IMatrixPosition oldNinjaPosition = this.currentNinja.Position;
            this.currentNinja.Move(newPosition);

            if (
                this.Database.Vegetables.Any(
                    veg =>
                    veg.Position.Equals(newPosition)))
            {
                IVegetable currentVegetable =
                    this.Database.Vegetables.First(
                        veg =>
                    veg.Position.Equals(newPosition));

                this.Database.RemoveVegetable(currentVegetable);
                this.currentNinja.CollectVegetable(currentVegetable);
                
                IBlankSpace newBlankSpace = new BlankSpace(
                    this.currentNinja.Position,
                    currentVegetable.TimeToGrow,
                    (VegetableType)Enum.Parse(typeof(VegetableType), currentVegetable.GetType().Name));

                this.Database.AddGrowingVegetable(newBlankSpace);

                IBlankSpace oldFieldPositionElement = new BlankSpace(oldNinjaPosition, -1, VegetableType.Blank);

                if (
                    this.Database.GrowingVegetables.Any(
                        growingVegetable =>
                        growingVegetable.Position.Equals(oldNinjaPosition)))
                {
                    oldFieldPositionElement =
                        this.Database.GrowingVegetables.First(
                            growingVegetable =>
                            growingVegetable.Position.Equals(oldNinjaPosition));
                }

                this.Database.SetGameFieldObject(oldNinjaPosition, oldFieldPositionElement);
                this.Database.SetGameFieldObject(this.currentNinja.Position, this.currentNinja);
                return;
            }

            INinja otherNinja = this.Database.GetOtherPlayer(this.currentNinja.Name);

            if (this.currentNinja.Position.Equals(otherNinja.Position))
            {
                this.Fight();
            }
        }
Esempio n. 4
0
        public void SeedField(IList <string> inputMatrix, string firstNinjaName, string secondNinjaName)
        {
            for (int i = 0; i < inputMatrix.Count; i++)
            {
                List <IGameObject> currentRow = new List <IGameObject>();

                string currentInputRow = inputMatrix[i];

                for (int j = 0; j < currentInputRow.Length; j++)
                {
                    char currentElement = currentInputRow[j];

                    IVegetable      newVegetable   = null;
                    IBlankSpace     newBlanckSpace = null;
                    INinja          newNinja       = null;
                    IMatrixPosition position       = new MatrixPosition(i, j);

                    switch (currentElement)
                    {
                    case 'A':
                        newVegetable = new Asparagus(position);
                        break;

                    case 'B':
                        newVegetable = new Broccoli(position);
                        break;

                    case 'C':
                        newVegetable = new CherryBerry(position);
                        break;

                    case 'M':
                        newVegetable = new Mushroom(position);
                        break;

                    case 'R':
                        newVegetable = new Royal(position);
                        break;

                    case '*':
                        newVegetable = new MeloLemonMelon(position);
                        break;

                    case '-':
                        newBlanckSpace = new BlankSpace(position, -1, VegetableType.Blank);
                        break;
                    }

                    if (currentElement.Equals(firstNinjaName[0]))
                    {
                        newNinja = new Ninja(position, firstNinjaName);
                    }

                    if (currentElement.Equals(secondNinjaName[0]))
                    {
                        newNinja = new Ninja(position, secondNinjaName);
                    }

                    if (newVegetable != null)
                    {
                        this.AddVegetable(newVegetable);
                        currentRow.Add(newVegetable);
                    }

                    if (newNinja != null)
                    {
                        this.AddNinja(newNinja);
                        currentRow.Add(newNinja);
                    }

                    if (newBlanckSpace != null)
                    {
                        currentRow.Add(newBlanckSpace);
                    }
                }

                this.gameField.Add(currentRow);
            }
        }
        public void SeedField(IList<string> inputMatrix, string firstNinjaName, string secondNinjaName)
        {
            for (int i = 0; i < inputMatrix.Count; i++)
            {
                List<IGameObject> currentRow = new List<IGameObject>();

                string currentInputRow = inputMatrix[i];

                for (int j = 0; j < currentInputRow.Length; j++)
                {
                    char currentElement = currentInputRow[j];

                    IVegetable newVegetable = null;
                    IBlankSpace newBlankSpace = null;
                    INinja newNinja = null;
                    IMatrixPosition position = new MatrixPosition(i, j);

                    switch (currentElement)
                    {
                        case 'A':
                            newVegetable = new Asparagus(position);
                            break;
                        case 'B':
                            newVegetable = new Broccoli(position);
                            break;
                        case 'C':
                            newVegetable = new CherryBerry(position);
                            break;
                        case 'M':
                            newVegetable = new Mushroom(position);
                            break;
                        case 'R':
                            newVegetable = new Royal(position);
                            break;
                        case '*':
                            newVegetable = new MeloLemonMelon(position);
                            break;
                        case '-':
                            newBlankSpace = new BlankSpace(position, -1, VegetableType.Blank);
                            break;
                    }

                    if (currentElement.Equals(firstNinjaName[0]))
                    {
                        newNinja = new Ninja(position, firstNinjaName);
                    }

                    if (currentElement.Equals(secondNinjaName[0]))
                    {
                        newNinja = new Ninja(position, secondNinjaName);   
                    }

                    if (newVegetable != null)
                    {
                        this.AddVegetable(newVegetable);
                        currentRow.Add(newVegetable);
                    }

                    if (newNinja != null)
                    {
                        this.AddNinja(newNinja);
                        currentRow.Add(newNinja);
                    }

                    if (newBlankSpace != null)
                    {
                        currentRow.Add(newBlankSpace);
                    }
                }

                this.gameField.Add(currentRow);
            }
        }
Esempio n. 6
0
    private void setupPieces()
    {
        for (int i = 0; i < numberOfRows; i++)
        {
            for (int j = 0; j < numberofColumns; j++)
            {
                theboard[i, j] = new BlankSpace(new PositionOnBoard(i, j));
            }
        }

        //each side has 16 pieces (1 King, 2 Guards, 2 Bishop, 2 Rooks, 2 Knight,2 Cannons,5 Pawns)
        //setting up all the black pieces (top half of board)
        //each pieces is added to the board and to the black pieces list


        King blackKing = new King(PieceControl.Colour.Black, new PositionOnBoard(4, 9), this);

        theboard[4, 9] = blackKing;
        blackPieces.Add(blackKing);

        Guard blackGuard1 = new Guard(PieceControl.Colour.Black, new PositionOnBoard(3, 9), this);

        theboard[3, 9] = blackGuard1;
        blackPieces.Add(blackGuard1);

        Guard blackGuard2 = new Guard(PieceControl.Colour.Black, new PositionOnBoard(5, 9), this);

        theboard[5, 9] = blackGuard2;
        blackPieces.Add(blackGuard2);

        Bishop blackBishop1 = new Bishop(PieceControl.Colour.Black, new PositionOnBoard(2, 9), this);

        theboard[2, 9] = blackBishop1;
        blackPieces.Add(blackBishop1);

        Bishop blackBishop2 = new Bishop(PieceControl.Colour.Black, new PositionOnBoard(6, 9), this);

        theboard[6, 9] = blackBishop2;
        blackPieces.Add(blackBishop2);

        Knight blackKnight1 = new Knight(PieceControl.Colour.Black, new PositionOnBoard(1, 9), this);

        theboard[1, 9] = blackKnight1;
        blackPieces.Add(blackKnight1);

        Knight blackKnight2 = new Knight(PieceControl.Colour.Black, new PositionOnBoard(7, 9), this);

        theboard[7, 9] = blackKnight2;
        blackPieces.Add(blackKnight2);

        Rook blackRook1 = new Rook(PieceControl.Colour.Black, new PositionOnBoard(0, 9), this);

        theboard[0, 9] = blackRook1;
        blackPieces.Add(blackRook1);

        Rook blackRook2 = new Rook(PieceControl.Colour.Black, new PositionOnBoard(8, 9), this);

        theboard[8, 9] = blackRook2;
        blackPieces.Add(blackRook2);

        Cannon blackCannon1 = new Cannon(PieceControl.Colour.Black, new PositionOnBoard(1, 7), this);

        theboard[1, 7] = blackCannon1;
        blackPieces.Add(blackCannon1);

        Cannon blackCannon2 = new Cannon(PieceControl.Colour.Black, new PositionOnBoard(7, 7), this);

        theboard[7, 7] = blackCannon2;
        blackPieces.Add(blackCannon2);

        Pawn blackPawn1 = new Pawn(PieceControl.Colour.Black, new PositionOnBoard(0, 6), this);

        theboard[0, 6] = blackPawn1;
        blackPieces.Add(blackPawn1);

        Pawn blackPawn2 = new Pawn(PieceControl.Colour.Black, new PositionOnBoard(2, 6), this);

        theboard[2, 6] = blackPawn2;
        blackPieces.Add(blackPawn2);

        Pawn blackPawn3 = new Pawn(PieceControl.Colour.Black, new PositionOnBoard(4, 6), this);

        theboard[4, 6] = blackPawn3;
        blackPieces.Add(blackPawn3);

        Pawn blackPawn4 = new Pawn(PieceControl.Colour.Black, new PositionOnBoard(6, 6), this);

        theboard[6, 6] = blackPawn4;
        blackPieces.Add(blackPawn4);

        Pawn blackPawn5 = new Pawn(PieceControl.Colour.Black, new PositionOnBoard(8, 6), this);

        theboard[8, 6] = blackPawn5;
        blackPieces.Add(blackPawn5);

        //setting up all the red pieces (button half of board)
        //add each pieces to the board and to the red pieces list
        King redKing = new King(PieceControl.Colour.Red, new PositionOnBoard(4, 0), this);

        theboard[4, 0] = redKing;
        redPieces.Add(redKing);

        Guard redGuard1 = new Guard(PieceControl.Colour.Red, new PositionOnBoard(3, 0), this);

        theboard[3, 0] = redGuard1;
        redPieces.Add(redGuard1);

        Guard redGuard2 = new Guard(PieceControl.Colour.Red, new PositionOnBoard(5, 0), this);

        theboard[5, 0] = redGuard2;
        redPieces.Add(redGuard2);

        Bishop redBishop1 = new Bishop(PieceControl.Colour.Red, new PositionOnBoard(2, 0), this);

        theboard[2, 0] = redBishop1;
        redPieces.Add(redBishop1);

        Bishop redBishop2 = new Bishop(PieceControl.Colour.Red, new PositionOnBoard(6, 0), this);

        theboard[6, 0] = redBishop2;
        redPieces.Add(redBishop2);

        Knight redKnight1 = new Knight(PieceControl.Colour.Red, new PositionOnBoard(1, 0), this);

        theboard[1, 0] = redKnight1;
        redPieces.Add(redKnight1);

        Knight redKnight2 = new Knight(PieceControl.Colour.Red, new PositionOnBoard(7, 0), this);

        theboard[7, 0] = redKnight2;
        redPieces.Add(redKnight2);

        Rook redRook1 = new Rook(PieceControl.Colour.Red, new PositionOnBoard(0, 0), this);

        theboard[0, 0] = redRook1;
        redPieces.Add(redRook1);

        Rook redRook2 = new Rook(PieceControl.Colour.Red, new PositionOnBoard(8, 0), this);

        theboard[8, 0] = redRook2;
        redPieces.Add(redRook2);

        Cannon redCannon1 = new Cannon(PieceControl.Colour.Red, new PositionOnBoard(1, 2), this);

        theboard[1, 2] = redCannon1;
        redPieces.Add(redCannon1);

        Cannon redCannon2 = new Cannon(PieceControl.Colour.Red, new PositionOnBoard(7, 2), this);

        theboard[7, 2] = redCannon2;
        redPieces.Add(redCannon2);

        Pawn redPawn1 = new Pawn(PieceControl.Colour.Red, new PositionOnBoard(0, 3), this);

        theboard[0, 3] = redPawn1;
        redPieces.Add(redPawn1);

        Pawn redPawn2 = new Pawn(PieceControl.Colour.Red, new PositionOnBoard(2, 3), this);

        theboard[2, 3] = redPawn2;
        redPieces.Add(redPawn2);

        Pawn redPawn3 = new Pawn(PieceControl.Colour.Red, new PositionOnBoard(4, 3), this);

        theboard[4, 3] = redPawn3;
        redPieces.Add(redPawn3);

        Pawn redPawn4 = new Pawn(PieceControl.Colour.Red, new PositionOnBoard(6, 3), this);

        theboard[6, 3] = redPawn4;
        redPieces.Add(redPawn4);

        Pawn redPawn5 = new Pawn(PieceControl.Colour.Red, new PositionOnBoard(8, 3), this);

        theboard[8, 3] = redPawn5;
        redPieces.Add(redPawn5);


        //redPawn3.LinktoBoard(this);
        List <PositionOnBoard> ans = redPawn3.LegalMoves();
    }
Esempio n. 7
0
    internal PieceControl[,] boardFor(int[,] boardFromInts)
    {
        BoardAI newBoard = new BoardAI(numberofColumns, numberOfRows);

        PieceControl[,] placeHolder = new PieceControl[numberofColumns, numberOfRows];

        for (int col = 0; col < numberofColumns; col++)
        {
            for (int row = 0; row < numberOfRows; row++)
            {
                switch (boardFromInts[col, row])
                {
                case 0:

                    placeHolder[col, row] = new BlankSpace(new PositionOnBoard(col, row));
                    break;

                case 1:

                    placeHolder[col, row] = new King(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 2:

                    placeHolder[col, row] = new King(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard);
                    break;

                case 3:

                    placeHolder[col, row] = new Guard(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 4:

                    placeHolder[col, row] = new Guard(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard);
                    break;

                case 5:

                    placeHolder[col, row] = new Bishop(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 6:

                    placeHolder[col, row] = new Bishop(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard);
                    break;

                case 7:

                    placeHolder[col, row] = new Knight(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 8:

                    placeHolder[col, row] = new Knight(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 9:

                    placeHolder[col, row] = new Rook(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 10:

                    placeHolder[col, row] = new Rook(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard);
                    break;

                case 11:

                    placeHolder[col, row] = new Cannon(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 12:

                    placeHolder[col, row] = new Cannon(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard);
                    break;

                case 13:

                    placeHolder[col, row] = new Pawn(PieceControl.Colour.Black, new PositionOnBoard(col, row), newBoard);
                    break;

                case 14:

                    placeHolder[col, row] = new Pawn(PieceControl.Colour.Red, new PositionOnBoard(col, row), newBoard);
                    break;
                }
            }
        }

        return(placeHolder);
    }