Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Working with Classes and Properties for Ga...
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

Working with Classes and Properties for Game Development in VB.NET
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-07-01

    Table of Contents:
  • Working with Classes and Properties for Game Development in VB.NET
  • Creating an Adventurer Class
  • Setting Properties and Defining Constructors
  • Creating a Tile 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


    Working with Classes and Properties for Game Development in VB.NET - Creating a Tile Class


    (Page 4 of 4 )

    The next thing we need to do is determine how to lay out the "tiles" (which are, remember, actually composed of single characters) for our maps. Since a map itself will be rectangular (though not all of the rectangle may be used, of course), the best way to represent it is through a two-dimensional array. Think of the map as a table of tiles. One dimension of the array contains the rows, and the other contains the columns. This is the most straightforward approach to it.

    We need to have an array of something, though, and despite the tiles being represented as characters, an array of characters won't due because each tile has special properties, such as color or the ability to be walked on (as opposed to being a wall or some other obstruction). These properties will be best represented as part of a Tile class. Then, we can just create an array of Tile objects.

    Create a new Tile class (inside Tile.vb) in Visual Studio, the same way we did with the Adventurer class:

    Public Class Tile


    End Class

    We'll need fields and properties for the tile's character symbol, its foreground color, its background color and whether or not the user can pass over it. The symbol needs to be a Char, the two colors need to be of type ConsoleColor, and a Boolean can tell us whether or not the user can pass over the tile. Let's go ahead and create all of this at once (it's a bit lengthy, but it's very simple, and there's nothing new):

    Private _symbol As Char

    Private _foregroundColor As ConsoleColor

    Private _backgroundColor As ConsoleColor

    Private _passable As Boolean


    Public Property Symbol() As Char

     Get

     Return _symbol

     End Get

     Set(ByVal value As Char)

    _symbol = value

     End Set

    End Property

    Public Property ForeGroundColor() As ConsoleColor

     Get

     Return _foregroundColor

     End Get

     Set(ByVal value As ConsoleColor)

    _foregroundColor = value

     End Set

    End Property

    Public Property BackgroundColor() As ConsoleColor

     Get

     Return _backgroundColor

     End Get

     Set(ByVal value As ConsoleColor)

    _backgroundColor = value

     End Set

    End Property

    Public Property Passable() As Boolean

     Get

     Return _passable

     End Get

     Set(ByVal value As Boolean)

    _passable = value

     End Set

    End Property

    As I said, it's lengthy, but we're just creating four fields and then creating four properties to access those fields. Now we need to create a constructor to set initial values for everything:

    Public Sub New(ByVal symbol As Char, _

     ByVal foregroundcolor As ConsoleColor, _

     ByVal backgroundColor As ConsoleColor, _

     ByVal passable As Boolean)

    _symbol = symbol

    _foregroundColor = foregroundcolor

    _backgroundColor = backgroundColor

    _passable = passable

    End Sub

    We won't be using the Tile class like this, however. Rather, we're going to subclass it in order to easily create different types of tiles. And that is where we will pick up next week!


    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.

       · Hello, all,This is a continuation of my series introducing Visual Basic .NET,...
       · Hi, I think this is just super :) keep up the good work and i will keep on pressing...
     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Polymorphism using Abstract Classes in Visua...





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