示例#1
0
文件: Navigator.cs 项目: Cendrb/Arman
 public void GoToPosition(PositionInGrid pos)
 {
     Direction direction = PositionInGrid.GetDirection(entity.Position, pos);
     if (!entity.IsMoving)
         if (!entity.Move(direction))
             completed();
 }
        void it_knows_how_to_instantiate_itself_from_a_scalar_and_grid_size()
        {
            var position = PositionInGrid.FromScalarForGridOfSize(9, 4);

            position.row.should_be(2);
            position.column.should_be(1);
        }
示例#3
0
文件: Player.cs 项目: Cendrb/Arman
 public Player(Arman game, PositionInGrid positionInGrid, Texture2D texture, Block[,] gameArray, int oneBlockSize, int timeForMove, List<Entity> movableObjects, GameArea gameArea, Controls controls)
     : base(game, positionInGrid, texture, gameArray, oneBlockSize, timeForMove, movableObjects)
 {
     this.gameArea = gameArea;
     this.controls = controls;
     spawnPoint = positionInGrid;
 }
示例#4
0
文件: Key.cs 项目: oursuccess/Meet
 public override void ThingMoveToMe(Element element, PositionInGrid direction)
 {
     if (element is Character character)
     {
         ThingHoldMe(character);
     }
 }
示例#5
0
    protected override void Move(int Horizontal, int Vertical)
    {
        var canMove   = true;
        var direction = new PositionInGrid(Horizontal, Vertical);

        foreach (var element in ChainedElements)
        {
            if (!element.CanMoveTo(direction))
            {
                canMove = false;
            }
        }
        if (canMove)
        {
            foreach (var element in ChainedElements)
            {
                var xPrev       = element.PositionInGrid.x - Horizontal;
                var yPrev       = element.PositionInGrid.y + Vertical;
                var prevElement = Board.GetElementOfPosition(xPrev, yPrev);
                //Debug.Log("Try Moving Element: " + element + " PositionX: " + element.PositionInGrid.x + " y: " + element.PositionInGrid.y);
                //Debug.Log("xPrev: " + xPrev + " yPrev: " + yPrev + " prevElement: " + prevElement);
                if (!ChainedElements.Contains(prevElement))
                {
                    //Debug.Log("moving " + element);
                    element.MoveTo(direction);
                }
            }
        }
    }
示例#6
0
文件: Mob.cs 项目: Cendrb/Arman
 public Mob(PositionInGrid position, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable, int scanRange, int wanderRange, int wanderChance)
     : base(position, "Mob", canPush, canBePushed, speed, collides, health, invulnerable)
 {
     Vision = scanRange;
     WanderRange = wanderRange;
     WanderChance = wanderChance;
 }
示例#7
0
文件: Block.cs 项目: Cendrb/Arman
 /// <summary>
 /// 
 /// </summary>
 /// <param name="game">Main game</param>
 /// <param name="spriteBatch">Where to draw textures</param>
 /// <param name="position">Where it should be placed</param>
 public Block(Game game, SpriteBatch spriteBatch, PositionInGrid position)
     : base(game)
 {
     this.game = game;
     Position = position;
     this.spriteBatch = spriteBatch;
 }
示例#8
0
文件: Detector.cs 项目: Cendrb/Arman
 public Detector(PositionInGrid position, double blastResistance, ArmanColor lockColor, bool blockMovableBlockOnApproach, bool isPartOfObjectives, PositionInGrid affectedPosition)
     : base(position, "Detector", false, blastResistance)
 {
     BlockMovableBlockOnApproach = blockMovableBlockOnApproach;
     LockColor = lockColor;
     IsPartOfObjectives = isPartOfObjectives;
     AffectedPosition = affectedPosition;
 }
示例#9
0
文件: Detector.cs 项目: Cendrb/Arman
 public Detector(PositionInGrid position, string name, double blastResistance, ArmanColor lockColor, bool blockMovableBlockOnApproach, bool isPartOfObjectives)
     : base(position, name, false, blastResistance)
 {
     BlockMovableBlockOnApproach = blockMovableBlockOnApproach;
     LockColor = lockColor;
     IsPartOfObjectives = isPartOfObjectives;
     AffectedPosition = new PositionInGrid(-1);
 }
示例#10
0
文件: Block.cs 项目: Cendrb/Arman
 public Block(Arman game, BlockType type, PositionInGrid position, int oneBlockSize)
     : base(game)
 {
     this.game = game;
     Type = type;
     Position = position;
     this.oneBlockSize = oneBlockSize;
 }
示例#11
0
文件: Entity.cs 项目: Cendrb/Arman
 public Entity(PositionInGrid position, string name, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable)
     : base(position, name)
 {
     Collides = collides;
     Speed = speed;
     Health = health;
     Invulnerable = invulnerable;
 }
示例#12
0
文件: Key.cs 项目: oursuccess/Meet
 public override bool ThingCanMoveToMe(Element element, PositionInGrid direction)
 {
     if (element is Character character)
     {
         return(true);
     }
     return(false);
 }
示例#13
0
文件: GameArea.cs 项目: Cendrb/Arman
 public void CreateBlock(BlockType type, PositionInGrid position)
 {
     if (type == BlockType.movable)
         entities.Add(new MovableBlock(game, position, game.Content.Load<Texture2D>(@"Sprites/Blocks/movable"), gameArray, blockSize, gameSpeed, entities));
     else if (type == BlockType.detector)
         gameArray[position.X, position.Y] = loadAndInitializeBlock(new Detector(game, BlockType.detector, position, blockSize, detectorActivated));
     else
         gameArray[position.X, position.Y] = loadAndInitializeBlock(new Block(game, type, position, blockSize));
 }
示例#14
0
        void it_is_able_to_retrieved_cells_by_position_in_grid()
        {
            var position = new PositionInGrid(1, 2);
            var cell     = _subject.CellAt(position);

            cell.value.should_be(6);
            cell.position.column.should_be(position.column);
            cell.position.row.should_be(position.row);
        }
示例#15
0
    public override bool ThingCanMoveToMe(Element element, PositionInGrid direction)
    {
        bool CanMove = false;

        if (CanMoveTo(direction))
        {
            CanMove = true;
        }
        return(CanMove);
    }
示例#16
0
 public virtual void MoveTo(PositionInGrid direction)
 {
     Board.ElementMoveTo(this, direction.x, direction.y);
     if (AudioSource && MoveSound)
     {
         AudioSource.clip = MoveSound;
         AudioSource.Play();
     }
     OnMoving?.Invoke(this);
     transform.position += new Vector3(direction.x, direction.y);
 }
示例#17
0
文件: Entity.cs 项目: Cendrb/Arman
 public Entity(Arman game, PositionInGrid positionInGrid, Texture2D texture, Block[,] gameArray, int oneBlockSize, int timeForMove, List<Entity> movableObjects)
 {
     Blocked = false;
     this.game = game;
     PositionInGrid = positionInGrid;
     this.Texture = texture;
     this.gameArray = gameArray;
     isMoving = false;
     this.timeForMove = timeForMove;
     this.oneBlockSize = oneBlockSize;
     this.movableObjects = movableObjects;
     movingDifference = 0.0F;
     movingDirection = Direction.up;
 }
示例#18
0
文件: Mob.cs 项目: Cendrb/Arman
        public Mob(Arman game, PositionInGrid positionInGrid, Texture2D texture, Block[,] gameArray, int oneBlockSize, int timeForMove, List<Entity> entities, int range, int aditionalTimeForMove, int movingFrequency)
            : base(game, positionInGrid, texture, gameArray, oneBlockSize, timeForMove, entities)
        {
            players = from entity in entities
                      where entity is Player
                      select (Player)entity;
            mobs = from entity in entities
                   where entity is Mob
                   select (Mob)entity;

            this.movingFrequency = movingFrequency;

            Range = range;

            this.timeForMove += aditionalTimeForMove;
        }
示例#19
0
文件: Entity.cs 项目: Cendrb/Arman
 public Entity(PositionInGrid position, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable)
     : base(position, "Generic entity")
 {
     if (collides)
     {
         CanPush = canPush;
         CanBePushed = canBePushed;
     }
     else
     {
         CanPush = false;
         CanBePushed = false;
     }
     Collides = collides;
     Speed = speed;
     Health = health;
     Invulnerable = invulnerable;
 }
示例#20
0
        public MainWindow()
        {
            InitializeComponent();
            data = new GameData();
            dataStack = new Stack<GameData>();
            data.OneBlockSize = 20;
            firstPosition = new PositionInGrid(0);
            secondPosition = new PositionInGrid(0);

            blocksLayerCheckBox.IsChecked = true;
            entitiesLayerCheckBox.IsChecked = true;

            activateDetectors.IsChecked = true;
            collectCoins.IsChecked = false;
            getHome.IsChecked = false;

            disableControlsForLevel();
        }
示例#21
0
 public override void ThingMoveToMe(Element element, PositionInGrid direction)
 {
     MoveTo(direction);
     if (element is Character character)
     {
         if (this.character == null)
         {
             this.character = character;
         }
         if (this.character != character)
         {
             this.character.OnMoving -= WaitToActivate;
             this.character           = character;
         }
         if (this.character != null)
         {
             this.character.OnMoving += WaitToActivate;
         }
     }
 }
示例#22
0
 public abstract void ThingMoveToMe(Element element, PositionInGrid direction);
示例#23
0
 public void SetPosition(PositionInGrid position)
 {
     PositionInGrid = position;
 }
示例#24
0
 public override bool ThingCanMoveToMe(Element element, PositionInGrid direction)
 {
     return(CanMoveTo(direction));
 }
示例#25
0
 public bool CanMoveTo(PositionInGrid direction)
 {
     return(Board.CanMoveTo(this, direction.x, direction.y));
 }
示例#26
0
文件: GameArea.cs 项目: Cendrb/Arman
 /// <summary>
 /// 
 /// </summary>
 /// <param name="position"></param>
 /// <param name="range"></param>
 /// <param name="speed"></param>
 /// <param name="movingFrequency">higher = smaller chance - number for random generator of direction</param>
 public void SpawnMob(PositionInGrid position, int range, int speed, int movingFrequency)
 {
     int movingFreq = movingFrequency + 4; //zamezení aby potvora nechodila poøád do jednoho smìru pøi zadání nízké hodnoty
     entities.Add(new Mob(game, position, game.Content.Load<Texture2D>(@"Sprites/potvora"), gameArray, blockSize, gameSpeed, entities, range, speed, movingFreq));
 }
示例#27
0
 private void removeBlock_Checked(object sender, RoutedEventArgs e)
 {
     LevelView view = new LevelView(data);
     view.ShowDialog();
     blockToRemove = view.choosenPosition;
 }
示例#28
0
 private void levelCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     Point point = e.GetPosition((Canvas)sender);
     choosenPosition = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize);
     this.Close();
 }
示例#29
0
 private void levelCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
 {
     Point point = e.GetPosition((Canvas)sender);
     PositionInGrid position = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize);
     firstPosition = position;
 }
示例#30
0
        private void levelCanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            dataStack.Push(data.Clone());
            // Příprava na následující akci
            blocksEnabled = (bool)blocksLayerCheckBox.IsChecked;
            entitiesEnabled = (bool)entitiesLayerCheckBox.IsChecked;

            Point point = e.GetPosition((Canvas)sender);
            PositionInGrid position2 = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize);
            secondPosition = position2;

            DoActionForEveryPositionInRectangle(firstPosition, secondPosition, delegate(PositionInGrid position)
            {
                if (blocksEnabled)
                {
                    foreach (Block block in data.Blocks.ToList())
                    {
                        if (block.Position == position && !(block is Air))
                        {
                            data.Blocks.Add(new Air(position));
                            data.Blocks.Remove(block);
                        }
                    }
                }
                if (entitiesEnabled)
                {
                    foreach (Entity entity in data.Entities.ToList())
                    {
                        if (entity.Position == position)
                            data.Entities.Remove(entity);
                    }
                }
            });
            refresh();
            changesSaved = false;
        }
示例#31
0
        private void DoActionForEveryPositionInRectangle(PositionInGrid firstPosition, PositionInGrid secondPosition, Action<PositionInGrid> action)
        {
            List<PositionInGrid> positions = new List<PositionInGrid>();

            if (firstPosition.Y <= secondPosition.Y)
            {
                for (int y = firstPosition.Y; y <= secondPosition.Y; y++)
                    if (firstPosition.X <= secondPosition.X)
                        for (int x = firstPosition.X; x <= secondPosition.X; x++)
                            positions.Add(new PositionInGrid(x, y));
                    else
                        for (int x = firstPosition.X; x >= secondPosition.X; x--)
                            positions.Add(new PositionInGrid(x, y));
            }
            else
            {
                for (int y = firstPosition.Y; y >= secondPosition.Y; y--)
                    if (firstPosition.X <= secondPosition.X)
                        for (int x = firstPosition.X; x <= secondPosition.X; x++)
                            positions.Add(new PositionInGrid(x, y));
                    else
                        for (int x = firstPosition.X; x >= secondPosition.X; x--)
                            positions.Add(new PositionInGrid(x, y));
            }
            foreach (PositionInGrid pos in positions)
                action(pos);
        }
示例#32
0
        private void levelCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            dataStack.Push(data.Clone());
            Point point = e.GetPosition((Canvas)sender);
            PositionInGrid position2 = new PositionInGrid((int)point.X / data.OneBlockSize, (int)point.Y / data.OneBlockSize);

            secondPosition = position2;

            // Setblocks
            DoActionForEveryPositionInRectangle(firstPosition, secondPosition, delegate(PositionInGrid position)
            {
                switch (ChoosenTool)
                {
                    case Tools.air:
                        #region Air
                        foreach (Block block in data.Blocks.ToList())
                        {
                            if (block.Position == position)
                                data.Blocks.Remove(block);
                        }
                        data.Blocks.Add(new Air(position));
                        #endregion
                        break;
                    case Tools.coin:
                        #region Coin
                        foreach (Block block in data.Blocks.ToList())
                        {
                            if (block.Position == position)
                                data.Blocks.Remove(block);
                        }
                        Windows.Coin coinWindow = new Windows.Coin();
                        coinWindow.ShowDialog();
                        try
                        {
                            data.Blocks.Add(new Coin(position, coinWindow.blastResistance.Value.Value, coinWindow.valueUpDown.Value.Value));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error while parsing data from form  - " + ex.Message, "Error");
                        }
                        refresh();
                        #endregion
                        break;
                    case Tools.detector:
                        #region Detector
                        foreach (Block block in data.Blocks.ToList())
                        {
                            if (block.Position == position)
                                data.Blocks.Remove(block);
                        }

                        // prepare variables
                        Color color;
                        bool blockMovableBlockOnApproach, addToObjectives;

                        Windows.Detector detector = new Windows.Detector(data);
                        detector.ShowDialog();
                        try
                        {
                            blockMovableBlockOnApproach = detector.blockPlacedMovableBlockCheckBox.IsChecked.Value;
                            color = detector.colorPicker.SelectedColor;
                            addToObjectives = detector.objectives.IsChecked.Value;
                            if (detector.removeBlock.IsChecked == true)
                                data.Blocks.Add(new Detector(position, 69.0, ArmanColor.ParseWindowsColor(color), blockMovableBlockOnApproach, addToObjectives, detector.blockToRemove));
                            else
                                data.Blocks.Add(new Detector(position, 69.0, ArmanColor.ParseWindowsColor(color), blockMovableBlockOnApproach, addToObjectives, new PositionInGrid(-1)));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error while parsing data from form  - " + ex.Message, "Error");
                        }
                        refresh();
                        #endregion
                        break;
                    case Tools.home:
                        #region Home
                        foreach (Block block in data.Blocks.ToList())
                        {
                            if (block.Position == position)
                                data.Blocks.Remove(block);
                        }

                        data.Blocks.Add(new Home(position, 69.0));
                        #endregion
                        break;
                    case Tools.mob:
                        #region Mob
                        foreach (Entity entity in data.Entities.ToList())
                        {
                            if (entity.Position == position)
                                data.Entities.Remove(entity);
                        }

                        // Prepare data
                        Windows.Mob mob = new Windows.Mob();
                        mob.speedLabel.ToolTip = "Set speed of mob (-Infinity - " + data.OneBlockSize + ")";
                        mob.speed.ToolTip = "Set speed of mob (-Infinity - " + data.OneBlockSize + ")";
                        mob.ShowDialog();
                        try
                        {
                            data.Entities.Add(new Mob(position, mob.nameTextBox.Text, mob.canPushCheckBox.IsChecked.Value, mob.canBePushedCheckBox.IsChecked.Value, (float)mob.speed.Value.Value, mob.collides.IsChecked.Value, mob.health.Value.Value, mob.invulnerable.IsChecked.Value, mob.vision.Value.Value, mob.wanderRange.Value.Value, mob.wanderChance.Value.Value));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error while parsing data from form  - " + ex.Message, "Error");
                        }
                        refresh();
                        #endregion
                        break;
                    case Tools.movable:
                        #region Movable Block
                        foreach (Entity entity in data.Entities)
                        {
                            if (entity.Position == position)
                                data.Entities.Remove(entity);
                        }

                        // Prepare data
                        Windows.MovableBlock mo = new Windows.MovableBlock();
                        mo.ShowDialog();

                        try
                        {
                            data.Entities.Add(new MovableBlock(position, mo.nameTextBox.Text, mo.canPushCheckBox.IsChecked.Value, mo.canBePushedCheckBox.IsChecked.Value, ArmanColor.ParseWindowsColor(mo.colorPicker.SelectedColor)));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error while parsing data from form  - " + ex.Message, "Error");
                        }
                        refresh();
                        #endregion
                        break;
                    case Tools.player:
                        #region Player
                        foreach (Entity entity in data.Entities.ToList())
                        {
                            if (entity.Position == position)
                                data.Entities.Remove(entity);
                        }

                        // Prepare data
                        Windows.Player player = new Windows.Player();
                        player.speedLabel.ToolTip = "Set speed of player (-Infinity - " + data.OneBlockSize + ")";
                        player.speed.ToolTip = "Set speed of player (-Infinity - " + data.OneBlockSize + ")";
                        player.ShowDialog();
                        try
                        {
                            data.Entities.Add(new Player(position, player.nameTextBox.Text, player.canPushCheckBox.IsChecked.Value, player.canBePushedCheckBox.IsChecked.Value, (float)player.speed.Value, true, 69.0, (bool)player.invulnerable.IsChecked,
                                new Controls(player.upText.Text, player.downText.Text, player.leftText.Text, player.rightText.Text), (int)player.lives.Value));
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error while parsing data from form  - " + ex.Message, "Error");
                        }
                        refresh();
                        #endregion
                        break;
                    case Tools.solid:
                        #region Solid

                        foreach (Block block in data.Blocks.ToList())
                        {
                            if (block.Position == position)
                                data.Blocks.Remove(block);
                        }
                        data.Blocks.Add(new Solid(position, 69.0));
                        #endregion
                        break;
                }
            });
            refresh();
            changesSaved = false;
        }
示例#33
0
 public override void MoveTo(PositionInGrid direction)
 {
     Animator.SetTrigger("Move");
     base.MoveTo(direction);
 }
示例#34
0
 public virtual bool ThingCanMoveToMe(Element element, PositionInGrid direction)
 {
     return(false);
 }
示例#35
0
文件: Detector.cs 项目: Cendrb/Arman
 public Detector(Arman game, BlockType type, PositionInGrid position, int oneBlockSize, DetectorActivated detectorActivated)
     : base(game, type, position, oneBlockSize)
 {
     this.detectorActivated = detectorActivated;
     alreadyActivated = false;
 }
示例#36
0
文件: Home.cs 项目: Cendrb/Arman
 public Home(PositionInGrid position, double blastResistence)
     : base(position, "Home", false, blastResistence)
 {
 }
示例#37
0
文件: Player.cs 项目: Cendrb/Arman
 public Player(PositionInGrid position, bool canPush, bool canBePushed, float speed, bool collides, double health, bool invulnerable, Controls controls, int lives)
     : base(position, "Player", canPush, canBePushed, speed, collides, health, invulnerable)
 {
     Lives = lives;
     Controls = controls;
 }
示例#38
0
文件: Home.cs 项目: Cendrb/Arman
 public Home(PositionInGrid position, string name, double blastResistence)
     : base(position, name, false, blastResistence)
 {
 }
 public CellLived()
 {
     position = new PositionInGrid();
 }
示例#40
0
文件: Mob.cs 项目: Cendrb/Arman
 public override bool TryMove(PositionInGrid position)
 {
     foreach(Mob mob in mobs)
     {
         if (mob.PositionInGrid == position)
             return false;
     }
     return base.TryMove(position);
 }
示例#41
0
 public override void ThingMoveToMe(Element element, PositionInGrid direction)
 {
     MoveTo(direction);
 }
 public Cell <int> CellAt(PositionInGrid position)
 {
     return(new Cell <int>(this, position, position.row * position.column));
 }
 public CellLived(int row, int column)
 {
     position = new PositionInGrid(row, column);
 }
示例#44
0
文件: GameArea.cs 项目: Cendrb/Arman
 public void SpawnPlayer(PositionInGrid position, Controls controls)
 {
     entities.Add(new Player(game, position, game.Content.Load<Texture2D>(@"Sprites/player"), gameArray, blockSize, gameSpeed, entities, this, controls));
 }
 public CellLived()
 {
     position = new PositionInGrid();
 }
示例#46
0
 public CellDied()
 {
     position = new PositionInGrid();
 }
 public CellDied(int row, int column)
 {
     position = new PositionInGrid(row, column);
 }
示例#48
0
        void it_is_able_to_retrieve_out_of_bounds_cells_by_position_in_grid()
        {
            var position = new PositionInGrid(1, 4);

            _subject.CellAt(position).value.should_be(default(int));
        }
 public CellDied()
 {
     position = new PositionInGrid();
 }
示例#50
0
 public GameElement(PositionInGrid position, string name)
 {
     Position = position;
     Name = name;
 }
 void before_each()
 {
     _subject = new PositionInGrid(2, 0);
 }