Visual Basic.NET
  Home arrow Visual Basic.NET arrow Creating and Drawing a Game Map in VB.NET ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Creating and Drawing a Game Map in VB.NET (FIXED PER REQUEST)
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2008-07-08

    Table of Contents:
  • Creating and Drawing a Game Map in VB.NET (FIXED PER REQUEST)
  • Creating the Map Array and a Basic Map
  • Drawing the Map
  • Creating the Entity Class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating and Drawing a Game Map in VB.NET (FIXED PER REQUEST)


    (Page 1 of 4 )

    This is the seventh part of a nine-part article series that teaches you Visual Basic.Net through the development of a text-based PC game similar to Rogue or Nethack. In this installment, you'll learn how to build the map, starting with the creation of some basic tiles. We'll be dealing with arrays, entity classes and more. Let's get started.

    Creating Some Basic Tiles Through Subclassing

    Before we start working with the map as a whole, let's create a few basic tiles to work with by subclassing the Tile class. The first tile we'll create is a basic floor tile. It won't be flashy at all. It will have a gray foreground and a black background, it will be represented by a period, and the user will, of course, be able to walk over it. Create a new class in Visual Studio called BasicTile (in BasicTile.vb):


    Public Class BasicTile


    End Class


    The first thing we need to do is set our class to inherit from the Tile class. This is very easy. All we have to do is use the Inherits keyword and then specify the parent class. As is characteristic of BASIC languages, the result is very straightforward and readable:


    Public Class BasicTile

     Inherits Tile


    End Class


    Notice how the Inherits statement is put on a new line. This is required.

    Immediately, Visual Studio should complain that we have to create a constructor because the parent class does not have a parameterless constructor which can be called by default. This is easy to do. Let's create a parameterless constructor that sets up everything. In this constructor, we will have to call Tile's constructor, which will set the fields to the values we specify. Let's go ahead and create it:

    Public Sub New()

     MyBase.New(".", ConsoleColor.Gray, ConsoleColor.Black, True)

    End Sub

    One of the first things you should notice is the use of the MyBase keyword. The MyBase keyword simply provides access to the parent class. Above, we use MyBase to call the parent class's constructor. Also, notice how, when working with characters, we do not use single quotes as we might in other languages. Instead, we just use double quotes, which other languages often reserve for strings. Besides, the single quote mark in Visual Basic is taken to be a comment.

    Now we have a basic floor tile. Next is a wall tile. It will be represented by the number sign, will have a gray foreground and a black background, and it will, of course, not be passable by the player. Create a class called WallTile (in WallTile.vb). The process is the same as before, except the name of the class is, obviously, different, and the values we pass to Tile's constructor are different:


    Public Class WallTile

     Inherits Tile


     Public Sub New()

     MyBase.New("#", ConsoleColor.Gray, ConsoleColor.Black, False)

     End Sub

    End Class


    The final basic tile we'll need is a blank tile. This tile will have a blank space associated with it, and it will be used to fill in if the physical map isn't as big as the available size. Make a class called BlankTile:


    Public Class BlankTile

     Inherits Tile


     Public Sub New()

     MyBase.New(" ", ConsoleColor.Black, ConsoleColor.Black, False)

     End Sub

    End Class


    More Visual Basic.NET Articles
    More By Peyton McCullough


       · Main() will fail after the change to the Adventurer class. The new constructor...
       · You're right. Main seems to have been quietly changed on my end, without any mention...
     

    VISUAL BASIC.NET ARTICLES

    - Clocks and Countdowns
    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek