Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 6
    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) - Creating the Entity Class


    (Page 4 of 4 )

    The map is missing something very important, though-the player. Fortunately, displaying the player is easy enough, but first we need to consider something else first. Yes, we'll have the player walking around the screen, but we'll also have other entities (monsters, etc.) moving around the screen as well. Here, we have some common behavior shared between players and other entities. Both groups have a location, both groups are represented by a symbol, and both groups have names associated with them. This is a great opportunity for inheritance to play a role. Let's create a class called Entity that represents all the entities on the map, including the player. Then, let's rework Adventurer to inherit from this class.

    The Entity class will have fields and properties for a name, a location, a symbol, and a foreground color. Let's go ahead and create the class-it's a little lengthy:


    Public Class Entity

     Private _name As String

     Private _symbol As Char

     Private _color As ConsoleColor

     Private _x As Integer

     Private _y As Integer


     Public Property Name() As String

     Get

     Return _name

     End Get

     Set(ByVal value As String)

    _name = value

     End Set

     End Property

     Public Property Symbol() As Char

     Get

     Return _symbol

     End Get

     Set(ByVal value As Char)

    _symbol = value

     End Set

     End Property

     Public Property Color() As ConsoleColor

     Get

     Return _color

     End Get

     Set(ByVal value As ConsoleColor)

    _color = value

     End Set

     End Property

     Public Property X() As Integer

     Get

     Return _x

     End Get

     Set(ByVal value As Integer)

    _x = value

     End Set

     End Property

     Public Property Y() As Integer

     Get

     Return _y

     End Get

     Set(ByVal value As Integer)

    _y = value

     End Set

     End Property

    End Class

    We also need a constructor to assign initial values to the fields:

    Public Sub New(ByVal name As String, ByVal symbol As Char, _

     ByVal color As ConsoleColor, ByVal x As Integer, _

     ByVal y As Integer)

    _name = name

    _symbol = symbol

    _color = color

    _x = x

    _y = y

    End Sub

    The Entity class is long, but we can now drastically reduce the size of Adventurer, since the functionality we provided previously is now provided in Entity. All we need to do now is call the constructor. Replace the entire Adventurer class with this:

    Public Class Adventurer

     Inherits Entity


     Public Sub New(ByVal name As String, ByVal x As Integer, _

     ByVal y As Integer)

     MyBase.New(name, "@", ConsoleColor.Cyan, x, y)

     End Sub

    End Class

    There, that's shorter than before. However, since the constructor's parameters have changed, we need to modify Main a bit, where we create the Adventurer:

    player = New Adventurer(name, 1, 1)

    Now we can create a method that will draw not only the player, but every other entity as well. The method will accept an Entity object and will then draw it on the proper location on the screen:

    Sub DrawEntity(ByVal toBeDrawn As Entity)

    Console.SetCursorPosition(toBeDrawn.X, toBeDrawn.Y)

    Console.ForegroundColor = toBeDrawn.Color

    Console.Write(toBeDrawn.Symbol)

    Console.ResetColor()

    End Sub

    The method is similar to DrawTile, except it specifies a parameter and sets the cursor to the proper location itself. In Main, after the call to DrawMap, call DrawEntity and pass player (since, after all, an Adventurer is an Entity):

    DrawEntity(player)

    This will draw the player on the screen. Run the program, and you should see the player in the top left-hand corner of the screen.

    Now that we have drawing taken care of, it's time to move on to movement. The game is finally starting to take shape.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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

    - 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...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT