示例#1
0
 // The new constructor
 public TrailObject(MatrixCoords matrixCoord, uint turns)
     : base(matrixCoord, new char[,] { {Symbol} })
 {
     if (turns == 0)
         throw new ArgumentException("Turns of the trailing object must be a positive integer number.");
     this.turns = turns;
 }
 public GiftBlock(MatrixCoords topLeft, Gift gift)
     : base(topLeft)
 {
     this.CurrentGift = gift;
     this.CurrentGift.SetTopLeft(topLeft);
     this.body = new char[,] { { GiftBlock.Symbol } };
 }
        private int shotsLeft; // Bullet Racket has limmited number of shots

        #endregion Fields

        #region Constructors

        public BulletRacket(MatrixCoords topLeft, int width)
            : base(topLeft, width)
        {
            this.body[0, 0] = '!'; // draw left gun
            this.body[0, this.body.GetLength(1)-1] = '!'; // draw right gun
            this.shotsLeft = 10; // Bullet Racket has only 10 shots loaded
            hasShooted = false;
        }
示例#4
0
 public void Print(List<dynamic> infoBar, MatrixCoords topLeft)
 {
     for (int line = 0; line < infoBar.Count; line++)
     {
         Console.SetCursorPosition(topLeft.Col, topLeft.Row + line);
         Console.WriteLine(infoBar[line]);
     }
 }
示例#5
0
 public TrailObject(MatrixCoords topLeft, char[,] body, int lifeTime)
     : base(topLeft, body, new MatrixCoords(0,0))
 {
     if (lifeTime <= 0)
     {
         throw new IndexOutOfRangeException("The life time can not be negative");
     }
     this.lifeTime = lifeTime;
 }
 public void Update(MatrixCoords coords)
 {
     this.Lifetime--;
     if (this.Lifetime <= 0)
     {
         this.IsDestroyed = true;
     }
     this.topLeft = coords;
 }
        public TrailObject(MatrixCoords topLeft, char[,] body, int lifetime)
            : base(topLeft, body)
        {
            if (lifetime < 1)
            {
                throw new ArgumentOutOfRangeException("Life time can not be less then 1.");
            }

            this.lifetime = lifetime;
        }
示例#8
0
 public TrailObject(MatrixCoords topLeft, char[,] body, int lifeTime)
     : base(topLeft, body)
 {
     this.TopLeft = topLeft;
     int imageRows = body.GetLength(0);
     int imageCols = body.GetLength(1);
     this.body = body;
     this.IsDestroyed = false;
     this.LifeTime = lifeTime;
 }
示例#9
0
 public override IEnumerable<GameObject> ProduceObjects()
 {
     List<GameObject> produced = new List<GameObject>();
     if (this.IsDestroyed)
     {
         MatrixCoords newRacketCoords = new MatrixCoords(this.TopLeft.Row + 1, this.TopLeft.Col);
         produced.Add(new ShootingRacket(newRacketCoords, 6));
     }
     return produced;
 }
        protected GameObject(MatrixCoords topLeft, char[,] body)
        {
            this.TopLeft = topLeft;

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

            this.body = this.CopyBodyMatrix(body);

            this.IsDestroyed = false;
        }
示例#11
0
        public CollisionData(MatrixCoords collisionForceDirection, List<string> hitObjectsCollisionGroupStrings)
        {
            this.CollisionForceDirection = collisionForceDirection;

            this.hitObjectsCollisionGroupStrings = new List<string>();

            foreach (var str in hitObjectsCollisionGroupStrings)
            {
                this.hitObjectsCollisionGroupStrings.Add(str);
            }
        }
示例#12
0
        // construktor na obektite
        protected GameObject(MatrixCoords topLeft, char[,] body)
        {
            // wytre6na matrica rawna na podadenta
            this.TopLeft = topLeft;

            int imageRows = body.GetLength(0);
            int imageCols = body.GetLength(1);
            // kopirame w body
            this.body = this.CopyBodyMatrix(body);
            // ne e uni6tojena
            this.IsDestroyed = false;
        }
        public override IEnumerable<GameObject> ProduceObjects()
        {
            if (this.IsDestroyedByRacket)
            {
                // TODO create fire racket
                var racketTopLeft = new MatrixCoords(this.topLeft.Row + 1, this.topLeft.Col);
                var racket = new ShootingRacket(racketTopLeft, 6);

                return new GameObject[] { racket };
            }

            return base.ProduceObjects();
        }
示例#14
0
        public override IEnumerable <GameObject> ProduceObjects()
        {
            List <GameObject> obj = new List <GameObject>();

            if (this.isLoaded == true)
            {
                MatrixCoords bul = this.GetTopLeft();
                bul.Col += this.Width / 2;
                Bullet bullet = new Bullet(bul);
                obj.Add(bullet);
                this.isLoaded = false;
            }
            return(obj);
        }
示例#15
0
        public virtual void Run(List<dynamic> list, MatrixCoords topLeft)
        {
            while (true)
            {
                // Print every object over the screen
                this.renderer.RenderAll();

                // Set game speed
                System.Threading.Thread.Sleep(520 - 5 * Speed);

                // Check for user input
                this.userInterface.ProcessInput();

                // Clear all objects from the screen
                this.renderer.ClearQueue();

                // For each objects the new position is updated
                foreach (var obj in this.allObjects)
                {
                    obj.Update();
                    this.renderer.EnqueueForRendering(obj);
                }

                // Check for collisions
                CollisionDispatcher.HandleCollisions(this.movingObjects, this.staticObjects);

                // Check for produced objects
                List<GameObject> producedObjects = new List<GameObject>();
                foreach (var obj in this.allObjects)
                {
                    producedObjects.AddRange(obj.ProduceObjects(playerRacket.TopLeft.Col));
                }

                // Delete all dead objects
                this.allObjects.RemoveAll(obj => obj.IsDestroyed);
                this.movingObjects.RemoveAll(obj => obj.IsDestroyed);
                this.staticObjects.RemoveAll(obj => obj.IsDestroyed);

                // Add all produced objects in the list
                foreach (var obj in producedObjects)
                {
                    this.AddObject(obj);
                }

                // Print the information field
                Infofield infoField = new Infofield();
                infoField.Print(list, topLeft);
            }
        }
        public override IEnumerable<GameObject> ProduceObjects()
        {
            if (this.CanShoot)
            {
                this.CanShoot = false;

                int col = this.topLeft.Col + (this.Width / 2);
                var bulletTopLeft = new MatrixCoords(this.topLeft.Row, col);
                var bullet = new Bullet(bulletTopLeft);

                return new GameObject[] { bullet };
            }

            return base.ProduceObjects();
        }
示例#17
0
        public override IEnumerable <GameObject> ProduceObjects()
        {
            if (this.CanShoot)
            {
                this.CanShoot = false;

                int col           = this.topLeft.Col + (this.Width / 2);
                var bulletTopLeft = new MatrixCoords(this.topLeft.Row, col);
                var bullet        = new Bullet(bulletTopLeft);

                return(new GameObject[] { bullet });
            }

            return(base.ProduceObjects());
        }
 public static Block GetBlock(int type, MatrixCoords coords)
 {
     switch (type)
     {
         case 1:
         case 2:
         case 3:
         case 4:
         case 5:
         case 6:
             return new Block(coords);
         case 7:
             return new UnpassableBlock(coords);
         case 8:
             return new GiftBlock(coords);
         case 9:
             return new ExplodingBlock(coords);
         default:
             return new Block(coords);
     }
 }
示例#19
0
         public override IEnumerable<GameObject> ProduceObjects()
        {
            List<GameObject> produced = new List<GameObject>();
            MatrixCoords speed = new MatrixCoords(0, 0);

            if (this.IsDestroyed)
            {
                //upper
                for (int col = -1; col <= 1; col++)
                {
                    MatrixCoords tempTopLeft = new MatrixCoords(this.topLeft.Row - 1, this.topLeft.Col + col);
                    ExplosionUnit unit = new ExplosionUnit(tempTopLeft, speed);
                    produced.Add(unit);
                }

                //lower
                for (int col = -1; col <= 1; col++)
                {
                    MatrixCoords tempTopLeft = new MatrixCoords(this.topLeft.Row + 1, this.topLeft.Col + col);
                    ExplosionUnit unit = new ExplosionUnit(tempTopLeft, speed);
                    produced.Add(unit);
                }

                //left
                MatrixCoords leftTopLeft = new MatrixCoords(this.topLeft.Row, this.topLeft.Col - 1);
                ExplosionUnit leftUnit = new ExplosionUnit(leftTopLeft, speed);
                produced.Add(leftUnit);

                //right
                MatrixCoords rightTopLeft = new MatrixCoords(this.topLeft.Row, this.topLeft.Col + 1);
                ExplosionUnit rightUnit = new ExplosionUnit(rightTopLeft, speed);
                produced.Add(rightUnit);
            }

            return produced;
        }
示例#20
0
        public override IEnumerable <GameObject> ProduceObjects()
        {
            List <GameObject> produced = new List <GameObject>();
            MatrixCoords      speed    = new MatrixCoords(0, 0);

            if (this.IsDestroyed)
            {
                //upper
                for (int col = -1; col <= 1; col++)
                {
                    MatrixCoords  tempTopLeft = new MatrixCoords(this.topLeft.Row - 1, this.topLeft.Col + col);
                    ExplosionUnit unit        = new ExplosionUnit(tempTopLeft, speed);
                    produced.Add(unit);
                }

                //lower
                for (int col = -1; col <= 1; col++)
                {
                    MatrixCoords  tempTopLeft = new MatrixCoords(this.topLeft.Row + 1, this.topLeft.Col + col);
                    ExplosionUnit unit        = new ExplosionUnit(tempTopLeft, speed);
                    produced.Add(unit);
                }

                //left
                MatrixCoords  leftTopLeft = new MatrixCoords(this.topLeft.Row, this.topLeft.Col - 1);
                ExplosionUnit leftUnit    = new ExplosionUnit(leftTopLeft, speed);
                produced.Add(leftUnit);

                //right
                MatrixCoords  rightTopLeft = new MatrixCoords(this.topLeft.Row, this.topLeft.Col + 1);
                ExplosionUnit rightUnit    = new ExplosionUnit(rightTopLeft, speed);
                produced.Add(rightUnit);
            }

            return(produced);
        }
示例#21
0
        public void EnqueueForRendering(IRenderable obj)
        {
            char[,] objImage = obj.GetImage();

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

            MatrixCoords objTopLeft = obj.GetTopLeft();

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

            for (int row = obj.GetTopLeft().Row; row < lastRow; row++)
            {
                for (int col = obj.GetTopLeft().Col; col < lastCol; col++)
                {
                    if (row >= 0 && row < renderContextMatrixRows &&
                        col >= 0 && col < renderContextMatrixCols)
                    {
                        renderContextMatrix[row, col] = objImage[row - obj.GetTopLeft().Row, col - obj.GetTopLeft().Col];
                    }
                }
            }
        }
 public IndestructibleBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = IndestructibleBlock.Symbol;
 }
示例#23
0
 public MeteoriteBall(MatrixCoords topLeft, MatrixCoords speed, int trailObjectLifeTime)
     : base(topLeft, speed)
 {
     this.trailObjectLifeTime = trailObjectLifeTime;
 }
示例#24
0
 public UnpassableBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = UnpassableBlock.Symbol;
 }
示例#25
0
 public Gift(MatrixCoords topLeft, char[,] body, MatrixCoords speed)
     : base(topLeft, body, speed)
 { 
     
 }
示例#26
0
 public ExplodingBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
 }
 public Block(MatrixCoords topLeft, char[,] symbols)
     : base(topLeft, symbols)
 {
 }
 public UnstoppableBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
     this.body[0, 0] = Symbol;
 }
示例#29
0
 public ImpassableBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = ImpassableBlock.Symbol;
 }
示例#30
0
 public Explosion(MatrixCoords topLeft, char[,] image, MatrixCoords speed)
     : base(topLeft, image, speed)
 {
     this.IsDestroyed = true;
 }
示例#31
0
 public UnpassableBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
 }
 public TrailObject(MatrixCoords topLeft, int lifetime)
     : base(topLeft,new char[,]{{'.'}})
 {
     this.Lifetime = lifetime;
 }
示例#33
0
 public ExplodingBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = ExplodingBlock.Body;
 }
示例#34
0
 public GiftBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
 }
 public TrailObject(MatrixCoords topLeft, char[,] body, int lifetime)
     : base(topLeft, body)
 {
     this.Lifetime = lifetime;
 }
示例#36
0
 public ExplodingPart(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[, ] {
     { 'e' }
 }, speed)
 {
 }
 public MeteoriteBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, speed)
 {
 }
 public ExplodingBlock(MatrixCoords upperLeft)
     : base(upperLeft)
 {
     this.body[0, 0] = ExplodingBlock.Symbol;
 }
示例#39
0
 // Constructor
 public Explosion(MatrixCoords topLeft, char[,] body, MatrixCoords speed)
     : base(topLeft, body, speed)
 {
 }
示例#40
0
 public Bullet(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[, ] {
     { '^' }
 }, speed)
 {
 }
示例#41
0
 public ShootingRacket(MatrixCoords topLeft, int width)
     : base(topLeft, width)
 {
 }
 public UnpassableBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     this.body[0, 0] = UnpassableBlock.symbol;
 }
示例#43
0
 public GiftBlock(MatrixCoords topLeft) : base(topLeft)
 {
     this.body[0, 0] = GiftBlock.Body;
 }
示例#44
0
 public Gift(MatrixCoords topLeft, char[,] body)
     : base(topLeft, body, new MatrixCoords(1, 0))
 {
 }
示例#45
0
 public Bullet(MatrixCoords topLeft)
     : base(topLeft, new char[, ] {
     { '1' }
 }, new MatrixCoords(-1, 0))
 {
 }
 public Fragment(MatrixCoords topLeft, MatrixCoords speed, int lifetime)
     : base(topLeft, new char[,] { { '"' } }, speed)
 {
 }
示例#47
0
 public Gift(MatrixCoords topLeft)
     : base(topLeft, new char[, ] {
     { 'G' }
 }, new MatrixCoords(1, 0))
 {
 }
 public MeteoriteBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft ,speed)
 {
 }
示例#49
0
 public ExplodingBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
 }
 public UnstoppableBall(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft, new char[,] { { '@' } }, speed)
 {
 }
示例#51
0
 public Gift(MatrixCoords topLeft, char[,] body, MatrixCoords speed)
     : base(topLeft, body, speed)
 {
 }
示例#52
0
 public UnpassableBlock(MatrixCoords topLeft)
     : base(topLeft)
 {
     base.body[0, 0] = UnpassableBlock.Symbol;
 }
示例#53
0
 public Block(MatrixCoords topLeft)
     : base(topLeft, new char[, ] {
     { '#' }
 })
 {
 }
示例#54
0
 public Bullet(MatrixCoords topLeft)
     : base(topLeft, new char[,] {{'.'}}, new MatrixCoords(-1,0))
 {
 }
示例#55
0
 public CollisionData(MatrixCoords collisionForceDirection, string objectCollisionGroupString)
 {
     this.CollisionForceDirection         = collisionForceDirection;
     this.HitObjectsCollisionGroupStrings = new List <string>();
     this.HitObjectsCollisionGroupStrings.Add(objectCollisionGroupString);
 }
 public ShootingRacket(MatrixCoords topLeft, int width)
     : base(topLeft,width)
 {
 }
示例#57
0
        private static void HandleMovingWithStaticCollisions(List <MovingObject> movingObjects, List <GameObject> staticObjects)
        {
            foreach (var movingObject in movingObjects)
            {
                int verticalIndex   = VerticalCollisionIndex(movingObject, staticObjects);
                int horizontalIndex = HorizontalCollisionIndex(movingObject, staticObjects);

                MatrixCoords movingCollisionForceDirection = new MatrixCoords(0, 0);

                if (verticalIndex != -1)
                {
                    movingCollisionForceDirection.Row = -movingObject.Speed.Row;
                    staticObjects[verticalIndex].RespondToCollision(
                        new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0),
                                          movingObject.GetCollisionGroupString())
                        );
                }

                if (horizontalIndex != -1)
                {
                    movingCollisionForceDirection.Col = -movingObject.Speed.Col;
                    staticObjects[horizontalIndex].RespondToCollision(
                        new CollisionData(new MatrixCoords(0, movingObject.Speed.Col),
                                          movingObject.GetCollisionGroupString())
                        );
                }

                int diagonalIndex = -1;
                if (horizontalIndex == -1 && verticalIndex == -1)
                {
                    diagonalIndex = DiagonalCollisionIndex(movingObject, staticObjects);
                    if (diagonalIndex != -1)
                    {
                        movingCollisionForceDirection.Row = -movingObject.Speed.Row;
                        movingCollisionForceDirection.Col = -movingObject.Speed.Col;

                        staticObjects[diagonalIndex].RespondToCollision(
                            new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0),
                                              movingObject.GetCollisionGroupString())
                            );
                    }
                }

                List <string> hitByMovingCollisionGroups = new List <string>();

                if (verticalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[verticalIndex].GetCollisionGroupString());
                }

                if (horizontalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[horizontalIndex].GetCollisionGroupString());
                }

                if (diagonalIndex != -1)
                {
                    hitByMovingCollisionGroups.Add(staticObjects[diagonalIndex].GetCollisionGroupString());
                }

                if (verticalIndex != -1 || horizontalIndex != -1 || diagonalIndex != -1)
                {
                    movingObject.RespondToCollision(
                        new CollisionData(movingCollisionForceDirection,
                                          hitByMovingCollisionGroups)
                        );
                }
            }
        }
 public Shrapnel(MatrixCoords topLeft, MatrixCoords speed)
     : base(topLeft,new char[,] {{'^'}}, speed)
 {
 }
 public UnstoppableBall(MatrixCoords topleft, MatrixCoords direction)
     : base(topleft, direction)
 {
 }