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  
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: 3 stars3 stars3 stars3 stars3 stars / 7
    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

    - 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...
    - Movement and Player Statistics in a VB.NET T...





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