Exemple #1
0
    private static void Walk(MatrixCoords currentPosition, int matrixSize)
    {
        bool neighbouringCellEmpty = true;
        MatrixCoords direction = new MatrixCoords();
        direction.Row = 1;
        direction.Col = 1;

        while (true)
        {
            matrix[currentPosition.Row, currentPosition.Col] = currentNumber;
            neighbouringCellEmpty = CheckNeighbouringCells(currentPosition);

            if (neighbouringCellEmpty)
            {
                while (currentPosition.Row + direction.Row >= matrixSize || currentPosition.Row + direction.Row < 0 || 
                    currentPosition.Col + direction.Col >= matrixSize || currentPosition.Col + direction.Col < 0 || 
                    matrix[currentPosition.Row + direction.Row, currentPosition.Col + direction.Col] != 0)
                {
                    direction = ChangeDirection(direction);
                }
            }
            else
            {
                break;
            }

            currentPosition.Row += direction.Row;
            currentPosition.Col += direction.Col;
            currentNumber++;
        }
    }
Exemple #2
0
    private static MatrixCoords ChangeDirection(MatrixCoords currentDirection)
    {
        InitializeDirectionArrays();

        int direction = 0;

        for (int directionsCounter = 0; directionsCounter < 8; directionsCounter++)
        {
            if (directionRow[directionsCounter] == currentDirection.Row && directionCol[directionsCounter] == currentDirection.Col)
            {
                direction = directionsCounter;
                break;
            }
        }

        if (direction != 7)
        {
            currentDirection.Row = directionRow[direction + 1];
            currentDirection.Col = directionCol[direction + 1];
        }
        else
        {
            currentDirection.Row = directionRow[0];
            currentDirection.Col = directionCol[0];
        }

        return currentDirection;
    }
 public SuperHero(MatrixCoords topLeft, MatrixCoords speed,int attackPower, int defencePower)
     : base(topLeft, heroBody, speed, attackPower, defencePower)
 {
     this.Life = SuperHeroLife;
     this.Gold = SuperHeroGold;
     this.Experience = SuperHeroExpirience;
 }
Exemple #4
0
 public Fence(MatrixCoords topLeft, char[,] body)
     : base(topLeft, body)
 {
     IsDestroyable = true;
     //this.Life = Init.StaticLife;
     this.Life = FenceLife;
 }
Exemple #5
0
 public Villager(MatrixCoords topLeft, char[,] body, MatrixCoords speed, 
     int attackPower, int defencePower, int gold)
     : base(topLeft, body, speed, attackPower, defencePower)
 {
     this.Life = VillagerLife;
     this.Gold = gold;
 }
 public ParticleRepeller(MatrixCoords position, MatrixCoords speed, int repelPower, int repellerRadius)
     : base(position, speed)
 {
     // Here we put minus '-', because we want to repel the particle, not to attract it
     // Other logic is the same as "Particle attractor"
     this.RepelPower = -repelPower;
     this.RepellerRadius = repellerRadius;
 }
 protected MovableObject(MatrixCoords topLeft, char[,] body, MatrixCoords speed, 
     int attackPower, int defencePower)
     : base(topLeft, body)
 {
     this.Speed = speed;
     this.AttackPower = attackPower;
     this.DefensePower = defencePower;
 }
Exemple #8
0
        private void AStarPathFinding(Character pacman, List <Path> paths)
        {
            MatrixCoords currPosition = new MatrixCoords(this.Position.Row, this.Position.Col);

            openList              = new List <MatrixCoords>();
            closedList            = new List <MatrixCoords>();
            firstEqualFoundedWays = new List <KeyValuePair <decimal, MatrixCoords> >();
            shortestDirections    = new List <KeyValuePair <int, Direction> >();
            foundWay              = false;
            int firstDirectionChoose = 0;
            int stepCounter          = 0;

            FindPath(currPosition, paths, pacman, firstDirectionChoose, stepCounter);
        }
Exemple #9
0
 public PlayerAircraft(MatrixCoords topLeft)
     : base(topLeft, new char[, ] {
     { ' ', ' ', ' ', ' ', ' ', ' ', '/', '\\', ' ', ' ', ' ', ' ', ' ' },
     { ' ', ' ', ' ', ' ', ' ', '|', '|', '|', '|', ' ', ' ', ' ', ' ' },
     { ' ', ' ', ' ', ' ', ' ', '|', '|', '|', '|', ' ', ' ', ' ', ' ' },
     { ' ', '/', '-', '-', '-', ' ', '/', '\\', '-', '-', '-', '\\', ' ' },
     { '/', '_', '_', '_', '_', ' ', '|', '|', '_', '_', '_', '_', '\\' },
     { ' ', ' ', ' ', ' ', ' ', '|', '|', '|', '|', ' ', ' ', ' ', ' ' },
     { ' ', ' ', ' ', ' ', ' ', '|', '|', '|', '|', ' ', ' ', ' ', ' ' },
     { ' ', ' ', ' ', ' ', '/', '/', '|', '|', '\\', '\\', ' ', ' ', ' ' },
     { ' ', ' ', ' ', '/', '_', '_', '/', '\\', '_', '_', '\\', ' ', ' ' },
 })
 {
 }
        public MatrixCoords[,] Profile()
        {
            int curRows = (int)this.body.GetLongLength(0);
            int curCols = (int)this.body.GetLongLength(1);

            MatrixCoords[,] profileMatrix = new MatrixCoords[curRows, curCols];
            for (int rows = 0; rows < curRows; rows++)
            {
                for (int cols = 0; cols < curCols; cols++)
                {
                    profileMatrix[rows, cols] = new MatrixCoords(this.topleft.Row + rows, this.topleft.Col + cols);
                }
            }
            return(profileMatrix);
        }
        public override bool Equals(object obj)
        {
            MatrixCoords temp = obj as MatrixCoords;

            if (temp == null)
            {
                return(false);
            }
            else if (temp == this)
            {
                return(true);
            }

            return(false);
        }
 public MovableObject(MatrixCoords coords, char[,] body,
                      int healthPoints,
                      int manaPoints,
                      int attack,
                      int experience,
                      int level,
                      Weapon weapon)
     : base(coords, body)
 {
     this.Health       = healthPoints;
     this.AttackPoints = attack;
     this.Mana         = manaPoints;
     this.Level        = level;
     this.Experience   = experience;
     this.Weapon       = weapon;
 }
Exemple #13
0
        private List <Path> FindPossibleWaysToMove(MatrixCoords currPosition, List <Path> paths)
        {
            List <Path> fourPossiblePaths = new List <Path>();

            fourPossiblePaths.Add(paths.FirstOrDefault(x => currPosition.TopPosition == x.Position));
            fourPossiblePaths.Add(paths.FirstOrDefault(x => currPosition.BottomPosition == x.Position));
            fourPossiblePaths.Add(paths.FirstOrDefault(x => currPosition.LeftPosition == x.Position));
            fourPossiblePaths.Add(paths.FirstOrDefault(x => currPosition.RightPosition == x.Position));
            fourPossiblePaths.RemoveAll(x => x == null);

            foreach (var item in closedList)
            {
                fourPossiblePaths.RemoveAll(x => x.Position == item);
            }

            return(fourPossiblePaths);
        }
Exemple #14
0
        public void FindPath(MatrixCoords currPosition, List <Path> paths, Character pacman, int firstChooseDirection, int stepCounter)
        {
            closedList.Add(new MatrixCoords(currPosition.Row, currPosition.Col));
            List <Path> fourPossiblePaths = FindPossibleWaysToMove(currPosition, paths);

            AddPathsToOpenList(fourPossiblePaths);
            RemoveClosedPathsFromOpenList();

            List <KeyValuePair <decimal, MatrixCoords> > foundedWays = new List <KeyValuePair <decimal, MatrixCoords> >();

            firstChooseDirection++;
            stepCounter++;

            foreach (var startPos in openList)
            {
                if (startPos == pacman.Position)
                {
                    ProceedWhenFindPacman(paths, pacman, firstChooseDirection, stepCounter);
                }

                decimal distanceDifference = CalculateDistanceDifference(startPos, pacman.Position);

                foundedWays.Add(new KeyValuePair <decimal, MatrixCoords>(distanceDifference, startPos));
            }

            if (firstChooseDirection == 1) // will be true only first time when this method is called
            {
                foundedWays = RemoveForbiddenDirections(foundedWays);
                this.firstEqualFoundedWays = CloneEqualWays(foundedWays);
            }

            foundedWays = foundedWays.OrderBy(x => x.Key).ToList();

            foreach (var distance in foundedWays)
            {
                if (foundWay)
                {
                    return;
                }
                else
                {
                    FindPath(distance.Value, paths, pacman, firstChooseDirection, stepCounter);
                }
            }
        }
Exemple #15
0
    public static string WalkThroughMatrix(int matrixSize)
    {
        matrix = new int[matrixSize, matrixSize];
        currentPosition.Row = 0;
        currentPosition.Col = 0;
        currentNumber = 1;

        Walk(currentPosition, matrixSize);
        currentPosition = FindNewStartPosition(matrix);

        if (currentPosition.Row != 0 && currentPosition.Col != 0)
        {
            currentNumber++;
            Walk(currentPosition, matrixSize);
        }

        return ConstructResult(matrixSize);
    }
    public static Block GenerateRandomBlock(MatrixCoords coords)
    {
        int randomNumber = rnd.Next(12);

        switch (randomNumber)
        {
            case 1:
            case 2:
            case 3: return new Block(coords);
            case 4:
            case 5:
            case 6: return new ExplodingBlock(coords);
            case 7:
            case 8:
            case 9:
            case 10: return new GiftBlock(coords);
            case 11: return new UnpassableBlock(coords);
            default: return new Block(coords);
        }
    }
Exemple #17
0
        public virtual void Move(Direction direction)
        {
            int newRow = this.Position.Row;
            int newCol = this.Position.Col;

            this.oldPosition = new MatrixCoords(this.Position.Row, this.Position.Col);

            switch (direction)
            {
            case Direction.Up: newRow -= 1; break;

            case Direction.Down: newRow += 1; break;

            case Direction.Right: newCol += 1; break;

            case Direction.Left: newCol -= 1; break;

            default:
                throw new InvalidOperationException("Invalid direction provided.");
            }
            this.Position = new MatrixCoords(newRow, newCol);
        }
Exemple #18
0
        public void EnqueueForRendering(IRenderable obj)
        {
            char[,] objImage = this.images[obj.GetType()];

            int imageRows = objImage.GetLength(0);
            int imageCols = objImage.GetLength(1);

            MatrixCoords objTopLeft = obj.TopLeft;

            int lastRow = Math.Min(objTopLeft.Row + imageRows, this.WorldRows);
            int lastCol = Math.Min(objTopLeft.Col + imageCols, this.WorldCols);

            for (int row = obj.TopLeft.Row; row < lastRow; row++)
            {
                for (int col = obj.TopLeft.Col; col < lastCol; col++)
                {
                    if (row >= 0 && col >= 0)
                    {
                        this.renderMatrix[row, col] = objImage[row - obj.TopLeft.Row, col - obj.TopLeft.Col];
                    }
                }
            }
        }
Exemple #19
0
    public static Block GenerateRandomBlock(MatrixCoords coords)
    {
        int randomNumber = rnd.Next(12);

        switch (randomNumber)
        {
        case 1:
        case 2:
        case 3: return(new Block(coords));

        case 4:
        case 5:
        case 6: return(new ExplodingBlock(coords));

        case 7:
        case 8:
        case 9:
        case 10: return(new GiftBlock(coords));

        case 11: return(new UnpassableBlock(coords));

        default: return(new Block(coords));
        }
    }
Exemple #20
0
 public Gift(MatrixCoords topLeft, char[,] body)
     : base(topLeft, body, new MatrixCoords(1, 0))
 {
 }
Exemple #21
0
 public Thief(MatrixCoords coords, char[,] body)
     : base(coords, body, 50, 50, 1, 0, 1, new Knife("qk knife"))
 {
 }
Exemple #22
0
 protected Character(MatrixCoords topLeft, char[,] body, MatrixCoords speed,
     int attackPower, int defencePower)
     : base(topLeft, body, speed, attackPower, defencePower)
 {
 }
Exemple #23
0
 public UnpassableBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = UnpassableBlock.Symbol;
 }
Exemple #24
0
 public Hen(MatrixCoords topLeft)
     : base(topLeft, LivestockType.Hen)
 {
 }
 public UnpassableBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
 }
Exemple #26
0
 protected Animal(MatrixCoords topLeft)
     : base(topLeft)
 {
 }
Exemple #27
0
        public override bool Equals(object obj)
        {
            MatrixCoords objAsMatrixCoords = (MatrixCoords)obj;

            return(objAsMatrixCoords.Row == this.Row && objAsMatrixCoords.Col == this.Col);
        }
 public UnpassableBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = UnpassableBlock.Symbol;
 }
 public UnstoppableBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
     this.body[0,0] = Symbol;
 }
Exemple #30
0
 public House(MatrixCoords topLeft)
     : base(topLeft, HouseBody)
 {
     IsDestroyable = false;
     this.Life = int.MaxValue;
 }
 public Fox(MatrixCoords topLeft)
     : base(topLeft)
 {
 }
Exemple #32
0
 protected FarmFood(MatrixCoords topLeft, Enum type)
     : base(topLeft)
 {
     this.Type = type;
 }
Exemple #33
0
 public Bullet(MatrixCoords topLeft, char[,] body, MatrixCoords speed)
     : base(topLeft, body, speed)
 {
 }
 public ParticleRepeller(MatrixCoords position, MatrixCoords speed, int repulsiveForce, int radius)
     : base(position, speed)
 {
     this.RepulsiveForce = repulsiveForce;
     this.Radius         = radius;
 }
 protected Villain(MatrixCoords topLeft)
     : base(topLeft)
 {
 }
Exemple #36
0
 public Warrior(MatrixCoords topLeft, MatrixCoords speed, int attackPower = 20, int defencePower = 200)
     : base(topLeft, warriorBody, speed, attackPower, defencePower)
 {
     this.Life = WarriorLife;
 }
Exemple #37
0
 public Splinter(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[,] { { '*' } }, speed)
 {
 }
Exemple #38
0
 public Bullet(MatrixCoords topLeft)
     : base(topLeft, new char[, ] {
     { '.' }
 }, new MatrixCoords(-1, 0))
 {
 }
Exemple #39
0
 public UnstoppableBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
 }
 public Rabbit(MatrixCoords topLeft)
     : base(topLeft, LivestockType.Rabbit)
 {
 }
 public Shot(MatrixCoords topLeft, MatrixCoords speed) : base(topLeft, new char[, ] {
     { '|' }
 }, speed)
 {
 }
 public BigBomb(MatrixCoords topLeft, MatrixCoords speed) : base(topLeft, new char[, ] {
     { '#', '#' },
     { '#', '#' }
 }, speed)
 {
 }
Exemple #43
0
 public Explode(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[,] { { Explode.Symbol } }, speed)
 {
 }
Exemple #44
0
 public BonusLifeScore(char symbol, MatrixCoords position)
     : base(symbol, position)
 {
     base.value = Constant.SuperBonusScoreValue;
 }
Exemple #45
0
 public Rabbit(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, rabbitBody, speed, AnimalAttack, 0)
 {
     this.Life = AnimalLife;
     this.Bonus = AnimalBonus;
 }
 // Constructor
 public IndestructibleBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = IndestructibleBlock.Symbol;
 }
 public Hen(MatrixCoords topLeft)
     : base(topLeft, LivestockType.Hen)
 {
 }
Exemple #48
0
 public Wolf(MatrixCoords topLeft, MatrixCoords speed, int attackPower)
     : base(topLeft, wolfBody, speed, attackPower, 0)
 {
     this.Life = AnimalLife;
     this.Bonus = AnimalAttack;
 }
 public MovingObject(MatrixCoords topLeft, char[,] body, MatrixCoords speed)
     : base(topLeft, body)
 {
     this.Speed = speed;
 }
Exemple #50
0
 protected Animal(MatrixCoords topLeft, char[,] body, MatrixCoords speed, 
     int attackPower, int defencePower)
     : base(topLeft, body, speed, attackPower, defencePower)
 {
     this.Bonus = attackPower;
 }
Exemple #51
0
 public Ball(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[,] { { 'o' } }, speed)
 {
 }
Exemple #52
0
 public SmallBomb(MatrixCoords topLeft, MatrixCoords speed) : base(topLeft, new char[, ] {
     { '*' }
 }, speed)
 {
 }
Exemple #53
0
 public Gift(MatrixCoords topLeft, char[,] body)
     : base(topLeft, body, new MatrixCoords(1, 0))
 {
 }
Exemple #54
0
 public EnemyShip(MatrixCoords topLeft) : base(topLeft, new char[, ] {
     { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', }
 })
 {
 }
Exemple #55
0
 protected GameObject(char symbol, MatrixCoords position)
 {
     this.Symbol   = symbol;
     this.Position = position;
     this.IsAlive  = true;
 }
 public ShootingRacket(MatrixCoords topLeft, int width)
     : base(topLeft, width)
 {
 }
 public Raspberry(MatrixCoords topLeft)
     : base(topLeft, FarmFoodType.Raspberry)
 {
 }
 public Lamb(MatrixCoords topLeft)
     : base(topLeft, LivestockType.Lamb)
 {
 }
Exemple #59
0
 public Path(char symbol, MatrixCoords position)
     : base(symbol, position)
 {
     base.team = Team.Path;
 }
Exemple #60
0
 public WorldObject(MatrixCoords coords, char[,] body)
     : base(coords, body)
 {
 }