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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights 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)