Visual Basic.NET
  Home arrow Visual Basic.NET arrow Movement and Player Statistics in a 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

Movement and Player Statistics in a VB.NET Text-Based Game
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2008-07-15

    Table of Contents:
  • Movement and Player Statistics in a VB.NET Text-Based Game
  • Adding Movement
  • Player Statistics
  • Displaying Properties

  • 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


    Movement and Player Statistics in a VB.NET Text-Based Game


    (Page 1 of 4 )

    Now that we've drawn the map and the player on the screen, we need to work on movement. Movement involves a number of things. We'll also need to give our player some statistics, such as health, attack, and defense. Keep reading for the lowdown as the text game we're creating to learn VB.Net really starts taking shape.

    Accepting User Input

    First, we need to allow the user to press a key. Second, we need to check to see if this movement is valid. For example, we don't want the player to walk on top of a wall. Checking to see if the movement is valid only involves checking the Passable property of the destination tile. Third, we need to actually make the movement. This involves drawing the player on the new tile, but it also involves erasing the player on the old tile.

    Finally, this all needs to be contained within a loop. After all, we want the user to be able to continue making movements, and each time, the game should go through the same steps to respond to the movement.

    The first thing we need to do is set up the loop. For now, an infinite While loop will work, but later we'll want to check for certain situations—such as when the player is dead. In this loop, we'll want to accept a keypress from the user. The keypress will be stored in a variable, so we'll need to define this variable. Also, we need to make sure that the cursor is not visible, and that the pressed key is not displayed in the console. Put the game loop at the bottom of Main:

    Console.CursorVisible = False

    Dim input As ConsoleKeyInfo


    While True

     input = Console.ReadKey(True)

    End While

    When you run the game, there will now be no cursor visible, and the console will not display anything you type (recall that this is accomplished by passing True to ReadKey). Now that we have the key stored, we need to check it against valid inputs. If the input is valid, then we need to perform the associated action. Otherwise, we need to go back and let the user try again. The checking will be done in a Select statement. Right now, let's put in a quit action, which will be escape. Pressing this key will exit the game immediately. Put this at the bottom of the loop:

    Select Case input.Key

     Case ConsoleKey.Escape

     Exit While

     Case Else

     Continue While

    End Select

    Notice how, if the user has pressed the escape key, we exit the While loop. Otherwise, we use the Continue statement. The Continue statement immediately moves to the next iteration of the loop. In this case, we use it to allow the user to press another key.

    More Visual Basic.NET Articles
    More By Peyton McCullough


       · Hello, all,This is a continuation of my series on learning Visual Basic through...
     

    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...





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