100% found this document useful (2 votes)
26 views

[FREE PDF SAMPLE] Learn VB NET Through Game Programming 1st Edition Matthew Tagliaferri (Auth.) ebook full chapters

The document promotes the ebook 'Learn VB NET Through Game Programming' by Matthew Tagliaferri, providing a link for download and additional resources for related ebooks. It includes details about the book's content, structure, and author, as well as acknowledgments and an introduction discussing the evolution of Visual Basic. The document serves as a guide for readers interested in learning VB.NET through practical game programming examples.

Uploaded by

kemrondeveja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
26 views

[FREE PDF SAMPLE] Learn VB NET Through Game Programming 1st Edition Matthew Tagliaferri (Auth.) ebook full chapters

The document promotes the ebook 'Learn VB NET Through Game Programming' by Matthew Tagliaferri, providing a link for download and additional resources for related ebooks. It includes details about the book's content, structure, and author, as well as acknowledgments and an introduction discussing the evolution of Visual Basic. The document serves as a guide for readers interested in learning VB.NET through practical game programming examples.

Uploaded by

kemrondeveja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Visit https://ebookultra.

com to download the full version and


explore more ebooks

Learn VB NET Through Game Programming 1st


Edition Matthew Tagliaferri (Auth.)

_____ Click the link below to download _____


https://ebookultra.com/download/learn-vb-net-through-
game-programming-1st-edition-matthew-tagliaferri-auth/

Explore and download more ebooks at ebookultra.com


Here are some suggested products you might be interested in.
Click the link to download

Beginning ASP NET 2 0 in VB 2005 From Novice to


Professional Apr 2006 1st Edition Matthew Macdonald

https://ebookultra.com/download/beginning-asp-net-2-0-in-vb-2005-from-
novice-to-professional-apr-2006-1st-edition-matthew-macdonald/

Murach s ASP NET 4 5 web programming with VB 2012 training


reference 5th ed Edition Boehm

https://ebookultra.com/download/murach-s-asp-net-4-5-web-programming-
with-vb-2012-training-reference-5th-ed-edition-boehm/

Build Your Own ASP NET Website Using C VB NET 1st Edition
Zak Ruvalcaba

https://ebookultra.com/download/build-your-own-asp-net-website-using-
c-vb-net-1st-edition-zak-ruvalcaba/

VB NET for Developers Sams White Book 1st Edition Keith


Franklin

https://ebookultra.com/download/vb-net-for-developers-sams-white-
book-1st-edition-keith-franklin/
Pro Silverlight 3 in VB 2nd ed. Edition Matthew Macdonald

https://ebookultra.com/download/pro-silverlight-3-in-vb-2nd-ed-
edition-matthew-macdonald/

Pro Silverlight 4 in VB 3rd Ed 3rd Edition Matthew


Macdonald

https://ebookultra.com/download/pro-silverlight-4-in-vb-3rd-ed-3rd-
edition-matthew-macdonald/

Programming ASP NET AJAX 1st Edition Christian Wenz

https://ebookultra.com/download/programming-asp-net-ajax-1st-edition-
christian-wenz/

Visual C Net programming 1st Edition Harold Davis

https://ebookultra.com/download/visual-c-net-programming-1st-edition-
harold-davis/

Real World Enterprise Reports Using VB6 and VB NET 1st


Edition Carl Ganz Jr. (Auth.)

https://ebookultra.com/download/real-world-enterprise-reports-using-
vb6-and-vb-net-1st-edition-carl-ganz-jr-auth/
Learn VB NET Through Game Programming 1st Edition
Matthew Tagliaferri (Auth.) Digital Instant Download
Author(s): Matthew Tagliaferri (auth.)
ISBN(s): 9781590591147, 1590591143
Edition: 1
File Details: PDF, 13.07 MB
Year: 2003
Language: english
learn VB .NET Through
Game Progranvning
Matthew Tagliaferri

APress Media, LLC


learn
Learn VB .NET Through Game Programming
Programming
Copyright
Copyright © Matther Tagliaferri 2003
2003
Originally published by Apress 2003

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
information
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.

ISBN 978-1-59059-114-7 ISBN 978-1-4302-0808-2 (eBook)


DOI 10.1007/978-1-4302-0808-2
DOl 10.1007/978-1-4302-0808-2

Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement
benefit infringement of the trademark.

Technical Reviewer: Mike Burgess

Editorial Board: Dan Appleman, Craig Berry, Gary Cornell, Tony Davis, Steven Rycroft, Julian
Skinner, Martin Streicher, Jim Sumser, Karen Watterson, Gavin Wray, John Zukowski

Assistant Publisher: Grace Wong

Project Managers: Laura Cheu and Nate McFadden

KimWimpsett
Copy Editor: Kim Wimpsett

Production Manager: Kari Brooks

Janet Vail
Production Editor: JanetVail

Proofreader and Indexer: Carol Burbo


Proofreader
Compositor: Kinetic Publishing Services, LLC
LLC
Artist: Dina Quan

Cover Designer: Kurt Krames

Manufacturing
Manufacturing Manager: Tom Debolsld
Debolski
phone I-S00-SPRINGER,
In the United States: phone 1-800-SPRINGER, email
email [email protected]. orvisit
[email protected], or visit
http://www.springer-ny.com. Outside the United States: fax
http://www.springer-ny.com. fax +49
+49 6221
6221 345229,
345229, email
email
orders@springer . de, or visit http://www.springer.de.
[email protected], http://www.springer.de.

information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219,
For information
94710. Phone
Berkeley, CA 94710. Phone 510-549-5930,
510-549-5930, fax
fax 510-549-5939,
510-549-5939,email
email [email protected], orvisit
[email protected], or visit
http://www.apress.com.

information in this book is distributed on an "as isn


The information is" basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
information contained in this work.
be caused directly or indirectly by the information

http://www.apress.com in the Downloads


The source code for this book is available to readers at http://www.apress.comin
section.
To my mom and dad, who got me here
Contents at a Glance
About the Author ................................................... xi
About the Technical Reviewer .................................... xii
Acknowledgments ................................................... xiii
Introduction ....................................................... xv
Chapter 1 Developing Your First Game ......................... l
Chapter 2 Writing Your First Game, Again ................... 43
Chapter 3 Understanding Object-Oriented Programming
from the Start ...................................... 89
Chapter 4 More OOPing Around ................................ 123
Chapter 5 Understanding Polymorphism ....................... 177
Chapter 6 Using Polymorphism via Interfaces ............... 209
Chapter 7 Creating Multiplayer Games ....................... 247
Chapter 8 Using DirectX ...................................... 279
Chapter 9 Learning other Object-Oriented
Programming Topics ................................ 319
Appendix A The Basics of Visual Basic ....................... 341
Appendix BUsing POV-RAY and Moray .......................... 347
Appendix C Using the BMPStitch Utility ...................... 357

Index .............................................................. 367

v
Contents
About the Author ................................................... xi
About the Technical Reviewer .................................... xii
Acknowledgments ................................................... xiii
Introduction ....................................................... xv

Chapter 1 Developing Your First Game .................... 1

Learning the Basics of Object-Oriented Programming ............ 2


Overview of the .NET Framework ................................... 5
Class Is in Session ................................................ 6
Designing the Die Roller Form ................................... 12
Coding the Die Roller ............................................ 17
Adding Your OWn Property ......................................... 19
Setting Up Events, or Making the Program Do Something ........ 21
Setting Up Methods ................................................ 24
Rolling the Die ................................................... 24
Where to Draw the Die? ........................................... 32
Putting the Die in Its Place .................................... 37
Moving the Die .................................................... 38
Tying the Functionality Together ................................ 40
The End? ........................................................... 42

Chapter 2 Writing Your First Game, Again ............. 43

Understanding the Benefits of Rewriting ........................ 44


Creating the Die Class ........................................... 45
Putting the Die Class to Work ................................... 60
Version 3: Creating the DicePanel Class ........................ 64
Testing the Classes ............................................... 81
Adding the DicePanel Class to the Toolbox ..................... 83
Now That's Reusable Stuff 1 ....................................... 86

Chapter 3 Understanding Object-Oriented


Programming from the Start................... 89

Starting the NineTiles Project .................................. 90


Looking Back on the Design ...................................... 118

vii
Contents

Chapter 4 More DOPing Around ............................ 123

Setting Up the Graphics ......................................... 124


Creating the Base Tile Class ................................... 125
Developing Brain Drain Concentration .......................... 139
Developing DeducTile Reasoning ................................. 146
Developing Lose Your Mind ....................................... 163
Summary ............................................................ 176

Chapter 5 Understanding Polymorphism .................. 177

Seeing Polymorphism in Action .................................. 178


Understanding Life and Something Like It ...................... 179
Developing Conway's Game of Life ............................... 187
Developing Rainbow Life ......................................... 194
Developing the Voting Game ...................................... 199
Building the Main Cellular Automaton Program ................. 203
Expanding the Cellular Automaton Games ........................ 207

Chapter 6 Using Polymorphism via Interfaces ........ 209

Seeing an Example Interface in Action ......................... 210


Using More Complex Interfaces .................................. 215
Finally, Seeing the Polymorphism in Action ................... 243
Additional Interface Topics ..................................... 245

Chapter 7 Creating Multiplayer Games .................. 247

Understanding Network Communication ............................ 247


Creating the Player Class and Subclasses ...................... 248
Developing the ReversiPiece Class .............................. 256
Developing the ReversiGame Class ............................... 257
Setting Up the Game .............................................. 262
Sending Game Data ................................................ 272
Receiving Game Data .............................................. 274
Debugging Network Code .......................................... 275
Moving Forward ................................................... 276

viii
Contents

Chapter 8 Using DirectX ................................... 279

Installing DirectX 9 ............................................. 280


Understanding DirectDraw Basics ................................ 280
Building an Arcade Game ......................................... 289
Summary ............................................................ 318

Chapter 9 Learning Other Object-Oriented


Programming Topics ............................ 319

Understanding Structured Exception Handling .................. 319


Understanding Garbage Collection ............................... 323
Understanding Object Serialization ............................. 328
Understanding Threading ......................................... 332

Appendix A The Basics of Visual Basic ................. 341

Getting Started with Basic Programming ........................ 342


Looking at an Example Project .................................. 346

Appendix BUsing POV-RAY and Moray...................... 347

Introducing Persistence of Vision .............................. 347


Creating the Ray-Traced Die ..................................... 348
Summary ............................................................ 355

Appendix C Using the BMPStitch Utility ................ 357

Using BMPStitch .................................................. 358


Using the BMPStitch Code ........................................ 360
Summary ............................................................ 366

Index ............................................................. 367

ix
About the Author
matt tagliaferrl has been developing soft-
ware since his high school obtained its
first computers-six TRS-80 Model 3s-in
1982. matt (who prefers his name in
lowercase) has developed software in sev-
eral industries, including retail, insurance,
corporate finance, and trucking before
(somewhat miraculously) landing a senior
analyst position with the Cleveland
Indians baseball organization. matt has
been with the Indians for six years and is now the manager of application
development.
Currently, matt lives in the Cleveland area with his wife and two daughters.
He enjoys collecting The Simpsons action figures and "family stuff" such as
American Idol and Friday Pizza Nights.

xi
About the Technical
Reviewer
MIKE BURGESS started writing software on computers back when they took up
whole rooms and had less memory than an average digital watch today. He has
worked for small to large corporations (including Microsoft) and has been work-
ing with Visual Basic since the beta of version 1. He's written many different types
of software including small business accounting and inventory, real estate, emer-
gency management, corporate communication, multimedia, medical diagnosis,
and some hush-hush stuff for the government.
He currently resides in northern Utah with his wife and five (yes, five) chil-
dren. He enjoys Family Game Night, Mountain Dew, and a good round of Ghost
Recon with his kids and brothers.

xii
Acknowledgments
WRITING A BOOK IS DEFINITELY not a solo project-and there are numerous people
to thank for the opportunity and the work put into this project. I'd like to thank
the entire Apress team. This is my first Apress title, and I've found it to be a first-
class organization. Individually, my list of acknowledgments probably reads like
the internal Apress organizational chart: thanks to Gary Cornell for listening to
and shaping my initial pitch, thanks to Dan Appleman for some overall direction
in finding the correct audience, and thanks to Laura Cheu and Nate McFadden
for serving as project managers and keeping the project on track. Mike Burgess
served as technical editor for the book and did a great job not only making sure
the code was complete and that everything compiled but also making sugges-
tions to help improve code clarity and readability. Kim Wunpsett filled the role of
editor, keeping my i's dotted and my gerunds gerunding. Finally, Beth Christmas
filled a multitude of roles from making sure I had the correct screen-capture soft-
ware to getting me advance copies of Visual Studio. I thank all of them for turning
a simple idea into the organized pile of pages you now hold in your hands.
On the home front, no project gets far without the understanding of my wife,
Janet, who has to put up with me running to the computer to check email as soon
as I get home from work and with the clack clack of the keyboard as she tries to
read every evening. I hope she doesn't need to read this to know how much her
love and support mean to me.

xiii
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 crank-
ing out millions of lines of code in the modem 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 newVB 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 newVB delivered against
these goals. The new VB, called Vzsual 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 devel-
opment 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 leam! Where
to start?
I've had many different people ask me about the best way to get into pro-
gramming 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

xv
Introduction

to learn anything. A program too large doesn't work, either-you end up spend-
ing 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/listboxl combo box 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 ofVB. 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 vari-
ous 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

xvi
Introduction

are looking to update your skill set to something more modem. Or perhaps
you've picked up software development as a secondary skill at your job (you're
the office "Excel macros guru"), and now you want to learn something more for-
mally. Whatever the case, my assumption is that as you crack open 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 mathe-


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

xvii
Introduction

Table 1. Download the Source Code


FOLDER NAME USED IN
Art Graphics/sounds used throughout the book

BMPStitch AppendixC
CellularAutomata ChapterS

Cellul~tomata~thSave Chapter 9

Common Modules/ classes used by multiple projects

DicePanel Chapter 2

DicePanelNew Bonus, used by the Yahtzee game

DirectXDemo ChapterS

FirstApplication Appendix A

GarbageDemoOne Chapter 9

GarbageDemoTwo Chapter 9

GuessTheDieRoll Chapter 1

GuessTheDieRoll2 Chapter 2

GuessTheDieRoll3 Chapter 2
lnterfaceEbGinlple Chapter 6
NetReversi Chapter 7
NineTiles Chapter 3
PCOpponent Chapter 6
PolymorphismEbGinlple ChapterS

ShapeTileGames Chapter 4
SpaceRocks ChapterS
ThreadParametersOne Chapter 9
ThreadParametersThree Chapter 9
ThreadParameters1\vo (broken) Chapter 9
Yahtzee Bonus game

xviii
CHAPTER 1

Developing Your
First Game
To GET THINGS ROLLING right from the start, you'll write a complete (albeit small in
scope) game in this chapter. This game will consist of a single die rolling around
in a black panel and an end user guessing the outcome of the die (see Figure 1-1).
If you consider yourself at a beginner level and think this chapter rushes through
some of the Visual Basic (VB) fundamentals, then refer to Appendix A, "The Basics
of Visual Basic," to create a simple project in a step-by-step fashion.

~ Guess the Oie Roll '.,~

Try Again

Figure 1-1. The Guess the Die Roll game in all its glory

1
Chapter 1

NOTE As you go through the code for this first program, you may
find you don't agree with all the design decisions made along the
way or with how the code is organized. As it turns out, I've gone out
of my way on this first program to write the code in a distinctly
non-object-oriented style. I've done this so you'll have a point of
comparison when you rewrite the same game in Chapter 2, "Writing
Your First Game, Again." So, ifyou're new to the .NET language,
concentrate on the individual language elements and constructs, as
well as the features ofVisual Studio (VS), and pay less attention to
the form and structure of this first program.

When you saw Figure 1-1 with its slick 3D-rendered die, I hope you said to
yourself "Oooh, that's pretty cool." This book covers the VB .NET language and
object-oriented development using simple games as examples. In other words,
this book doesn't teach how to develop the next Quake killer. However, a small
game can still become extremely popular if it's done well and if it's fun to play.
Done well means that the graphics, sounds, and overall design of the game are
interesting, unique, funny, or all three. Fun to play is of course a matter of opin-
ion, so the games you write will have to at least pass your own "fun meter"-and
then perhaps you can try them out on family, friends, and coworkers to get their
input.

Learning the Basics of Object-Oriented Programming


Older, procedural-driven languages were difficult on developers in terms of code
organization. As projects in these languages grew, it became hard to manage the
source code. Larger projects could be split up into different source files, but many
times the variable or procedure declarations would collide if they had similar
names (which is just one example of the problems that the lack of organization
produced). Programmers found they had to name their constructs uniquely to
avoid collisions, which meant the variable and procedure names got longer and
longer. Having procedure names such as StockltemSaveMonthlyPaymentToDatabase
certainly didn't help make the code more readable.
Part of the issue was simply finding things in a large project. As a natural
step, developers began putting procedures that handled similar functions
together, sometimes in a single source module. Therefore, all the reports might
reside together, or all of the routines handling one type of data might reside
together.
The object-oriented programming approach was developed, in part, to allow
developers to organize the code by grouping together code constructs that han-
dle similar functions. In fact, the object-oriented programming methodology
forces the developer into grouping code in a natural way and into doing so from

2
Developing Your First Game

the beginning of the coding process. Programmers new to this approach might
find this methodology difficult at first because they often can't simply jump into
their editors and start writing lines of code. Instead, before you start coding, you
must plan how you'll organize the code and group it into units and, to some
extent, how these units will interact.

What Are Classes and Objects, Anyway?


The basic grouping mechanism in an object-oriented programming approach is
known as a class. A class is a grouped collection of code and data that models
something in life-either a concrete item or a concept. For example, if you're going
to write a program that collects information about people (a human resources
application, perhaps), then you'll probably create a class in your application that
models a person and another class that models a group of people (such as all
those in a department or all those managed by one supervisor). If your applica-
tion instead tracks information for a library, then you'll most likely create classes
to model books, magazines, videotapes, CDs, and anything else people can
check out of the library. If your program is going to track baseball games, then it
would be natural to create classes for players, pitchers, games, teams, leagues,
and seasons.
As you can see, the minute you describe a program, even with a single sen-
tence ("a program to track baseball games"), the object-oriented approach asks
you to begin modeling the real or theoretical concepts of your program into
distinct classes.
One way to think of a class is as a recipe to create something. An object, on
the other hand, is an actual something. In other words, if a class is a recipe for
a cake, then an object is the cake you create from the recipe. You can use the
recipe to create many different cakes, and the cakes can be the same (the same
flavor, the same frosting, the same number of tiers), or they can be different.
Extending the analogy into the programming world, the class is the recipe, and it
doesn't maintain any real presence in memory-all the class can do for you is
create one or more instances of whatever it models. These instances are called
objects. Each object has its own memory space and is independent. So, if you
have a BaseballPlayer class, then you can create one, two, or 25 instances of that
class to represent all the players on a team. You might also have a BaseballTeam
class that contains the 25 BaseballPlayer instances. You could then have 30 instances
of the BaseballTeam class, each representing a different team in a league. These 30
BaseballTeam instances might be stored in two instances of the BaseballLeague class,
representing the American and National Leagues (assuming major league baseball
players are being modeled). Notice how the organization of the classes and objects
model the relationship of these constructs in "reallife."

3
Chapter 1

Why Object-Oriented Programming Is Valuable


This object organization is a powerful concept in that it's both self-documenting
and extendable. It would be easy to draw a graphical representation of the classes
previously described; people create such graphical representations all the time-
the official name for such a drawing is a UML class diagram. (UML stands for
Unified Modeling Language.) In addition, the relationship of the classes makes it
easy to know where to "put things" when the developer adds functionality to the
program. Suppose version 2.0 of the baseball program has to also model front-
office personnel (to store their contract information, for example). It's easy to see
that you can create a FrontOfficeMember class, and you can place instances of that
class where they belong-as part of the BaseballTeam class (perhaps now renam-
ing it to something more appropriate such as BaseballOrganization). If the
program has to track some new advanced statistic for each player, it's evident
that this new statistic will become a member of the BaseballPlayer class so that
every instance of this object has a place to store this statistic.
One other important thing to know about classes is that their definitions can
be hierarchical in nature, which is to say that you can create a class by first start-
ing off with another class and then extending the functionality of that base class
to create something new. When you do this, the base class is called the ancestor,
and the new class is called the descendant. You can also say that the new class is
a subclass of the base class. The .NET class hierarchy is a giant family tree in
which you can trace every class back to a single ancestor. That "patient zero"
ancestor is the class that has the (somewhat unfortunate) name of Object.
Sub classing gives you a powerful way to share functionality between classes
that are somewhat, but not entirely, similar. Getting back to the baseball exam-
ple, the program has to represent both pitchers and hitters. Pitchers and hitters
share many common traits-for instance, they both belong to teams, they both
have uniform numbers, and they both have a height, weight, age, and birthplace.
Many of them went to school and played baseball there, which is another piece
of information you'll want to store.
However, hitters and pitchers also contain many differences that you need
to keep distinct. Pitchers have a separate statistical set than hitters; for pitchers,
the program has to keep track of innings pitched, earned run average, and num-
ber of starts, wins, and losses (among other statistics). For hitters, relevant
statistics include batting average and number of hits, walks, and strikeouts.

NOTE This example is modeling American League baseball, where


pitchers don't usually hit. The relationship (and therefore the class
structure) would be different if the program had to model the
National League rules, where the pitcher bats. Furthermore, the
design would require even more complexity if the program had to
model both sets of rules.

4
Developing Your First Game

You can easily model this relationship by using the sub classing ability of an
object-oriented language. You could model these constructs by creating an ancestor
class named BaseballPlayer and creating two subclasses from this class named
BaseballOffensivePlayer and BaseballPitcher. The common pieces of informa-
tion such as height, weight, age, and school would reside in the ancestor class,
and the specific pieces of information unique to hitters and pitchers would
reside in the appropriate subclass.
You'll start looking at VB classes to see examples of all these concepts soon,
but you have one stop to make first-the .NET Framework.

Overview of the .NET Framework


Before cranking out and explaining reams of code, this section discusses some of
the underpinnings of this new language and development platform. VB .NET is
what's known as a .NET Framework language. The .NET Framework consists of
two major components-the .NET Framework class library and the common
language runtime. The former is a set of classes (recipes) that provide support
for all of the languages in the .NET family. From the viewpoint of a former VB
developer, it's accurate to say that the .NET Framework class library will in most
cases replace the application programming interface (API) calls and user inter-
face toolbox elements of your old language. That is, the classes in the .NET
Framework class library will replace all the forms, buttons, listboxes, treeviews,
labels, and checkboxes. But it also goes much deeper than that-basically, the
Windows API is also encapsulated into an object-oriented framework. One quick
example (and one relevant to this book) is the availability of graphics-related
classes such as pens, brushes, and bitmaps. These concepts are easy to encap-
sulate into a class.

Understanding the Common Language Runtime


You can think of the common language runtime as the foundation upon which
.NET programs are built. The common language runtime handles the overall
memory management of your program, as well as the thread management. It
also handles the line-by-line execution of your program. As a beginner to .NET
languages, you don't need to know much about the common language runtime.
It's always there doing work for you (running your programs), but you don't need
to know much else-much like you don't really need to know how the internal
combustion process in your engine works to drive a car or how a processor can
talk to a graphics card to use your computer.

5
Chapter 1

Understanding the .NET Framework Class Library


The .NET Framework class library, on the other hand, is something you'll become
slowly familiar with as you learn VB .NET. In fact, much of the learning process is
becoming familiar with the classes in the .NET Framework-much more than
learning the syntax of the language, which has changed a bit but not dramati-
cally from previous versions of VB.
The classes that make up the .NET Framework are organized in a hierar-
chical set of structures known as namespaces. There really isn't anything to
compare namespaces to in older versions of VB, so you can think of them as
groups of objects compiled into a sort of directory structure. The highest level of
the directory structure is a namespace, and it's represented by a D11 on the com-
puter. Within that D11, however, can be other namespaces, each with its own set
of classes, and those child namespaces can also contain namespaces within them.
The physical D11 that contains one or more namespaces is called an assem-
bly. For your project to use any of the classes in a namespace, it must reference
that assembly. A new project has a default set of references that you can see when
you begin a new project. You'll learn how to add additional references to your
project in Chapter 2, "Writing Your First Game, Again."
With this introduction to the .NET Framework out of the way, let's look at
your first class.

Class Is in Session
The Guess the Die Roll program will begin its life as a standard Wmdows Appli-
cation solution. You can create this type of project and give it any name you like
now. Or, if you'd rather study my version of the project, refer to the project named
GuessTheDieRoll. If you haven't downloaded the source code for the book yet, you
can do so in the Downloads area of the Apress Web site (http://www.apress.com).

NOTE . Please refer to Appendix A, liThe Basics ofVisual Basic," if


you want to learn (or review) how to create a new solution in
Visual Studio .NET and find your way around the environment.

Uyou select Form1.vb in the Solution Explorer for this new project and then
click the View Code button at the top of the Solution Explorer, the main window
of Visual Studio will open and show you the code that makes up the default form
in your project (see Figure 1-2).

6
Developing Your First Game

Form1.vb [Design) Forml.vb I


111\ (General)
8 Public Class Foral
Inher1c s Syscem.Windovs.Forms.Form

t ll,Jindovs Form Desillller Ilene raced code I


End Class

Figure 1-2. The auto-generated code for the default form in a Windows Forms
project

It doesn't look like much at first, does it? The tiny amount of code declares a class
named Formi, which is a subclass of something called System. Windows. Forms. Form. This
represents the full name of a class, including the namespace in which that class
resides. The ancestor class name is Form, but it resides inside a namespace named
System. Windows. Forms.

NOTE The dot notation for the System. Windows. Forms namespace
doesn't imply that there's a namespace named Forms contained
within a namespace named Windows contained within a name-
space named System. Instead, there's a single assembly named
System. Windows. Forms. dIl on your computer (it might take
a while to get used to filenames that have multiple periods in
them). There's a System namespace, as well, contained in the
assembly System. dIl, but obviously because these two assemblies
are contained in different files, the namespaces aren't considered
one within the other.

So, the default project has a class named Formi, which is an ancestor of
a class named Form. What does that mean? Well, for starters, it means that the
Formi class automatically gains all the functionality of its ancestor. For an idea of
just what type of functionality this is, select View ~ Class View from the Visual
Studio menu, navigate down to Forml, open Bases and Interfaces, and then
open Form. Your Class View's treeview will quickly fill up with all the available
members of the Form class, as shown in Figure 1-3. Amember is a field, property,
event, or method attached to a class.

7
Chapter 1

NOTE You'll learn the definition ofall these terms as you go. For
now, it's important simply to note the sheer quantity of members
found in the Form class and know that the Formi class you're about
to build upon already contains the functionality of Form simply
because it's declared as an ancestor of the Form class. This "borrow-
ing" offunctionality is one of the truly powerful aspects of
object-oriented programming.

[ Class View - NolhinjL


~~ ~

El ·ii1 Nothing
B {} Nothing
El ~ Forml
$_.
~ Bases and Interfaces
El ~ Form
IB- ~ Bases and Interfaces
GJ·~ ControlColledion
; <!'
[Select](ByVal Boolean, ByVal Boolean)
.'~. ActlliateO
, ,.~ ActivateMdiChud(ByVal System.Windows,Forms,Form)
'''. AddOwnedForm(ByVal System ,Windows,Forms ,Form)
~ AdjustFormSuollbars(ByVal Boolean)
~ ApplyAutoScalingO
.~ CenterToParentO
-~ CenterToScreenO

.• '''. CloseO

Figure 1-3. The Class View, showing all the functionality received for free because
Formi is a subclass of the class Form. I love free stuff, don't you?

Understanding Properties
Properties store a piece of information that helps describe an object. Think of
a property as a variable that describes some aspect of the object to which it's
attached. The Form class, for example, has properties to describe its size (height
and width) and location on the screen (top and bottom). Changing the value of
any of these four properties changes the appearance of the form.
Note that a property helps to describe an object, not a class. It's important
to understand the distinction between those two terms. The class (recipe) helps to
define the presence of the property and can declare a starting value, but the prop-
erty itself is associated with each instance of the object. This means, of course,
that each instance can have a different value for the same property. If a cake class
has a property named lcingFlavor, then of course each actual cake can have a dif-
ferent value in this property, meaning that each cake can have a different flavor of
icing. If a cake class has a property named NumberOfLayers, then each cake can be

8
Developing Your First Game

a single-decker, double-decker, or quintuple-decker, depending on the value that


this property contains for each instance of the cake class.
In Visual Studio, you can view and edit the properties for all of the visual
objects you create (your user interface elements such as forms, buttons, and
labels) with the Properties window. You can open this window using the F4 key
from within Visual Studio. The Properties window is a two-column grid (see
Figure 1-4).

Properl les II '

IfGuess System.WlndoW5.Forms.Form

[iJ ~. IOO ~
El Accesslbrhty
--------------------------,
AccesslbleDescrlption
AccessibleName
AccessibleRole Default
El Appearanc
BackColor o Control
Backgroundlmage o (none)
Cursor Default
I!l Font Tahoma, 8.2Spt
ForeColor Controllext
FormBorderStyle Sizable
RlghtToLeft No
Text Guess the Die Roll
El 8ella i
AllowDrop False
ContextMenu (none)
Enabled True
ImeMode NoControl
13 Lonfrguta on
I!l (DynamicProperties)
13 0 t
I!l(DataBindlngs)
Tag
13 Desrgn
(Name) fGue5S
DrawGrld True
I!l GridSize 8,8
Locked False
SnapToGrid True
13 Focu'
CausesValldatlon True

TeKt
The text contained In the control.

Gil Solution Explorer ~ pr~ I~ Class View I

Figure 1-4. The Properties window

9
Chapter 1

The left column of the grid displays the name of each property, and the right
side displays the current value of each property. The Properties window shows
the properties for a single object at a time. To change which object is being dis-
played, you can click a new object in the Form Designer, or you can select that
object from the drop-down box at the top of the Properties window.
You can change a property by clicking the row that contains that property
and then, depending on the type of variable that the property represents, typing
a value, selecting it from a list, or sometimes selecting it from an extended
selector.

TIP If a property has enumerated values (with a drop-down list to


select them), you can cycle through the possible values by double-
clicking the property name.

Figure 1-5 shows the Start Position property on the Forml object in the
example project being changed from the value WindowsDefaultLocation to the
value Centerscreen. This property is an enumerated type, meaning it has a finite
number of possible values, with each value represented by an easily remem-
bered word. As you can see in Figure 1-5, you change the value of the property
by selecting the desired value from a drop-down box. Once changed, the prop-
erty value displays in bold if it's different from that property's default value.

I!l Size 456,408


-
CenterScreen J
...
WindowState
B .M=an~uall~=-IIIIII"~
AcceptButton WildowsDef aultLocation
CancelButton WindowsDef aultBounds
KeyPreview CenterParent
language ~uerault)

J=:tt.-o

Figure 1-5. Changing a property value in the Properties window

Understanding Fields
A field on an object is so similar to a property (at least from the outside of the
object) that it's almost impossible to tell the difference between the two, so this
chapter won't cover them in any detail. Like a property, a field is like a variable
attached to an object instance that describes some aspect of the object. The dif-
ference between fields and properties is in how they're declared; because you're
not quite ready to learn about declaring, let's continue.

10
Developing Your First Game

Exploring More Auto-Generated Code


Besides the class declaration and the corresponding End Class statement, the
rest of the auto-generated code shown in Figure 1-2 is a single line that reads
Windows Form Designer generated code. This line at first looks pretty innocuous
(perhaps because it's light gray), but the little plus sign to the left of it is a clue
that there's something going on underneath. Clicking that plus sign yields some
more Visual Studio auto-generated code and demonstrates a cool new feature of
Visual Studio: the ability to group code into blocks and then collapse that block
to make it easier to manage large modules. If you expand the collapsed region in
the Visual Studio code editor, you'll see the VB code shown in listing 1-1.

Listing 1-1. Auto-Generated Form Initialization and Cleanup Code

#Region " Windows Form Designer generated code "

Public Sub NewO


MyBase.NewO

'This call is required by the Windows Form Designer.


InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.


Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer


Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer


'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.

11
Chapter 1

<System.Diagnostics.DebuggerStepThrough(» Private Sub InitializeComponent()

'Forml

Me.AutoScaleBaseSize = New System.Drawing.Size(s, 13)


Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Name = "Forml"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me. Text = "Forml"

End Sub

#End Region

Visual Studio generated all of this code, including the comments, when you
created your project. There's a good deal of stuff in Listing 1-1 that isn't explain-
able right away, but one thing worth mentioning is toward the bottom, where
several properties of this form object appear (AutoscaleBaseSize, ClientSize, Name,
startposition, and Text).
Note how all of these properties are referenced with the Me keyword-for the
Clientsize property, for example, this keyword means "the property attached to
Me named Client Size." Also, notice that the property you changed in the prior
section, Start Position, is one of the properties listed. This is because the prop-
erty is no longer at its default value. If you change it back to the default value
WindowsDefaul tLocation in the Properties window, this line of code disappears.
Likewise, if you delete this line of code, the Properties window reflects this change.
It's best to get into the habit of not modifying this auto-generated code directly,
however, because you might (in the worst case) confuse the compiler or corrupt
your form to the point where Visual Studio can't read it anymore. When modify-
ing the value of properties, always use the Properties window.

NOTE You can add things to the auto-generated code; for example,
you might want to add some resource cleanup code to the Dispose
method shown previously or some initialization code to the New
method, as the comment suggests.

Designing the Die Roller Form


One of the first things you should do when starting a new project or adding
a form to the existing project is to rename the form. The name Formi is obviously
not very descriptive, and although it seems like no big deal in this small project,
the name will lose what little meaning it has as soon as you add a second form
12
Developing Your First Game

to the project ("Which form is Formi again?"). You can change the name of a form
or any other visual control in the Properties window. The label for the Name prop-
erty is enclosed in parentheses, as shown in Figure 1-6 (Microsoft does this so
that the Name property remains at the top of the Properties window when you
sort the properties alphabetically). For this example, enter the name fGuess as
your form name.

PIC/pc-Illes q. X

IrGuess System.Windows,Forms,Form

:= [IDOO
IIII (DataBindings)
IIII (DynamicProperties)
rGuessl
AcceptButton (none)

Figure 1-6. Changing the name ofyour form

Form Renaming Gotcha


When renaming the initial form in a project, you'll get an error message from
Visual Studio the next time you try to compile and run your project. For this
example, this error message reads as follows:

'Sub Main' was not found in 'GuessTheDieRoll.Formi',

What this rather confusing error message is trying to tell you is that the project
no longer knows which piece of code to run first. The project was originally
instructed to run Formi on startup, but you just renamed Formi out of existence.
To fix this error, you'll need to right -click the project name (not the solution
name) in the Solution Explorer, select Properties, and change the Startup Object
in the drop-down box (you can also select Project ~ Properties from the menu
to get to the same dialog box). In a beginning project like this one, there will be
only two choices for startup, either fGuess (the renamed Formi) or Sub Main. Sub
Main is only available if you don't want to load a form in the beginning of the
project. Of course, you must have a Sub Main somewhere in your program to
choose this option.

VB got its name because designing forms is a visual process. That is, the pro-
grammer can arrange the user interface at design time by adding controls to
a form and then moving and sizing them into their desired positions. This was

13
Chapter 1

the first Windows language that allowed the graphical arrangement of controls at
design time. VB .NET is certainly no exception to this feature-you design forms
visually. Specifically, you place controls on a form by using the Toolbox, which is
docked (by default) on the left side of Visual Studio (see Figure 1-7).

*I Toofbox ~ x

a
-<
a-
0
My User Controls
Data
x Com onents
Windows Forms •
I~ Pointer
A label
~
A Unklabel
.!!!l Button
lObi TextBox
Ii! MainMenu
P CheckBox
r. RadioButton
L.J GroupBox
PictureBox
o Panel
hi r"la...t: .......

Figure 1-7. The Visual Studio Toolbox. Now where's that screwdriver. .. ?

The Toolbox contains a series of controls commonly used to create applica-


tions. Acontrol is a certain type of object in the .NET Framework. Most controls
have a visual representation (such as a button or label), and they have built-in
code to handle user input (clicks, key presses, and so on).
To begin visually designing a form in your project, locate that form in
the Solution Explorer and double-click it. You can also highlight the form in the
Solution Explorer and click the View Designer button (second from the left) at
the top of the Solution Explorer, as shown in Figure 1-8. Once you have chosen
either of these options, the visual designer for this form will display.
To add a control to a form, simply locate the desired control in the Toolbox
and drag it onto the form. Alternately, you can double-click the control name in
the Toolbox, which will add an instance of it to the form. Once added, you can
move and size the control in the manner you'd expect-by clicking the control to
select it, by dragging it from the center to move it, and by using the sizing han-
dles around the edge to size it.

14
Developing Your First Game

Solullon E>plorer . r·lrne T,Ies Q. x

Solution 'NineTiles' (I project)


~ &I NineTiles
. References
B res
,... ~ applause.w<!lv
~ die!.wav
I ~ die2.wav
~ dischord.wav
!@ laughs.wav
, I?MI numbertnes. bmp
~". ~ squeak!.wav
i-- ~ squeak2.wav
: ~ thud.wav
!.. Assemblylnfo. vb

- Q Solutlon Explorer I~ Properties 121 (l<!Iss "iew I

Figure 1-8. The Solution Explorer, showing the View Code button and the View
Designer button on the toolbar (the first and second buttons from the left,
respectively)

Once you place a control on a form and select it, you can use the Properties
window to change that control's appearance and behavior, just as you changed
the form's properties earlier.

TIP You can select multiple controls in the designer by dragging


a rectangle around them or by Ctrl+clicking on them in sequence.
You can then edit the common properties o/multiple controls in
the Properties window.

The Guess the Die Roll game form has seven label controls on it. Six of the
controls are similar-they're the numbered "buttons" the user will click to make
a guess. This game will use label controls for these buttons mainly because they're
easier to color and because they don't give the 3D "clicking" effect. The choice
was purely aesthetic. The seventh label control tells users whether they won or
lost the game.
The fastest way to add these controls to a form is to add the first label, set its
properties so that it looks just the way you want it to look, and then copy and
paste it five more times (you can copy and paste controls just like in Word or
Excel). You'll then have to change the names of the six labels to IbOne, IbTwo,
IbThree, IbFour, IbFive, and IbSix.

15
Chapter 1

Table 1-1 describes the numbered labels and their common properties. (When
you view their values in the Properties window, they look slightly different.)

Table 1-1. Label Properties

PROPERTY NAME VALUE


BorderStyle System.Windows. Forms. BorderStyle. FixedSingle
Cursor System.Windows.Forms.Cursors.Hand
Font New System.Drawing.Font("Tahoma", 14.25!,
System. Drawing. FontStyle. Bold)

Size New System.Drawing.Size(56, 48)


Tag "Yes"
TextAlign System. Drawing. ContentAlignment.MiddleCenter

Observe how some of these properties are object instances themselves-the


Size and the Font properties have a New keyword in front of them. This is how you
create a new instance of an object in code. The BorderStyle, Cursor, and TextAlign
properties are all an enumerated type. The name of the enumerated type is the
second-from-the-Iast word in the value (BorderStyle, Cursors, ContentAlignment,
respectively). The value of the property is the last word (FixedSingIe, Hand, and
MiddIeCenter, respectively). The remaining portion of the property value is the
namespace in which that enumerated type resides (System.Windows.Forms,
System.Windows.Forms again, and System. Drawing, respectively). Enumerated types
are designed so that their values are self-explanatory rather than having some
arbitrary integer value represent the property (in other words, BorderStyIe = 1
isn't quite as self-documenting as BorderStyle = FixedSingIe).
The only property left to explain in Table 1-1 is the Tag property. If you have
experience in VB 6 development, the Tag property was kind of a catchall place
to put any user-specific data. The first beta versions of VB .NET left out the Tag
property, but Microsoft put it back in because of developer feedback (mainly
for backward-compatibility reasons). The six labels have a "Yes" value to easily
differentiate them from the single-user feedback label. You'll see why in the
next section.
The only remaining design-time object left to put on the form is the user
feedback label. This label's name is IbResul t, and it goes under the six buttons.
Figure 1-9 shows the form in the designer after adding the seven label controls.

16
Developing Your First Game

c -:' .::-; 'l;": :;:; . t,::::: t~;:


hi' ~ Guess the Die Roll ?'{:
li:!::::::::::::::::::::::::::::::::::::::::::::::::::::::: : ':
im::::0 :[~] :0:[~~] 0 : [~~]: :;:
ilT
~r ::::: ::
eorrect!
: ::::::::::::::::::::::
............ · ••.
:::::::::::::: :::: :
f t ,"

Figure 1-9. The Guess the Die Roll program at design time

Coding the Die Roller


The routine shown in Listing 1-2, named UpdateGuessButtons, takes care of color-
ing the label on which the user clicks.

Listing 1-2. Coloring the Guess Buttons

Private Sub UpdateGuessButtons()

Dim ctl As Control


Dim clrBack As Color = Color.Blue
Dim clrFore As Color = Color. White

For Each ctl In Me.Controls


If TypeOf ctl Is Label Then
With ctl
If .Tag = "Yes" Then
If CInt(.Text) = Guess Then
.BackColor = clrBack
.ForeColor = clrFore
Else
.BackColor = Color.FromKnownColor(KnownColor.Control)
.ForeColor = Color.Black
End If
End If
End With
End If
Next
End Sub

17
Chapter 1

There's quite a bit to look at in this relatively small routine, whether you're
new to VB or a VB 6 programmer learning .NET. First, three variables are declared
at the top of the procedure. The two color variables are also initialized to a default
value, which is something you wouldn't be able to do in VB 6. For this program,
these two variable values never change from their default values, so you could
theoretically make them constants. In this case, they're variables in case the game
ever expands to support variable color schemes, such as the ability to load user-
selected colors from a configuration file.

TIP The Color data type is actually a structure rather than a class.
Within it are dozens of static members that retum colors by name.
You can also specify colors by Red-Green-Blue (RGB) values. Don't
worry if any of the terms such as structure or static member are
confusing at this point in the game-it'll all be clear eventually.

The rest of the routine is a loop that iterates through all of the controls
found in the collection Me. Controls. Me is a special keyword in VB that refers to
the current object in which this code resides. In this case, the code is inside
the form fGuess, so the loop iterates through all the controls that are part of that
form. This includes the seven label controls.
The next If statement checks if the current control in the loop is a label
(there could be other classes of controls on the form besides the seven labels,
and in fact there will be other nonlabel controls by the time this project is com-
plete). If the current control is a label, then a With statement begins. A With
statement is a form of shorthand that allows you to avoid having to enter
a control's name repeatedly in a block of code. A With statement begins with the
keyword With and then contains a control name. The statements within the block
can then omit the control name and refer to properties and other members with
only a period and the member name. The With statement allows you to omit the
control name to make code shorter and more readable.
The rest of the code inside the loop checks first to see if the currently con-
sidered label has a Tag property value of "Yes" (so that the IbResul t label is never
considered in this coloring code). If it does have a Tag value of "Yes", then the
code performs a check to see if the Text (formerly called the Caption property in
VB 6 and prior) of the currently considered label control matches that of an inte-
ger variable named Guess (whose declaration you'll see later). If this label has
a Text value of 2 and the current value of Guess is 2, then the background and
foreground colors of this label change to the values of the two color variables ini-
tialized at the beginning of the routine. If the Text value and variable value aren't
equal, then the colors change to the system colors (using yet another built-in
.NET Framework enumeration named KnownColor and a function to convert this
enumeration to a color data type named FromKnownColor).

18
Developing Your First Game

The purpose of this routine is to color the six numbered labels so that the label
that matches the value of the Guess variable is blue and the other five labels remain
black on gray. If one assumes that the value of Guess can only be 1 through 6, then
this code will always color exactly one label white on blue and the other five black
on gray.

Adding Your Own Property


For simplification, the previous section mentioned that an integer variable
named Guess stores the number (1 through 6) that the user guesses for the next
die roll. In truth, this was a little lie. Guess is actually a property added to the
form. Listing 1-3 shows the code that defines this new property.

Listing 1-3. A Property Added to the fGuess Form Class

Private FGuess As Integer


Property Guess() As Integer
Get
Return FGuess
End Get

Set(ByVal Value As Integer)


FGuess = Value
End Set
End Property

There are actually two declarations in Listing 1-3, but they're related. The
first is a private integer variable named FGuess. By declaring a variable private,
you hide that variable from any code outside of this form class. Even if someone
knew there was a variable named FGuess and tried to refer to it from outside the
class, the compiler would complain and state that this variable was unknown.
The second declaration is for the Guess property itself. This declaration is
more complex than the simple FGuess integer declaration. A property is defined
in a block that has (up to) two subblocks within it: a Get function and a Set pro-
cedure. The Get function returns the value of the property whenever someone
references it. That is, if a piece of code like the following executes:

If CInt(.Text) = Guess Then


.... do stuff
Else
... do other stuff
End If

19
Chapter 1

then the property's Get routine executes when it's time to evaluate the value of
the Guess property. Note that the code doesn't simply have to return the value
of a variable-it could go through any type or length of VB code to calculate or
derive the value of the function before returning the current value.

CAUTION By convention, I've always used a capital F as the first


letter of private form-level variables, as in this example's integer
variable FGuess. This could initially be confusing from the stand-
point that the form in this project is named fGuess, coincidentally
having the same name as the form-level variable.

The Set procedure of a property does just the opposite-its purpose is to


store the value whenever the property is written to. So, if code is written like this:

Guess =1

then the property Set procedure executes. In the case of this property, the pri-
vate FGuess variable is set to the value passed into the Set procedure and is
returned as the current value of the Get function. This is the simplest, most
trivial type of property to set up.
The astute reader might ask the following: "Why set up a property in this
way?" This property is functionally equivalent to this declaration:

Public Guess as Integer

Here, a simple integer variable is declared, but it's specified as public instead
of private. A public declaration means that the variable is visible to code outside
of the class. Therefore, something functionally equivalent was created in fewer
lines of code. Isn't that better?

~ TIP A public variable declared on a class is also called a field.

Under most circumstances, shorter code that does the same thing is indeed
better, but in this situation that's not lOO-percent correct. The reason is that set-
ting up properties, even if they don't look like they're going to do much for the
program yet, are much more powerful and allow you to conserve code later. You
won't see this in action until the next chapter when you'll rewrite the Guess the
Die Roll program. At this point, just know that properties are better than fields in
helping you write more structured object-oriented code.

20
Developing Your First Game

Setting Up Events, or Making the Program Do


Something
The program now has a form class named fGuess that contains seven labels,
a property named Guess, and a routine named UpdateGuessButtons that colors the
six numbered labels to match the value in the property. What the program doesn't
have yet is something that calls this routine. You want the UpdateGuessButtons
routine to execute when a user clicks one of the six numbered labels. To accom-
plish the execution of code, the program needs an event handler.
Wmdows programs operate using an event-driven model, meaning that the
program usually just sits around waiting for something (an event) to happen. This
something is most commonly a mouse click or a key press. The type of mouse click
(where clicked, which button, button going up or down) or the type of key press
(which key, key going down or up) determines what the program does. Many of
these events are preprogrammed-for instance, clicking in the title bar of a win-
dow and dragging it moves that window around on the desktop. You don't have to
program that functionality into VB .NET programs because the functionality is
built into the operating system. Ditto for sizing a window by dragging the lower-
right corner-that functionality is built into the operating system.
However, coloring the six buttons (actually, labels) when one of them is
clicked on isn't standard functionality, so you'll have to code that functionality.
This means you have to write an event handler for the Click event of the six label
controls. listing 1-4 shows the code for that event handler.

Listing 1-4. Click Event Handler for the Numbered Labels

Private Sub cbButtonClick(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles IbOne.Click, _
IbTwo.Click, IbThree.Click, IbFour.Click, IbFive.Click, IbSix.Click

Guess = CInt(CType(sender, Label).Text)


Call UpdateGuessButtons()
Call RollTheDie()

If dieResult = Guess Then


lbResult.Text = "Correct!"
Else
lbResult.Text = "Try Again"
End If
End Sub

21
Chapter 1

An event handler in VB is just a standard procedure (declared Sub) . They're


also declared private, meaning that they're not callable from the outside of this
class. This is desirable because event handler routines are usually not called
directly in a program anyway-they're called as a result of the desired events
occurring.
In this case, the desired event is one of the six labels being clicked. You can
see that the declaration of this event handler states that this event is "attached"
to the events IbOne.Cli ck, IbTwo.Click, and so on all the way to IbSix.Click using
the Handles keyword.
To set up an event handler, you use the code editor. At the top of the code-
editing window are two drop-down boxes. The left drop-down box lists all controls
on the current form. Once you select a control, the right drop-down list shows all
the event handlers available for this control (see Figure 1-10). Selecting one of
these event handlers adds an empty event handler procedure to your code.

h bOno :::oJ 111\ (Declarations) ::J


Iaports syse ••. Kath Il\ (Oeclaratlons) ..!.
I.ports Syse ••. Thre .. d.in1jll P AutoSizeChangod
P II
a Publ1c Cl .. ss feu .... P Bil<InQCantextChonr./od
Inhu"J.c,. S .t. ••. Vinclova:. ' oral' . 'ora .- P Cause<Vold~ ~
P ChonQeUICues L
t:::!i!!£'~1I. D•• J.'71'"Ier .,.neratwi (;'0<11 I P Click
P CantextMeruChonQod
Pri'lla'l:.. pnLov.r A.s Paint Panel
P Cant",IAddod L
Pr1va.e41 bS.ck A, 8ie••p 'backqr
P Cant,oI\emoved
PCur5OrChqod
Pdvae. bStop ..u Bie_ap
Private bxllot A. Dit_AD POisposod

Figure 1-10. Viewing available event handlers for a control using the two drop-
down boxes in the code editor

As you can see in Listing 1-4, you can make the same event handler handle
events on multiple controls by listing those events after the Handles clause. This
is easy to do manually.
The event handler in Listing 1-4 does a few things. The first thing it does is
set the Guess property discussed in the previous section to some value. It obtains
that value by casting the variable sender (which is passed into the event handler
and represents the label that the user clicked) to a label type, then obtaining
the value of the Text property of that label, and in tum converting that text
(string) value to an integer. All of those things happen in a single line of code:

Guess = Clnt(CType(sender, Label).Text)

Stated another way, when the user clicks the 3 label, this code converts the
passed-in sender parameter to a label, converts the text of that label to an integer
value, and stores it in the Guess property.

22
Developing Your First Game

Code Size vs. Complexity


The previous lone line of code functions perfectly, but it does quite a few things
at one time, which could be confusing to another programmer trying to figure
out what the code is doing. There's a constant battle between keeping a program
"short and sweet" and keeping it easy to read. You could rewrite the single line
of code in the following, more verbose way:

Dim lb as Label
lb = CType(sender, Label)
Guess = Cint(lb.Text)

As always, it's up to the developer to decide whether to go for compactness or


readability. Factors helping to determine this decision include whether other
developers might someday be responsible for your code, your company, or
your department coding standards and how you feel that day.

After the Guess integer is populated based on the clicked label, the next line
of code calls the UpdateGuessButtons procedure (which has already been dis-
cussed). This procedure, as you might recall, colors the six labels in such a way
that the one matching the value of the Guess property turns blue. The complete
effect is the user clicking one of the labels and having that label change color.
The following line calls a procedure named Roll TheDie. You'll learn more
about this procedure in the "Tying the Functionality Together" section.
Finally, a new variable named dieResult, is compared with the value of the
Guess property. If the values are equal, the seventh label changes to read Correct!,
meaning the user correctly guessed the value of the die roll. If the value of the
two variables isn't equal, the message ny Again displays in the seventh label.
This simple event handler represents the complete "flow" of the Guess the
Die Roll game. When one of the numbered labels is clicked, the value is stored,
the correct label is colored, the die is rolled, and the user is notified whether she
won or lost. The game then waits for the user to click one of the labels again, and
the process repeats.

23
Chapter 1

Setting Up Methods
The procedures discussed in the previous section, UpdateGuessButtons, are called
methods. A method is a procedure or function associated with a class. In the case
of the Guess the Die Roll program, the UpdateGuessButtons method is associated
with the fGuess class, which is a subclass of the .NET Framework form class.
Methods are often thought of as the "do work" code for a class. Because of
this, it's common that a method name is an action phrase or a verb. Look at all
of the method names associated with the final (version 1) fGuess class in the
Guess the Die Roll program, and you'll see a pattern:

• RollTheDie

• UpdateDiePosition

• DrawDie

• UpdateGuessButtons

Each of the method names has a verb in it, and thus it's self-evident what
task each method performs.

Rolling the Die


Okay, the mundane part of the game has been covered-selecting the number
from 1-6, highlighting the selected button Gabel), and declaring whether the
user wins or loses. Now for the graphics! Getting the die to bounce around at the
bottom of the form takes several different techniques.

Introducing the Graphics


The die is an animation comprised of three sets of 36 frames, 108 frames in total.
There's a set of 26 frames that shows the die rotating along its x-axis, a second set
that shows rotation along its y-axis, and a third set that renders each of the six
possible values rotating into its final position (each one of the six values com-
prises six frames). Each of the 36 frame sets exists in a 6X6 bitmap. Figure 1-11
shows the x-rotation bitmap. For instructions on how to create these bitmaps,
refer to Appendix B, "Using POV-RAY and Moray," and Appendix C, "Using the
BMPStich Utility."

24
Developing Your First Game

Figure 1-11. One of the three sets of36 frames of die-rolling animations

Drawing the Graphics


The die rolling works something like a cartoon-the program first decides where
on the screen it's going to draw the die. Then it selects one of the 108 frames for
drawing, and finally it draws that frame to the screen.
Well, that's almost correct. Instead of drawing that frame directly to the
screen, the program instead draws the frame to an intermediate bitmap and
then draws that bitmap to the screen. Why this extra step? The main reason is
screen flicker-copying graphics to a visible surface causes visual problems. This
becomes important as more and more objects are rendered (like later when the
program draws two dice instead of one die). If you draw to the final visible sur-
face, you can run into screen-flickering issues that aren't appealing to users' eyes.

Describing the Die

Obviously, the program must know several pieces of information to correctly


render the die on the form:

25
Chapter 1

• The width and height of a frame

• Which frame to draw at a given time (and how to figure out which frame
to draw next)

• The current location of the die on the form (as x and y coordinates)

• The current direction the die is moving

The width and height of a frame are constants, and you can declare them as
such at the top of the fGuess form:

Const HGT As Integer = 144


Const WID As Integer = 144

These values depend on how the frames of the die were created. The current
location of the die is also held in a pair of integer values:

Private diexPos As Integer


Private dieyPos As Integer

A lowercase die designates that these are variables describing the die, and
xPos and yPos are abbreviations for the x position and y position.

NOTE Variable naming is certainly more art than science; I like to


be somewhat consistent in my naming conventions, and I almost
always use descriptive variable names except for loop variables or
in short blocks of code where the declaration is clearly visible a'll
point out these exceptions along the way).

Next are the two variables that represent the direction in which the die is
moving:

Private diexDir As Integer '-8 to 8


Private dieyDir As Integer '-8 to 8, indicates direction moving

As the comments indicate, these two variables hold a value between -8 and 8
(but never 0). A die moving left has a negative x direction; a positive x direction
indicates it's moving right. Likewise, negative and positive y directions indicate
upward and downward movement, respectively. Because neither direction can
ever be 0, the die is always moving in some sort of diagonal. This is intentional

26
Developing Your First Game

because the animated frames of the bitmap indicate movement along the "diag-
onal" of the pseudo-3D surface upon which the die is rolling (in other words, it
looks better if the die doesn't move straight up, down, left, or right).
There are three final variables to record the state of the die, the final result of
the roll (l-6), the current frame being displayed (0-35), and a status variable to
describe in which state the die is. You might recall from Listing 1-4 that the result
variable is named dieResult. The other two variables are also appropriately
named as follows:

Private dieResult As Integer 'result of the die, 1-6


Private dieFrame As Integer
Private dieStatus As DieMovementStatus = DieMovementStatus.dslanding

All of the variables declared to this point have been simple integer types.
Look at the type of the dieStatus variable-it's a type named DieMovementStatus.
It's also being initialized to a value of dslanding. Can it be that there's a variable
type built into the .NET Framework that explicitly lists the possible status values
for a rolling die? Sadly, no. Instead, you have to make you own variable type,
called DieMovementStatus, and list the possible values with the declaration. As
mentioned earlier, this is known as an enumerated type. Fortunately, it's easy to
create your own:

Private Enum DieMovementStatus


dmsStopped = 0
dmsRolling = 1
dmsLanding = 2
End Enum
Private dieStatus As DieMovementStatus = DieMovementStatus.dmsLanding

Enumerated types work just like integers under the hood, but they're much
easier to use for two reasons. First, the code is much more readable as follows:

dieStatus = DieMovementStatus.Rolling

as opposed to the following:

dieStatus = 1

Second, enumerated types prevent the programmer from using an unknown


or out-of-bounds value. The die status type has three possible values: 0, 1, or 2. If
you were to use an integer to store the die status, there would be nothing to pre-
vent the code from putting a 3, -3, or 1,203 into that variable. If other parts of that

27
Chapter 1

code are expecting only 0-2, there's no telling what bug you just introduced by
placing an unexpected value in there.

Getting Down to Graphics


Okay, you've now declared all the variables required to keep track of the state of
the die. Listing 1-5 shows the code that actually draws the die onto the back-
ground bitmap (named bmBack).

Listing 1-5. The DrawDie Routine

Private Sub DrawDie()

Dim gr As Graphics
Dim oBitmap As Bitmap

Dim x As Integer = (dieFrame Mod 6) * WID


Dim y As Integer = (dieFrame \ 6) * HGT
Dim r As New System.Drawing.Rectangle(x, y, WID, HGT)

If dieStatus = DieMovementStatus.dmsRolling Then


'check quandrant rolling toward based on sign of xdir*ydir
If (diexDir * dieyDir) > 0 Then
oBitmap = bmyRot
Else
oBitmap = bmxRot
End If
Else
oBitmap = bmStop
End If

gr = Graphics.FromImage(bmBack)
Try
gr.Clear(Color.Black)
gr. DrawImage(oBitmap, diexPos, dieyPos, r, GraphicsUnit.Pixel)
Finally
gr .DisposeO
End Try

pnLower.Invalidate()
Application.DoEvents()

End Sub

28
Developing Your First Game

As usual, this rather tiny routine is doing quite a bit of work. The variables x
and y are set up first. These variables represent the upper-left comer of one of the
36 frames within one of the three die animation bitmaps. The variable dieFrame
holds the frame number, and the two equations shown in the declaration ofvari-
abIes x and y calculate the x and y coordinates of that frame. The backward slash
in a math statement such as this one refers to an integer divide (where any deci-
mal is truncated), and the Mod operator is the remainder operator after an integer
divide. You can check out the math if you like with an example. Suppose dieFrame
holds the value 17, then the upper-left comer of frame 17 would turn out to be
as follows:

x = (17 mod 6) * 144 = 5 * 144 = 720


Y= (17 \ 6) * 144 = 5 * 144 = 288

Thus, the upper-left comer of frame 17 is the coordinate (720, 288). Next,
a .NET Framework class known as a Rectangle is instantiated and filled with these
starting coordinates, as well as the constants that represent the width and height
of a die frame:

Dim r As New System.Drawing.Rectang1e(x, y, w, h)

This rectangle should now describe one frame of the die within one of the
three animation bitmaps.
Now that the program knows the coordinates within the animation bitmaps
needed to draw the frame, it needs to select the proper bitmap of the three avail-
able bitmaps. Listing 1-6 shows the selection code.

Listing 1-6. Selecting a Die Animation

Dim oBitmap as Bitmap


••• (code removed for clarity)
If dStatus = DieMovementStatus.dmsRolling Then
'check quandrant rolling towards based on sign of xdir*ydir
If (diexDir * dieyDir) > 0 Then
oBitmap = bmyRot
Else
oBitmap = bmxRot
End If
Else
oBitmap = bmStop
End If

29
Chapter 1

As you'll recall, the three bitmaps represent the die rolling in the two direc-
tions diagonally and coming to a stop on each of the six values. These three
bitmaps are held in variables named bmxRot, bmyRot, and bmStop, respectively
(you'll see how to load these variables with bitmaps in the next section). When
one of the three bitmaps is selected, it's placed in variable oBi tmap for later.
The process of selecting which bitmap comes first determines what state
the die is in (variable dieStatus). If that status is dmsRolling (the enumerated
type value), then more work needs to happen. If the status is any other value
(dsStopped or dsLanding), then the choice is easy-the "stopping" is the selected
bitmap, which is held in the variable bmStop.
Now, let's get back to the dmsRolling case. What must be decided is if the die
is rolling in "upper-Ieft-to-Iower-right" diagonal direction or in the "lower-Ieft-
to-upper-right" direction. These are the only two cases because the possibility
that the die is moving along a true vertical or horizontal has already been elimi-
nated. The direction in which the die is traveling is held in the diexDir and
dieyDir variables. The value in these two variables is a random value between
-8 to +8, with zero removed as a possibility. You can determine the diagonal
direction by multiplying diexDir and dieyDir and looking at the sign of the result
(proof that you can use geometry in real life). If the sign is negative, then the die
is moving along the "lower-Ieft-to-upper-right" diagonal. If the sign is positive,
then it's moving along the other one. Figure 1-12 illustrates using the two direc-
tion variables to determine the direction of the diagonal.

- dxDir -y + dxDir
- dyDir - dyDir

-x

- dxDir
"/ /
~
+x

+ dxDir
+ dyDir + dyDir
+y

Figure 1-12. Determining which diagonal the die is rolling in by using simple
geometry. Special thanks to my 10th-grade geometry teacher, Mr. Cosimi!

The code in listing 1-6 performs this multiplication and selects either the
bitmap bmxRot or bmyRot based on the sign of the result.
Okay, so now there's a source bitmap (one of the three animated die bitmaps),
a source rectangle based on which frame to draw, and a destination bitmap
(named bmBack). All that remains is to determine where to draw the die on the
destination. This is easy, though, because variables that record the position of

30
Another Random Scribd Document
with Unrelated Content
road may run off with them.” Starlight obeyed, frightened enough at
the thought of the possible loss of the borrowed articles, and quickly
returning with them to the great relief of both Hazel and himself.
Then the story went on again, turn and turn about, Flutters
gaining courage to join in now and then, till at last, when the
twilight had given place to the sort of half darkness of a starlight
night, and the fire-flies were flashing their little lanterns on every
side, they had told all there was to tell, and three foot-sore little
people confessed they were tired and sleepy and hungry, and glad
enough to go indoors and do justice to a most inviting little supper,
which Josephine had slipped away some time before to prepare.
“Bonny Kate” (as she was called more than half the time, after a
certain wilful but very charming young woman in one of
Shakespeare's great plays) had long ago fallen asleep, and lay just
where her mother, running indoors for a moment, had stowed her
away in a corner of the great hair-cloth sofa in the dining-room. One
pretty hand was folded under her rosy cheek, and such a merry
smile played over her sweet face! She surely must have been
dreaming of a remarkable little fellow, in beautiful velvet and
spangles, coming head over heels up a garden path.
CHAPTER V.—CAPTAIN BONIFACE
RECEIVES AN ANGRY LETTER.

T is one thing to help a much-abused and unhappy


little member of a circus troupe to run away from his
unhappy surroundings; it is quite another thing to
provide for all his future, particularly if, like Flutters,
he has not a penny to his name nor a stitch to his
back, none more serviceable, that is, than the ring
costume of a high and lofty tumbler. And so it was
that Mrs. Boniface and Josephine and Harry sat up
well into the night, laughing heartily now and then over the funny
side of the children's adventure, but talking gravely enough most of
the time of its more serious side.
“As far as I can make out,” said Harry, “Starlight rather expected
to bring Flutters over to the farm to-morrow and ask Aunt Frances to
care for him, at least till he found somebody else who would. I
imagine his heart rather failed him later, as it ought to. Aunt Frances
has enough to bother her at present.”
“But you don't blame the children for helping the poor little fellow,
do you?” said Josephine, warmly; “I think almost anyone would have
done the same thing under the same circumstances.”
“Very likely, Miss Josephine, but that doesn't dispose of the
troublesome question, What is now to be done with him?
“Unfortunately, there are questions to be met more troublesome
than that,” said Captain Boniface, joining for the first time in the
conversation, and he had only too good reason for speaking as he
did. Early in the evening a letter had been brought him, to which no
one had paid any attention. It was a daily occurrence for a
messenger to turn in at the gate with a note for the Captain, since
he had been for the last eight years the principal furnisher of
supplies to the English soldiers stationed in the city, and had need
both to write and receive many letters. Indeed, so loyal had he been
to King George that, at the very commencement of the Revolution,
he had joined the English army, but had had the misfortune to be
very seriously wounded in the first battle that was fought. When at
last, after weeks of constant suffering, he was able to be moved,
General Gage, under whom he served, had contrived to send him
home by easy stages along the Boston post-road, under protection
of an English escort; and Captain Boniface always declared, and no
doubt he was right about it, that nothing short of his wife's careful
nursing would ever have brought him through. But after that it was
out of the question for him to rejoin the army, so he must needs
stay quietly at home and aid the King's cause as best he could by
helping to feed the King's soldiers. All this, of course, had made
enemies of most of the Captain's old friends. Harry Avery was almost
the only exception; and now that the Colonies had been successful,
matters were looking pretty serious for him and for every American
who had sided with the King. The note that had just been brought to
him proved a very threatening one. It as much as ordered him to
leave the country, saying “that there was but one safe course for
him and his, and that was to be gone instantly; that New York had
no further use for him; that the sooner her streets and coffee-
houses were rid of him the better, and that he would simply be
taking his life in his hands if he stayed.” It was truly a terribly
alarming letter, but Captain Boniface, knowing that sooner or later
his wife and Josephine would have to know about it, now broke in
upon the conversation and read it to them.
“Who has dared to write you that?” asked Mrs. Boniface.
“Four old friends, Mary; that is the saddest part of it.”
Mrs. Boniface sat pale and silent, looking straight before her, and
not hearing another word that was said. She knew her husband well
enough to feel assured that no such letter would move him a step
from his home. Not he! He would remain and live the bitter
persecution down. But would he be allowed to live it down? There
were cruel words in that letter. “By remaining you simply take your
life in your hands,” it said, and the terrible threat sent all sorts of
dread possibilities thronging through her mind.
With anxious faces, and quick-beating hearts, Josephine and her
mother listened, as Harry Avery and the Captain talked late into the
night. It was a great comfort to realize that although Harry was a
Whig, and a strong one, too, he did not harbor any bitter feeling
against them. “Perhaps,” thought Josephine gladly, “there are others
like him.”
It seemed as though Harry must have seen the gratitude in her
expressive eyes, as he continued again and again to reassure the
Captain of his full sympathy, and his determination to be of
assistance to him in every possible way.
“Well, what will you do about it, father? Josephine asked, as just
at midnight, she leaned over his chair to say good-night.
“Do about it, child?” he said, taking her hands in both of his,
“Why, stay just where I am!”
Mrs. Boniface shook her head gravely, as she and Josephine left
the room together. She had known so well beforehand that he would
say exactly that.
CHAPTER VI.—OFF FOR THE
PRISON-SHIP.

HAT a queer sort of thing it is, this regularly going


to sleep and waking up again once in every twenty-
four hours; but people who have had a little
experience in not going to sleep regularly, and in
waking up at most unheard-of and irregular hours, will
tell you that that experience is a deal queerer, and not
so pleasant by half. Some of the little folk who have
need to be coaxed and urged to bed six nights out of
the seven, would hardly dare to fret, I imagine, if they only knew
that to be a sound sleeper is an accomplishment sorely envied by
some of those grown-up people who may sit up as late as they
choose. And if one of those wakeful, grown-up people should some
day ask you, “What is the secret of your sound sleeping, my little
friend?” just tell them that you think it is because you do not worry.
Then if they say, “That's all very well; children have no need to
worry, they have fathers and mothers to lean upon tell them that
they, too, have a Father, One far more kind and loving than any
earthly father, and that they could lie down at night as free from
worry as any child if they would;” and who knows but they will learn
a blessed lesson from you that will be well worth the learning.
Now this little reverie has all been suggested by the fact that the
Boniface household was waking up, all save old Dinah, the cook, for
she had been up for an hour or more. She had once been Hazel's
nurse, and, since the beginning of the war, was the only servant the
Bonifaces could afford to keep. How comfortable she made them,
that faithful old Dinah, so that all one had to do was to waken and
wash, and brush and dress, and then sit down to steaming coffee,
delicate rolls, and the most savory little rasher of bacon, which Dinah
always added as a “relisher,” as she called it, to the more substantial
part of the breakfast. Yes, they were waking, all of them, from
anxious Captain Boniface to happy little Flutters, for Dinah's vigorous
ringing of the rising bell had thoroughly done its work.
Each busy brain was taking up again the manifold threads of
thought which had slipped from its hold when sleep had stolen
across it so gently the night before. Captain Boniface instantly
remembered the angry letter, as, of course, did Mrs. Boniface and
Josephine, and so their waking was rather heavy hearted. Harry
instantly remembered it too, but his second thought was of the
pretty sail-boat moored down at the Boniface wharf, and of the plan
for the day, and he was glad to open his eyes on blue skies and the
sunshine that flooded his eastward room. Flutters woke with a smile.
Indeed, he doubted if he should ever do anything but smile again,
so sure was he that he had turned a very happy corner in his life.
Starlight roomed with Flutters, and his first thought when he opened
his eyes was how they were to manage to return those clothes of
Hans Van Wyck's, that Flutters was getting into with such an air of
complacent ownership. Hazel's little mind took its first morning flight
in the same direction as Harry Avery's. The sail-boat, the bay
sparkling in the sunshine, the visit to the old prison-ship—it all
meant so much to her enthusiastic, pleasure-loving temperament. A
certain uncomfortable and premeditated call upon Colonel Hamilton
could easily be postponed to an indefinite future, with such
delightful anticipations in the definite present.
“It seems heartless to be going off for a day's jaunt, when father
has so much to trouble him,” Josephine said, when, soon after
breakfast, the little party of five, basketed and equipped, were
starting down to the wharf.
“Not at all, Josephine,” answered her sweet-faced mother, holding
bonny Kate by the hand as she spoke. “We will try and keep dear old
papa cheery, won't we, little daughter?” then, seeing that Josephine
still lingered, as though reluctant to go, she added, cheerily, “nothing
would be gained by your staying, Josephine. Your father has some
office work that will keep him in the house, so you can think of him
as safe at home all day, and we are both of us glad enough to have
you enjoy a little change.” So, somewhat relieved in her mind,
Josephine hurried down and joined the Others, and soon the
“Gretchen,” with her white sail spread to the crisp morning breeze,
sped out on the river, fairly dancing along the crests of the white
caps that splashed against her prow with such a continuous and
merry little thump and splutter.

Wind and tide favored them, and Harry was an excellent sailor, so
that in a comparatively short time they had left the waters of the
Hudson behind them, had rounded Fort George, the Battery of to-
day, and were headed up the East River, with New York on the one
side, and the then scattered town of Brooklyn on the other. Skilfully
tacking in long slants from shore to shore, the wharves and shipping
were soon exchanged for the sloping banks of Manhattan Island on
the left, and of Long Island on the right, and then suddenly the
dismasted hulk of the old “Jersey” loomed up before them.
She was a dreary enough looking object to any one, but if, like
Harry, you had been a prisoner aboard of her for eighteen long
months, you would, like him, no doubt, have shuddered at the sight
of her. Josephine shuddered too. “Oh, do not let us go any nearer!”
she said.
“All right,” was Harry's quick response, for, in point of fact, nothing
pleased him better than to comply with Josephine's slightest wish, so
the “Gretchen” veered off again.
“Oh! can't we go aboard?” cried Flutters, with a world of
disappointment in his tone, for in imagination he had already scaled
the gangway ladder that hung at her larboard side, and turned more
than one somersault on the wide sweep of her upper deck.
“Why, no, child!” answered Hazel, who was fast assuming a most
patronizing air toward her little protégé; “no one would think of
going aboard of her, would they, Cousin Harry?”
“Why, why not?” Flutters asked, half-impatiently, for Harry, giving
his attention for the moment to the management of the boat, did
not at once reply.
“Because,” he said, finally, “there has been far too much sickness
in that old hulk for any one to safely venture aboard of her; she has
been responsible for the lives of eleven thousand men. I doubt if the
strongest and longest of north winds could ever blow her free from
the fever that must be lurking in her rotten timbers.”
That was a new phase of the matter to Flutters, and he subsided
at once into thoughtful silence.
“I think this would be a good place to anchor,” suggested Harry,
but waited a moment till Josephine had given her consent before
letting the anchor run the length of its rope and bury itself in the
mud bottom beneath them.
As soon as the “Gretchen” had settled into the position
determined for her by the tide, the little party of five ranged
themselves about the boat, so as to be as comfortable as possible,
for there they meant to stay for the next hour, or two, or three, as
the case might be. It had been for some time a thoroughly
understood matter between Hazel and Harry Avery, that whenever
the day should come for this trip to the “Jersey,” they were to anchor
their boat in full sight of her, and then and there he was to tell them
the “whole story”—from the day he volunteered till the day of his
release in the previous summer.
Flutters, who had been made acquainted with the object of the
expedition, waited, with a charming native sense of the “fitness of
things,” until the others had chosen their places; then he threw
himself at Harry's feet, in one of the graceful positions so natural to
him, and which even Hans Van Wyck's rough, homespun clothes did
not altogether succeed in hiding. It was wonderful to look into
Flutters's upturned face—such complete satisfaction, such tranquil
happiness shone out of it. Even in those exciting moments when
every nerve and tissue was thrilling under Harry's narration of the
dark features of his prison life, a smile still seemed to be lurking in
the corners of his expressive mouth. Yesterday, a lonely little tumbler
in a dreary, tawdry circus company; to-day, one of a blessed circle of
warm-hearted friends. Whatever fears others might have as to the
disposal to be made of him, Flutters had none for himself. Of course
he was to be Hazel's faithful little servant from that day forward, and
it was almost worth while, he thought, to have “darkey blood” in
one's veins for the sake of rendering such happy service. Farther
than that he did not trouble himself, literally taking no thought for
the morrow, nor for what he should put on when his present
habiliments should have found their way back to their rightful owner.
The “Gretchens” little company made a pretty picture against the
blue gray of the bay, and when at last there was no more arranging
to be done, and all had repeatedly declared themselves “perfectly
comfortable,” there was a breathless, momentous little pause, as in
the moment at a play between the significant and abrupt cessation
of the orchestra and the rolling back of the curtain. “Please begin,”
said Hazel, with a great sigh, as though the intense anticipation of
that supreme moment was quite too heavy for child-nature to
endure, and Harry, looking sadly over to the old “Jersey,”
commenced his story.
CHAPTER VII—HARRY'S STORY

I am to begin, Hazel, and at the very beginning,


too, if I keep my promise. Well, this little chapter of
my life began with a thought, as happens with most
everything that is done in this world, and the thought
was not one I had reason to be very proud of. I
suppose all of you know, even Flutters, that since the
commencement of the Revolution American vessels have been
cruising about, hoping to capture English vessels.
“Now it chanced about two years ago that the 'Hannah,' a very
rich prize, was brought into New London. Some of the men who had
taken part in her capture had sailed out of New London as poor as
could be, and here they came sailing back again, with a prize in tow
rich enough to fill all their empty pockets. So it was not strange,
perhaps, that the capture of the 'Hannah' turned a good many
young heads, nor that mine turned with the rest, and that, as soon
as possible, I joined the crew of the 'Venture,' a privateer that was
being rapidly fitted out for a cruise. At length everything was in
readiness, and away we sailed with the highest hopes, and with our
pretty brig so crowded with musketry that when in action she looked
like a great flame of fire. Well, we were not long at sea before we
gave chase to an English ship, in appearance as large as ours. We
exchanged a few shots, then we ran alongside of her, and with one
salute of all our fire put her to silence, and fortunately, too, without
losing a single life. I can tell you I was a happy fellow, Hazel (Harry
seemed to consider Hazel his chief listener), when it fell to my lot to
be one of the crew who were ordered to man the prize and bring her
into port; happy I was, and as proud as a turkey-cock; but that state
of things did not last very long. It was our purpose not to attempt to
make a landing until we should reach New Bedford; but before we
had even cleared the shores of Long Island an English ship of war,
the 'Belisarius,' of twenty-six guns, bore down upon us, and in less
than an hour from the time she had sighted us, those of our number
left on the 'Venture,' and those of us who had manned the English
brig were all prisoners together and in irons in her hold.”
“Bless my stars! were you really?” exclaimed Flutters, quite
unprepared for this turn of affairs.
“Yes, Flutters, sixty-five of us, and on our way to the old prison-
ship, yonder.”
“How many did you say?” asked Hazel. She had been thinking she
must teach Flutters not to say “Bless my stars!” and things like that,
and so her attention had wandered for a moment.
“Sixty-five, and in less than five months we were reduced to thirty-
five.”
“Did thirty die?” she asked, incredulously.
“Yes, thirty did die,” interrupted Starlight, setting his lips firmly, for
he knew what he was talking about, “and you old English as good as
murdered them.”
“Starlight, don't you dare to speak like that to me,” was Hazel's
quick retort, while the blood flashed hotly into her face. Flutters
gazed at her with astonishment. Perhaps, thought he, it will not
always be an easy matter, after all, for even the most faithful of
body-servants to please such a spirited little mistress.
“Good for you, Hazel,” laughed Harry; “I would not stand such
incivility either, if I were you; but then I must tell you one thing, not
all English hearts are as kind as yours and Josephine's. If they were,
the old 'Jersey' would not have so sorrowful a tale to tell.” Harry
paused a moment. Starlight and Hazel were feeling a trifle
uncomfortable. They could not resist the temptation to give each
other a little home-thrust now and then on the score of their political
differences: The result, as a rule, was a half-acknowledged
admiration for each other's patriotism, and an extra touch of mutual
consideration in word and manner for the time being.
“Flutters,” said Hazel, solemnly, perhaps by way of disposing of
the pause that seemed to reflect somewhat upon the conduct of
herself and Starlight, “Flutters, what are you?” Flutters looked down
at his queer little Dutch outfit, and then up at Hazel, with a smile,
which said as plainly as words, “I give it up.”
“I mean,” continued Hazel, “who do you side with? Are you a
stanch little Loyalist like me? That is, do you think, as I think, that it
is very wrong to take up arms against the King?”
Flutters was lying flat in the bottom of the boat now, his dark little
face propped between the palms of his hands, at a loss to know how
to answer. He was a trifle embarrassed by the directness of Hazel's
question.
“I would rather side with you, Miss Hazel,” he replied, at last, “a
sight rather; but mulatto boys what has passed most of their time in
a circus don't know much 'bout those things. I'm going to hear Mr.
Harry out, and then I'll make up my mind.”
“Very well,” Hazel replied, with chilling dignity; “please go on,” she
added, turning to Harry.
Harry hesitated a moment, evidently trying to recall just where he
had left off.
“You were in irons on the 'Belisarius,”' suggested Josephine,
whose thoughts, judging from the far-away look in her eyes, had
been with the poor prisoners all the while rather than with what had
been going on about her.
“Oh, yes, there we were! and fortunately with no idea of the
suffering in store for us. Early the next morning we were led on
deck. The 'Belisarius' had dropped anchor over yonder (pointing to
the New York shore), and two boats were coming toward us, for she
had signalled the 'Jersey' that she had prisoners to transfer. Oh, how
our hearts sank within us as the little boats that were to carry us
came nearer and nearer, and do you wonder, children, that we
dreaded to board the old craft? Did you ever see a drearier-looking
object, with never so much as a spar or a mast to remind you of the
real use of a vessel? Even her lion figure-head had been taken away,
leaving nothing but an unsightly old hulk, and yet I believe the
Englishmen who were in charge of her thought the place, wretched
as it was, too good for us. It seemed we were not even to be
treated with the consideration due to prisoners of a war with a
foreign nation. Having risen against the Mother Country, in their eyes
we were simply traitors. Hopeless and despairing we were rowed
over to the old prison, marched up the gangway ladder, ordered
down the hatchway, and then, with the brutal exclamation, 'There,
rebels! there is the cage for you,' we found ourselves prisoners in
the midst of a very wretched company.”
The story was growing pretty painful, and likely to grow still more
so, provided Harry told them all, as he had promised. Besides, it was
so terribly real, sitting there aboard of the “Gretchen” with the old
“Jersey” right before them.
By way of affording a little relief from what she felt was yet to be
told, Josephine asked: “What was that canvas-covered place there in
the stern used for?”
“Oh, that was a shelter put up for the guards on the quarterdeck.
Just below that, and reaching from the bulkhead of the quarter-deck
to the forecastle, was what they called the spar-deck, and it was
there that we were allowed to take such exercise as we could. We
used to walk in platoons facing the same way, and then all turn at
once, so as to make the most of the little space. The gun-room,
right under the quarter-deck, was where I was imprisoned, and it
was a trifle more comfortable there, if you can use that word in
connection with anything on the 'Jersey,' than the crowded place
between decks where most of the prisoners were herded together. I
had fortunately been chosen second mate on the English brig during
the little while that we were masters of it, and to that lucky fact I
owed my assignment to the gun-room with the other officers. But
for that, I do not believe I should be here to-day to tell the story. I
do not see how I could have endured any more and lived. As it was,
you know, I was very ill.”
“Yes, I know,” said Hazel, laying her hand affectionately over one
of Harry's and looking sympathetically into his face; “perhaps you
had better not say very much about that part. Josephine and I cry
very easy; don't we, Josephine?”
“Then please don't, Harry,” urged Starlight; “I'd rather have a
good thrashing any time than see a girl cry,” recalling one occasion
in particular, when his own misconduct had moved Hazel to tears,
and she had refused for the space of one long half hour to be in
any-wise comforted.
Flutters had not paid the least attention to this last interruption.
He was thinking that, after all, the life of a friendless little circus
performer, sorry and comfortless and forlorn as it was, might be less
full of hardship than a prisoner's. It was a very grand thing to have
one's freedom, and he had always had that—that is, he might at any
time have run away if he chose.
“What did they give you to eat, Mr. Harry?” he asked, by way of
comparing bills of fare.
“Little that was fit to eat, Flutters; but I can tell you exactly if you
would like to know,” and Harry drew from his pocket-book a scrap of
folded paper. “This was our list of supplies. I wrote it down the first
week on board, and knew it quite by heart all too soon. I think I
could repeat it now.”
“Suppose you try,” and Josephine taking the paper from his hand,
Harry at once began to recite, with the satisfied air of a child that
perfectly knows its lesson:
“On Sunday.—1 pound of biscuit, 1 pound of pork, and 1 pint of
peas.
“On Monday.—1 pound of biscuit, 1 pint of oatmeal, 2 ounces
butter.
“On Tuesday.—1 pound of biscuit, 2 pounds beef.
“On Wednesday.—1 1/2 pounds of flour and 2 ounces suet.
“On Thursday.—Same as Sunday.
“On Friday.—Same as Monday.
“On Saturday.—Same as Tuesday.
“There, how is that?” he asked, “any mistakes?”
“Not one,” answered Josephine; “but really, Harry, is that all you
received?”
“Why,” exclaimed Flutters, “seems to me that's considerable.
Circus folks often don't fare no better than that, and don't get things
so reg'lar, either.”
“And yet, Flutters, that is only two-thirds of the allowance of an
English seaman. However, we would have managed well enough to
exist if the things had been good in themselves or decently cooked,
but all the provisions were of so wretched a quality that many a poor
'Jersey' prisoner died from starvation through sheer inability to eat
them.”
“Who cooked the things for you?” asked Hazel.
“Whenever we could manage, Hazel, we cooked them ourselves.
Do you see that big derrick on the starboard side? Well, that was for
taking in water, and we each had a scanty allowance of so much and
no more each day. But, as a rule, we contrived to save a little of it
with which to do our own cooking, because only the toughest men
on board could so much as swallow the food prepared by the ship's
cook. Under the forecastle, there in the bow, hangs a great copper
divided in the middle and holding two or three hogsheads of water.
In one side they cooked the meat, in the other the peas and oatmeal
—sometimes, I believe, in salt water, but always in water so stale as
to be absolutely unfit for use. So five or six of us would club
together, each contributing our portion of water to the cooking
supply, and then, by begging a little wood from the cook, now and
then, and splitting it very carefully and economically with our knives,
we could manage to keep a fire going that would soon set our little
pots boiling. It was a great day for us, I remember, when a tangle of
driftwood came bumping against the ship's side, and we were
allowed to haul it on board for our fires.”
“It must have been very hard only now and then to have had a
little butter for the biscuit,” remarked Hazel, to whom this particular
feature of Harry's story appealed most pathetically, so very fond was
her own little ladyship of the variety and sufficiency of a well-
appointed table.
“But the butter was not forthcoming, Hazel; they gave us rancid
sweet-oil instead, which refused to pass muster with our Yankee
palates, so that we were able to bestow a double portion upon some
poor Frenchmen, who were very grateful for it.”
Flutters had changed his mind about the adequacy of the
“Jersey's” bill of fare, and was growing not a little indignant over
Harry's narration.
“Miss Hazel,” he said, while the color flashed through his dark skin,
“I am siding with the Yankees very fast.”
“I do not blame you very much, Flutters; I never heard of
anything like it;” which was quite a concession for so loyal a little
Red-Coat as Hazel.
“But, Harry,” asked Josephine, who could scarcely bear to hear of
such barbarous treatment at the hands of her own kinsmen, “do you
think King George and the English nation, generally, knew about it?”
“No, I don't, nor do I believe they know it now; but they will some
day. It was their business to know it, Josephine, and not to leave
thousands of human beings at the mercy of a few merciless British
seamen. Your own father would scarcely credit all I could tell him of
our treatment, nor many another English officer; but it was the clear
duty of some of them to have looked into the matter.”
“You don't mean it was my papa's duty, do you?” Hazel asked,
bristling up a little; she was not going to allow even “Cousin Harry”
to utter a word that would seem to reflect upon her father even for a
moment.
“No, of course, I don't mean anything of the kind. If I thought
Captain Boniface in any way responsible for those horrors, do you
think I could be on such friendly terms with him? No, Hazel, your
father is a true, brave man, and no one knows better than I how
much he has given up in King George's service. It was not his duty
to inspect the prison-ships. Furnishing supplies for the English troops
called for every moment of his thought and time, and taxed all his
strength and energy; but there are some men—men whom your
father knows—whose names we need not mention, who are very
culpable in the matter, if you know what that means?”
“I suppose it means very much to blame,” sighed Hazel.
“Oh, I wish you would just go on telling about things!” urged
Flutters, beseechingly, for to him the story itself was far more
interesting than any side remarks.
Harry remained silent a moment. Since Josephine and Hazel “cried
very easy,” he had need to be careful just where he began again. “I
must not forget to tell you,” he said, “something about 'Dame Grant,'
as we called her, for her visits to the old 'Jersey' constituted almost
our greatest blessing. She was a fat old woman, who dealt in sugar
and tea, pipes and combs, needles and pins, and a few other of the
necessaries of life. Every day or two her little boat would push out
from the Brooklyn shore, and, rowed by two boys, over she would
come to the ship's side. Those of us who were fortunate enough to
have any money were then allowed to go to the foot of the ladder
and make some little purchases, obtaining everything—so she
always assured us—'at cost price.' But sometimes I was almost sorry
that I had a cent to spend. It was so terrible to see the longing in
the faces of the poor fellows who had no money. I will say this much
in our favor, however; I think there was hardly a man among us who
did not share with some one else fully half of whatever he had
bought. But suddenly the visits came to an end. One morning the
little boat put out from the shore as usual, but with no one in it save
one of the boys who used to row it, and he brought us the sad news
that the old 'Dame' had caught the fever from the hulk of the
'Jersey' and died. After that no one else was ever willing to run the
risk of contagion for the sake of the profits of our little purchases.
But one of the happiest experiences that ever came to us in those
long, dreary days, was to be allowed to become a member of the
'Working Party.' It was composed of twenty men, and all the
prisoners who had any strength left were always eager to join it. It
was the duty of these men to wash down the upper deck and
gangway, to spread the awning, and to hoist wood, water, and other
supplies on board, from the boats that came alongside. Then, in the
case of any deaths—and there were often three or four during a
single night—some of the party would be assigned the duty of burial,
and sent to the shore for that purpose, but always closely watched
by two or three guards. Strange as it may seem, this sad duty was
considered the most desirable of all. It meant setting ones foot on
dear old Mother Earth again, for, at least, a little while, and even the
mournful work in hand could not quite offset that pleasure. Only
once was I so fortunate as to be chosen, and so keen was my
delight in treading the ground again, that I actually took off my
shoes for the sake of feeling the sand fall away from my feet as we
pushed along with our sad burden. Now and then it would happen
that, notwithstanding the watchfulness of the guards, a prisoner
would succeed in making his escape when sent ashore with one of
these interment parties. Near the spot where most of the 'Jersey's'
prisoners were buried was a comfortable homestead belonging to a
miller. The men used to call it the 'Old Dutchmans, and always
looked toward it with a sort of veneration as they passed,
particularly as they knew that the miller's daughter was deeply
interested in us. She kept account of all the poor fellows who were
brought to the shore to be buried, and I think many of us cherished
a vain sort of hope that deliverance might possibly come through her
some day.”
“That was strange about caring to feel the sand against your feet,”
remarked Starlight; “that is the last sort of thing you'd think a fellow
would ever really care for.”
“Very likely; but if you ever spend even a month on shipboard
you'll find yourself longing for some of the things that you never so
much as gave a thought to while you had them. Why, when the men
returned to the 'Jersey' from the shore they would take back with
them as much common turf as they could carry, and the little
fragments would be greedily sought for and inhaled with more
pleasure than if they had had the fragrance of a rose.
“Did they pay you in any way for the work? asked flutters, still
anxious to compare experiences.
“Not in money, of course, Flutters, but we had the privilege of
going on deck early in the morning, and were allowed to stay till
sunset. All the other prisoners were ordered down to the foul air
between decks two hours earlier, there to stay, come what would,
for ten wretched hours, with the iron gratings of the hatchways
firmly fastening them in. Then we were granted a full allowance of
provisions, such as they were.”
“Tell about when all the 'Venture's crew were at last exchanged
excepting you and Tom Burnham,” suggested Starlight, in a pause
that offered.
“No, don't, please,” Josephine exclaimed; “we all know about that,
and it was so very dreadful. Besides, it's all right now.”
“What,” said Flutters, eagerly, sitting bolt upright “what's that? I
don't know about it.”
“I'll tell you,” Hazel whispered, motioning him closer to her;
meanwhile Harry pointed out different parts of the ship in answer to
certain questions of Josephine's.
“You see,” explained Hazel in a melodramatic whisper, “that Cousin
Harry was taken sick one day very suddenly, and then he had the
fever so badly that he was carried over to Blackwell's Island to die.
But he didn't die.”
“Didn't he, really?” asked Flutters, mischievously.
“I wouldn't joke about a thing like this, Flutters. No, he didn't die;
but while he was getting well very slowly a cartel—that's a kind of
boat—was sent from New London, with some English prisoners on
board, to exchange for the crew of the 'Venture;' but there were not
quite as many English prisoners as were needed for an exchange, so
they decided they would have to leave Cousin Harry and a friend of
his, Tom Burnham, who were sick over on the island, behind, and as
soon afterward as those two poor fellows were well enough, back
they had to go again to that dreadful old 'Jersey.' Wasn't that pretty
hard?”
“Gosh, yes,” exclaimed inelegant little Flutters, and Hazel excused
the word because the occasion seemed to demand something
strong.
“And there they stayed, Flutters, one whole year longer, till last
August, when the English had to let all their prisoners go free; but
understand, Flutters, it was just those few bad men in charge of the
'Jersey' who were so cruel. In other places we did not treat our
prisoners badly at all. Besides, it was very wicked indeed to take
arms against the King, though, of course, men like Cousin Harry
thought they were doing right.” Hazel, as usual, wound up with a
defence of her own loyalist principles.
And so the story of Harry's hard prison life was all told, or, rather,
as much of it as was suited to his audience or was not too
heartrending, and at once the little party agreed to weigh anchor
and sail quite out of sight of the dreary old ship before opening the
well-filled luncheon baskets stowed away in the “Gretchen's” narrow
hold.
And then, of course, every one kept on the lookout for the best
point to come to anchor again; but Flutters was the first to discover
a most attractive spot on the New York side of the river, where some
fine old trees grew close to its edge, and already cast their shadows
far enough out on the water to shade the “Gretchen” from bow to
stern. Thither they sailed, quickly dropped anchor, and soon sitting
down to cold tongue and biscuits, peach jam and sponge cake,
endeavored to banish all thoughts of prisoners and prison-ships. It
was not hard work, for Flutters was funny, and Starlight and Hazel
actually silly. Indeed, all of them felt a sort of reaction from the
gloomy, depressing thoughts of the last hour, and, to my thinking, a
little silliness was perfectly allowable. After a most leisurely
luncheon, Hazel and Starlight moved to the stern of the boat. There
was one important matter they had need to discuss confidentially—
the return of Flans's clothes. Hazel had not forgotten her promise to
surely bring them back to Mrs. Van Wyck the next day; and now the
next day had come, and with no better prospect of any other
equipment for Flutters. Entirely unconcerned, Flutters, growing
drowsy in the noontide stillness of the river, had stretched his lithe
little body along one of the boat cushions and fallen asleep.
Josephine, after stowing away the emptied baskets, had seated
herself again with her back against the mast. Harry had moved to a
seat by her side, and they were talking together of what filled both
their hearts—their anxiety for Captain Boniface; and Harry was doing
his best to calm Josephine's fears. He spoke most cheerily and
hopefully, for he honestly did not believe the antagonism against her
father would amount to so very much; and watching her lovely face
brighten at his encouraging words, no doubt thought how very
beautiful she was. You would have thought so too could you have
seen her, with her wide-brimmed hat pushed far back on her head,
and the airiest of little breezes playing with the pretty light hair that
lay in curling wisps about her forehead. Starlight happened to glance
toward Josephine just as he and Hazel had settled the matter they
had in hand, and seemed more impressed with her beauty, as she
sat there, than ever before.
“You don't often find a girl like your sister Josephine,” he said;
“she's lovely herself, and she's lovely to look at. Those two things
don't generally go together—in girls.”
“What do you mean?” asked Hazel, bristling a little, as usual.
“I mean that most lovely girls know that they're lovely, and that
spoils it. The good-natured girls are most always homely.”
“No, of course, you're not homely, Hazel, but then you're not”—a
long pause—“so very good-natured either;” Starlight's love of
mischief having gotten the better of his discretion.
Hazel gave him one look of indignant condemnation. Then,
without a word, she moved away, took her seat at Josephine's feet,
and for the remainder of the afternoon treated Starlight with all the
studied coolness offended dignity could muster.
About four o'clock the “Gretchen” again weighed anchor and
steered out into the river, homeward bound. It had been arranged
that she should touch at the foot of Beekman Street, and that
Starlight should leave them there, so as to stop at Mrs. Van Wyck's
and see what could be done about Flutters's clothes, or rather
Hans's; and from there he would no doubt be able to beg a ride out
to the Bonifaces'. “Good-bye, Hazel,” he called back, as he bounded
on to the little wharf. Hazel vouchsafed no answer. Josephine
wondered what was up, and so did Harry, but were wise enough not
to ask any questions. Flutters was not so wise. “Miss Hazel, did you
hear Starlight call good-bye?” he queried.
“I'm not deaf, Flutters.”
“Then why didn't you answer?” with innocent directness.
“I had my own good reasons. And, Flutters, you must not ever ask
me why I do things.”
“All right, Miss Hazel,” Flutters answered cheerily, for her word was
law to him; but Josephine and Harry found it difficult to conceal a
smile.
It proved rather a tedious sail homeward, for the wind that had
blown them so finely down river in the morning had not been so
accommodating as to change its direction, and only by dint of much
“tacking” was any headway to be made. At last, however, the
Boniface homestead came in sight, and in the stillness of the twilight
the “Gretchen” was safely moored to her own little dock.
CHAPTER VIII.—A CALL ON
COLONEL HAMILTON.

OOD-BYE, Hazel,”
“Good-bye, Starlight,”
“Good-bye, Josephine,”
“Good-bye, Cousin Harry,”
“Good-bye, Flutters.” Quite a medley of good-byes,
to be sure, but no more than were needed, for Harry
and Starlight, once more aboard of the “Gretchen,”
were fast gliding out on to the river, and Josephine
and Hazel and Flutters were being left behind on the
wharf. The little prison-ship party had had their
supper, and now Harry and Starlight were off for
Paulus Hook; it was high time, too, that they were,
since they had already been absent a day longer than Harry had
planned, and Aunt Frances would naturally begin to feel worried.
Little Flutters cut a queer figure as he stood there on the boating
dock in the moonlight. Hans Van Wyck's clothes, done up in a snug
bundle, were already on their way back to their lawful owner, so that
he had need to resort once more to the spangles and tinsel of his
circus costume. By way of making up for insufficient clothing, Mrs.
Boniface had thrown a shawl about him, one end of which Flutters
allowed to trail behind, pinning the other close about his throat, with
one corner thrown over his left shoulder.
“We must do something about some clothes for you, Flutters, right
away,” Hazel remarked, as they turned to walk up from the wharf,
when, amid the darkening shadows of the river, the “Gretchen's” sail
was no longer visible. “Starlight and I hoped Mrs. Van Wyck would
offer to give us that suit of Hans's to keep when he stopped to see
her this afternoon and told her about you, but she did not propose
anything of the kind. She only said 'it was very inconvenient for Hans
not to have them, and she hoped we'd manage to get them back to-
night.'”
“And you have managed, haven't you, Miss Hazel?” Flutters
answered, as if the managing were a matter to be proud of; and,
mimicking a sort of stage stride such as he had often witnessed in
tragical circus pantomimes, he apparently bestowed far more
attention on the sweep of his majestic train than on what Hazel was
saying.
“Yes, of course, I sent them back; what else could I do?”—this last
rather impatiently, because of Flutters's exasperating unconcern
__"but how are you going to manage without them is what I'd like
to know.”..
Flutters gave Hazel a comical little look. “With tights and shawls, I
s'pose, Miss Hazel, unless the Captain felt like as he could buy some
for me.”
“No,” said Hazel decidedly; “I am not going to bother father 'bout
things like that, 'specially now when he's so worried and his life's in
danger.”
This remark brought Flutters to a stand. “Is the Captain's life in
danger, really, Miss Hazel?”
“Yes, it is. Josephine said he received a very angry letter the other
night from some old friends of his. They as much as told him that he
must go away, and that his life wasn't safe here; and lots of people
are going, Flutters; people who, like father, have sided with King
George.”
“Where are they going, Miss Hazel?”
“To England, most of them.”
“And will the Captain go?”
“No, Josephine thinks not. You see he built this house, Flutters,
and he loves it, and he loves this country, too. Josephine says she
believes he'll just stay, and try and live the angry feeling down.”
“Miss Hazel,”.said Flutters, stopping to gather the trailing shawl
over one arm, for he was ready now to give his whole mind to the
matter in hand, “it's a very puzzling thing 'bout me. When Mr. Harry
was telling those sad things of the prison-ship, I thought I was a
Whig, and now when you are talking 'bout the Captain, it seems as
though I was a—a what do you call it?”
“A Loyalist, Flutters?”
“Yes, a Loyalist; but I reckon folks what has friends on both sides,
had better not be anything particular.”
“Perhaps that would be best,” Hazel replied, smiling in spite of
herself.
“Miss Hazel,” Flutters said, after a little pause, stopping and
looking round him somewhat cautiously, as though he feared his
question might be overheard, “did Starlight hear of any 'quiries for
me, when he was in the city this afternoon?”
Hazel nodded “Yes” in a most mysterious manner.
“There's no danger of their 'quiring round here, do you think?”
and Hazel saw the involuntary little tremble shoot through Flutters's
frame.
“No, indeed, Flutters, and we wouldn't give you up if they did.
Mrs. Van Wyck told Starlight that a forlorn old man, who belonged to
the circus, stopped at her gate and asked if she'd seen anything of a
little mulatto boy what had deserted from the troupe, or knowed
anything about him, and Mrs. Van Wyck said, 'Lor', no!' never
dreaming that her very own little Hans's clothes were on that same
little boy that very moment.”
“That must have been good old Bobbin,” answered Flutters, fairly
chuckling over the thought of the entire success of his escape.
“Miss Hazel,” he added, after a moment's thoughtful meditation,
“I've been thinking how I might earn the money for my clothes by
doing a little tumbling for folks round here, only I'm so awfully afraid
of being heard of by the circus people.”
The suggestion instantly flashed a new scheme through Hazel's
mind.
“Flutters,” she said, very slowly and seriously, “I've—thought—of
something. Yes, it's the very thing. I'm going to town tomorrow, to
see Colonel Hamilton about an important matter, and I'll make all the
'rangements.”
“'Rangements 'bout the clothes, Miss Hazel?”
“Yes, 'rangements 'bout everything; but, hush! 'cause nobody else
must know about it.” They had reached the porch where Mrs.
Boniface was sitting, and Josephine was close behind them, which
was the occasion for Hazel's “Hush” and so little Flutters tumbled
into bed half an hour later, still in ignorance as to what the scheme
of his “little Mistress” might be, but with perfect confidence in her
ability to make any arrangements under the sun.

Joe Ainsworth found his little friend waiting in the sunshine the
next morning, and, almost without intimation from him, the leaders
came to a standstill, and Hazel mounted to her seat beside him.
“Business in town?” ventured Joe.
“Colonel Hamilton's, please,” all intent on getting comfortably
seated.
“Oh!” exclaimed Joe, with elevated eyebrows, “haven't fixed that
matter up yet, eh?”
“Not yet. I haven't had time to see to it until to-day.”
“Haven't had time,” said Joe, with a significant smile.
“No, I haven't, really. Yesterday I had to go on a sailing party and
the day before to the circus.”
“My lands, Miss Hazel! I guess if you had to drive this Albany
coach every day of your life, week in and week out, and was ever
able to take so much as a day off for a circus or a sailing party, you
would call that having lots of time. I would, I can tell ye.”
“Well, then, perhaps it was because I couldn't do both things, Joe,
so I chose the sailing party and the circus.”
“I don't blame you, Miss Hazel. Besides, there can't be anything
very pleasant for such a loyal little Red-Coat as you to look forward
to, in calling on our American Colonel.”
“I'm not afraid of any American Colonel,” with the air of a grand
duchess.
“No, of course not, Miss Hazel, but I'd have a care to that little
tongue of yours.”
Hazel did not answer. She would not have allowed many people to
offer that unsolicited advice without some sort of a rejoinder, but she
had always a most kindly side toward Joe Ainsworth, not entirely
accounted for, either, by the fact of the free rides.
For some reason or other the coach horses kept up a good pace
that morning, and it was not long before they came to a halt at
Hazel's destination.
Colonel Hamilton's law office was in just such another wide-
porched double house as the Starlight homestead; and, like it, had
been vacated by its rightful owner during the progress of the war,
and so had shared the similar fate of being immediately claimed by
the English. They were most comfortable-looking dwellings, those
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like