예제 #1
0
        public void Paint(Type tileType, int numOfTimesToPaint)
        {
            for (int i = 0; i < numOfTimesToPaint; i++)
            {
                ITile tile = tileFactory.GetTile(tileType);

                tile.Draw(graphics, GetRandomNumber(),
                          GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
            }
        }
예제 #2
0
 public void DrawTile(SpriteBatch sb, Vector2 pos, ITile tile, float depth, Color colour, Vector2?scale = null)
 {
     if (tile == null)
     {
         return;
     }
     if (!tile.Draw(this, sb, pos, colour, depth, scale))
     {
         sb.DrawRectangle(pos, new Size2(this.TileSize, this.TileSize), Color.Red);
         var font = Store.Instance.Fonts("Base", "debug.small");
         var s    = $"{tile.DebugString}";
         font.DrawString(sb, pos + new Vector2(this.TileSize / 2) - font.Font.MeasureString(s) / 2, s, Color.Yellow);
     }
 }
예제 #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            for (int i = 0; i < 20; i++)
            {
                ITile ceramicTile = TileFactory.GetTile("Ceramic");
                ceramicTile.Draw(e.Graphics, GetRandomNumber(),
                                 GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
            }

            for (int i = 0; i < 20; i++)
            {
                ITile stoneTile = TileFactory.GetTile("Stone");
                stoneTile.Draw(e.Graphics, GetRandomNumber(),
                               GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
            }

            this.toolStripStatusLabel1.Text = "Total Objects Created : " +
                                              Convert.ToString(CeramicTile.ObjectCounter
                                                               + StoneTile.ObjectCounter);
        }
예제 #4
0
        public void Run()
        {
            // Not using Flyweight
            for (int i = 0; i < 20; i++)
            {
                ITile ceramicTile = new CeramicTile(GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
                ceramicTile.Draw("CeramicTile");
                ITile stoneTile = new StoneTile(GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
                stoneTile.Draw("StoneTile");
            }
            Console.WriteLine($"Total of files created not using Flyweight pattern and TileFactory factory : {CeramicTile.objectCounter} + {StoneTile.objectCounter} created");


            // Using Flyweight
            for (int i = 0; i < 20; i++)
            {
                ITile ceramicTile = TileFactory.GetTile("Ceramic");
                ceramicTile.Draw("CeramicTile", GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
                ITile stoneTile = TileFactory.GetTile("Stone");
                stoneTile.Draw("StoneTile", GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
            }
            Console.WriteLine($"Total of files created using Flyweight pattern using TileFactory factory : {CeramicTile.objectCounter} + {StoneTile.objectCounter} created");
            Console.ReadKey();
        }
예제 #5
0
 /// <summary>
 /// Draws using the ITile.Draw(GameTime, SpriteBatch, ITransform2D, Color). Color is set to Color.White.
 /// </summary>
 /// <param name="tile"></param>
 /// <param name="gameTime"></param>
 /// <param name="spriteBatch"></param>
 /// <param name="transform"></param>
 public static void Draw(this ITile tile, GameTime gameTime, SpriteBatch spriteBatch, ITransform2D transform, float depth)
 {
     tile.Draw(gameTime, spriteBatch, transform, Color.White, SpriteEffects.None, depth);
 }