Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - 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) - Drawing the Map


    (Page 3 of 4 )

    Now we have a map. That didn't take much, did it? We need to draw it out to the screen now, one tile at a time. This will enable us to see what it looks like for the first time. To draw it out to the screen, we once again need two loops, but rather than going through the map column-by-column, we'll need to go through row-by-row. This way, we can just call Write for each tile, and we only have to manually adjust the cursor's position at the end of each row. Once again, we'll place this code in a separate method, so as not to clog up Main. The method will be called DrawMap:


    Sub DrawMap()

     For y As Integer = 0 To map.GetUpperBound(1)

    Console.SetCursorPosition(0, y)

     For x As Integer = 0 To map.GetUpperBound(0)

    DrawTile(x, y)

     Next

     Next

    End Sub

    As noted, the outer loop goes by row, and the inner loop goes by column. At the start of each iteration of the outer loop, we set the cursor to the beginning of the appropriate row. As we draw the tiles, the cursor will automatically shift right. Notice how I've called a method called DrawTile. We'll be drawing tiles frequently, and so it's best to have a separate method for this. Inside of DrawTile, we apply our knowledge of console output:

    Sub DrawTile(ByVal x As Integer, ByVal y As Integer)

    Console.ForegroundColor = map(x, y).ForeGroundColor

    Console.BackgroundColor = map(x, y).BackgroundColor

    Console.Write(map(x, y).Symbol)

    Console.ResetColor()

    End Sub

    We first have to set the colors. Then, we write out the tile's symbol and then clean up by changing back to the default color.

    Now we can see the map in action. In Main, call DrawMap:


    DrawMap()


    It's also a good idea to call ReadKey temporarily. That way, the console won't close before we can see the map. Just remember to erase it afterward:


    Console.ReadKey()

    Run the program, and, after you enter your name, you should see the map we just created.

    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

    - 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 1 hosted by Hostway
    Stay green...Green IT