Skip to main content

Loading Levels from Files

  • Chapter
Learning C# by Programming Games

Abstract

Many games consist of different levels. Especially in casual games such as puzzles and maze games, the game may have several hundreds of levels. With the programming tools that we have seen thus far, we could add different levels to our game by, for example, writing a generic Level class, and then defining (hundreds of) subclasses, where each class defines what the particular level looks like. A much better approach, however, would be to store the different levels in a text file, and then read the information from this text file to create the levels. Then, if we want to add another level to our game, we do not have to change the source code but we can simply edit the text file. In this chapter, we will see how we can load levels from a text file using the C# file I/O classes. As an example, we will show how to create a tile-based game world based on information saved in a text file.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Hardcover Book
USD 54.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2013 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Egges, A., Fokker, J.D., Overmars, M.H. (2013). Loading Levels from Files. In: Learning C# by Programming Games. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-36580-5_22

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-36580-5_22

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-36579-9

  • Online ISBN: 978-3-642-36580-5

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics