Template that is used for creating similar chunks, which in turn make up a level. Chunk templates define the positions of all contexts and anchors of chunks, as well as attributes that are required for the level generation process such as the probability of a chunk being picked to be added next.
示例#1
0
        /// <summary>
        /// Constructs a new chunk with a reference to the passed chunk template,
        /// using that template's width and height and performing deep copies of
        /// the lists of contexts and anchors of that template.
        /// </summary>
        /// <param name="chunkTemplate">Chunk template the new chunk will be based on.</param>
        /// <seealso cref="Chunk.ChunkTemplate"/>
        /// <exception cref="ArgumentNullException"><paramref name="chunkTemplate"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="chunkTemplate"/> is not of the type <see cref="ChunkTemplate2D"/>.</exception>
        public Chunk2D(ChunkTemplate chunkTemplate)
            : base(chunkTemplate)
        {
            ChunkTemplate2D chunkTemplate2D = chunkTemplate as ChunkTemplate2D;

            // Check the type of the passed template.
            if (chunkTemplate2D == null)
            {
                throw new ArgumentException("Passed template isn't of type ChunkTemplate2D.", "chunkTemplate");
            }

            // Copy template extents.
            this.Extents = chunkTemplate2D.Extents;

            // Perform deep copies of the context and anchor lists of the template.
            foreach (Context2D context in chunkTemplate2D.ChunkTemplateContexts)
            {
                this.ChunkContexts.Add(new Context2D(context, this));
            }

            foreach (Anchor2D anchor in chunkTemplate2D.ChunkTemplateAnchors)
            {
                this.ChunkAnchors.Add(new Anchor2D(anchor, this));
            }
        }
示例#2
0
文件: Chunk.cs 项目: npruehs/bychance
        /// <summary>
        /// Constructs a new, empty chunk with a reference to the passed chunk template.
        /// </summary>
        /// <param name="template">Chunk template the new chunk will be based on.</param>
        /// <seealso cref="ChunkTemplate"/>
        /// <exception cref="ArgumentNullException"><paramref name="template"/> is null.</exception>
        protected Chunk(ChunkTemplate template)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            this.ChunkContexts = new List<Context>();
            this.ChunkAnchors = new List<Anchor>();

            this.ChunkTemplate = template;
        }
示例#3
0
        /// <summary>
        /// Constructs a new chunk with a reference to the passed chunk template,
        /// using that template's width, height and depth and performing deep copies of
        /// the lists of contexts and anchors of that template.
        /// </summary>
        /// <param name="chunkTemplate">Chunk template the new chunk will be based on.</param>
        /// <seealso cref="Chunk.ChunkTemplate"/>
        /// <exception cref="ArgumentNullException"><paramref name="chunkTemplate"/> is null.</exception>
        /// <exception cref="ArgumentException">Passed template is not of the type <see cref="ChunkTemplate3D"/>.</exception>
        public Chunk3D(ChunkTemplate chunkTemplate)
            : base(chunkTemplate)
        {
            // Check the type of the passed template.
            if (!(chunkTemplate is ChunkTemplate3D))
            {
                throw new ArgumentException("Passed template isn't of type ChunkTemplate3D.", "chunkTemplate");
            }

            // Copy template extents.
            this.Extents = ((ChunkTemplate3D)chunkTemplate).Extents;

            // Perform deep copies of the context and anchor lists of the template.
            foreach (Context3D context in chunkTemplate.ChunkTemplateContexts)
            {
                this.ChunkContexts.Add(new Context3D(context, this));
            }

            foreach (Anchor3D anchor in chunkTemplate.ChunkTemplateAnchors)
            {
                this.ChunkAnchors.Add(new Anchor3D(anchor, this));
            }
        }
示例#4
0
 /// <summary>
 /// Factory method that returns a new chunk based on the given chunk template that the type of the chunk template 
 /// and of the chunks in the level.
 /// </summary>
 /// <param name="chunkTemplate">Chunk template the returned chunk should be based on.</param>
 /// <returns>Chunk based on the chunk template with the desired chunk type.</returns>
 /// <exception cref="ArgumentException">
 /// The type of the passed <c>chunktemplate</c> doesn't match the desired chunk type.
 /// </exception>
 protected override Chunk ConstructChunkFromTemplate(ChunkTemplate chunkTemplate)
 {
     return new Chunk2D(chunkTemplate);
 }