Introduction - Learn VB .NET Through Game Programming [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Learn VB .NET Through Game Programming [Electronic resources] - نسخه متنی

Matthew Tagliaferri

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید





Introduction

A Few Years Ago, Microsoft raised a few eyebrows (my own included) when it announced that the next version of Visual Basic (VB) would not be backward compatible with the current version, VB 6. There were many valid reasons for breaking the compatibility, but many people still thought Microsoft was taking a considerable gamble. After all, there were thousands of VB programmers cranking out millions of lines of code in the modern workforce, and suddenly Microsoft was announcing that this mountain of code would someday be considered “old” technology.


Introducing the New VB


Would the development community take to the new VB? The answer to that, of course, depended on what the new language had to offer. Community revolt would be the result if it were perceived that VB was changing simply for the sake of change. No, Microsoft had to make sure that the new VB was bringing enough to the table to get developers to want to make the change and make a concerted effort to plan upgrade paths for their production VB code.

Fortunately (for Microsoft and its stockholders), the new VB delivered against these goals. The new VB, called Visual Basic .NET, supported a full object-oriented paradigm—much better than the object-oriented features “bolted on” to VB along its prior development cycle. Furthermore, VB was only one of many possible languages that built upon the .NET Framework—an enormous library of classes from which your new programs would be based. Browser-based development took a major leap forward in the new release, as well—allowing the developer to do much of the development outside of the Web page in “standard” classes that could be accessed from the browser. These classes could be accessed through standard means or referenced remotely using Web Services, which allow full .NET Framework objects to be passed via Extensible Markup Language (XML) across the Internet. So much to learn! Where to start?

I’ve had many different people ask me about the best way to get into programming or the best way to learn a new language such as VB .NET. I’ve always found that I can’t learn a new language unless I have a specific task that I want to solve by writing a program. I’m not of the camp that believes one can sit down with the compiler, the development environment, and the help file and then stand up many hours later an “expert” in the language. I need to learn by doing.

With that in mind, an important choice becomes the type of program to develop. Choose a program too small, and you won’t have enough opportunity to learn anything. A program too large doesn’t work, either—you end up spending too much time bogged down in the complexity of the task, which takes away time from learning the features of the language. Like Goldilocks, you’re looking for the program not too small, not too big, but instead “just right.”

I discovered a few years ago that the “small game” program fit nicely into the “just right” category for learning the basics of a programming language. A small game is one that fits on a single screen and can usually be played by a single player in a few minutes. Examples of a small game include card games, dice games, and some simple board games. Many qualities make programs such as these good learning subjects. Programs of this type usually need to keep track of one or more types of game piece, and these pieces are often required to change state (such as a die rolling or a board element changing color). These game elements often come in groups (52 cards in a deck, five dice for Yahtzee), so you’ll have to learn how the language stores a group of similar elements. The user interface requirements of such games are usually more interesting (and therefore more challenging) than the usual button/listbox/combobox interface. Finally, when you’ve succeeded and completed the program, you’ve got a fun game to play.

The goal of this book is to teach you how to get started programming in Visual Basic .NET by developing games. This book doesn’t intend to be a complete treatise of all the features and capabilities of this latest version of VB. Instead, it provides a series of example programs that illustrate basic features of the language and begins the huge task of introducing you to the contents of the .NET Framework. In addition, I introduce one more important programming concept—the concept of design. Now that object-oriented languages are more common, people have found that the various objects in a program can be designed to interact with each other in different ways; these interactions can make the program more or less complex or more or less adaptable to future features or enhancements. To illustrate the importance of design on a program, I’ve taken the time to walk you through the development process of several of these programs rather than simply presenting you with the final version of the game. By learning how to solve a program one way, then improving upon that design in a second or third version of the program, you’ll begin to recognize when your own designs might be headed down a wrong path and some redesign is in order.


Where Are You Now?


This book assumes you’ve had at least some experience in software development before diving into the first chapter and that you now want to learn Visual Basic .NET. Perhaps you’re a VB 6 programmer, for example, in which case this book will help describe the syntactical differences between the languages, as well as introduce you to the .NET Framework classes that will be new to you. Perhaps you’re experienced in an older technology such as mainframe programming and Chapter 1, “Developing Your First Game,” you’ve written programs in some other language so that you have a jumping-off point. Specifically, the following concepts should be familiar to you:



Simple variables such as integers and strings to hold pieces of information



Manipulation of data through expressions using elements such as mathematical operators (plus, minus, multiply, divide) or string operations (left, right, substring, uppercase/lowercase)



Flow statements such as If..Then..Else blocks, For loops, and While statements



The use of procedures and functions and how to get information into and out of them



The event-driven nature of Windows programming and how many programs remain in an “idle state” until the user does something, at which point some type of code runs




Getting Up to Speed


If the previous little review list gives you a queasy feeling, or you simply think you might need a refresher on some of these topics, then you’ll be happy to know that Appendix A, “The Basics of Visual Basic” contains some introductory material. Specifically, it covers these topics while describing how to write a simple Visual Basic .NET program. Becoming familiar with the topics in the appendix should give you enough background to dive into Chapter 1, “Developing Your First Game,” and start the game writing.


Downloading the Code


If you want to follow along with the examples in the book, you can download the code for all the games developed in the book. It’s available from the Downloads section of the Apress Web site ([http://www.apress.com]). The code is divided into the chapter folders described in Table 1.























































































Table 1: Download the Source Code

FOLDER NAME


USED IN


Art


Graphics/sounds used throughout the book


BMPStitch


Appendix C


CellularAutomata


Chapter 5


CellularAutomataWithSave


Chapter 9


Common


Modules/classes used by multiple projects


DicePanel


Chapter 2


DicePanelNew


Bonus, used by the Yahtzee game


DirectXDemo


Chapter 8


FirstApplication


Appendix A


GarbageDemoOne


Chapter 9


GarbageDemoTwo


Chapter 9


GuessTheDieRoll


Chapter 1


GuessTheDieRoll2


Chapter 2


GuessTheDieRoll3


Chapter 2


InterfaceExample


Chapter 6


NetReversi


Chapter 7


NineTiles


Chapter 3


PCOpponent


Chapter 6


PolymorphismExample


Chapter 5


ShapeTileGames


Chapter 4


SpaceRocks


Chapter 8


ThreadParametersOne


Chapter 9


ThreadParametersThree


Chapter 9


ThreadParametersTwo (broken)


Chapter 9


Yahtzee


Bonus game


/ 106