Programming Games with Small Basic: Chapter 1: Writing Programs

Small Basic > Small Basic Books > Programming Games with Small BasicChapter 1:  Writing Programs

This chapter is adapted from the book Programming Games with Microsoft Small Basic by Philip Conrod and Lou Tylee.

To purchase this book in its entirety, please see the Computer Science For Kids web site.

 

Writing Programs Using Small Basic

Preview

In this first chapter, we will do an overview of how to write a program using Small Basic.  You'll get a brief history of Small Basic and look into use of the Small Basic development environment.

 

Introducing Programming Games With Microsoft Small Basic

In these notes, we will use Small Basic to build many fun game programs.  The games are non-violent and teach logical thinking skills.  They are appropriate for kids of all ages (even adults).  The programs you will build are (in increasing complexity):

  • Safecracker - Decipher a secret combination using clues from the computer.
  • Tic Tac Toe - The classic game - one of the first programmed by Bill Gates!
  • Match Game - Find matching pairs of hidden photos ? you use your own photos!
  • Pizza Delivery - A business simulation where you manage a small pizza shop for a night.
  • Moon Landing - Land a module on the surface of the moon.
  • Leap Frog - A fun arcade game where you need to get a frog through traffic and across a raging river.

These programs will teach many of the skills needed to be a successful game programmer.  You will learn about timing, multi-player games, scoring, simulation techniques and animation.

Each program will be addressed in a single chapter.  Complete step-by-step instructions covering every program detail will be provided.  Before beginning the programs, however, we will review Small Basic and its development environment in the remainder of this chapter.  Then, we provide an overview of the objects used in Small Basic (Chapter 2), a review of the Small Basic programming language (Chapter 3) ), and instructions on using the Small Basic debugging (Chapter 4).  The programs will begin with Chapter 5.

 

Requirements for Programming Games With Small Basic

Before starting, let's examine what you need to successfully build the programs included with Programming Games With Small Basic.  As far as computer skills, you should be comfortable working within the Windows environment.  You should know how to run programs, find and create folders, and move and resize windows.

As far as programming skills, we assume you have had some exposure to computer programming using some language.  If that language is Small Basic, great!!  We offer two tutorials Small Basic for Kids and Beginning Small Basic, that could help you gain that exposure (see our website for details).  But, if you?ve ever programmed in any language (Visual Basic, C, C++, C#, Java, J#, Ada, even FORTRAN), you should be able to follow what's going on.  Even if you are a veteran programmer, we suggest you go through the first three chapters before attacking the programs.  This review will give you some idea of the terminology we use in referring to different parts of a Small Basic program.

Regarding software requirements, to use Small Basic, you must be using Windows 8, Windows 7, 2000, Windows XP, Windows NT, or Windows Vista.  These notes and all programs are developed using Windows Vista and Version 1.0 of  Small Basic.  And, of course, you need to have the Small Basic product installed on your computer. It is available for free download from Microsoft.

Follow this link for complete instructions for downloading and installing Small Basic on your computer: http: //www.smallbasic.com

 

Introducing Small Basic

In the late 1970's and early 1980's, it seems there were computers everywhere with names like Commodore 64, Texas Instruments 99/4A, Atari 400, Coleco Adam, Timex Sinclair and the IBM PC-Jr.  Stores like Sears, JC Penneys and even K Mart sold computers.

One thing these machines had in common was that they were all programmed in some version of Microsoft?s BASIC.  Each computer had its own fans and own magazines.  Users would wait each month for the next issue of a magazine with BASIC programs you could type into your computer and try at home.

This was a fun and exciting time for the beginning programmer, but the fun times ended with the introduction of the IBM-PC in the early 1980?s.  Bigger and faster computers brought forth bigger languages and bigger development environments.  These new languages were expensive to acquire and difficult for the beginning programmer to grasp.

Which brings us to Small Basic, which I would call a relative of the early, original BASIC language.  The development of Small Basic is an attempt to rekindle the exciting days when just about anyone could sit down at a computer and write a simple program using the BASIC language.

Those of you who wrote programs on those old "toy" computers will recognize the simplicity of the Small Basic language and the ease of its use.  And, you will also notice Small Basic is a great environment for writing and testing code, something missing in the early 1980's.  For those of you new to programming, I hope you can feel the excitement we old timers once had.  For the old timers, I hope you rekindle your programming skills with this new product.

Small Basic possesses many features of more powerful (and more expensive) programming languages:

  • Easy-to-use, Integrated Development Environment (IDE)
  • Response to mouse and keyboard actions
  • Full array of mathematical, string handling, and graphics functions
  • Can easily work with arrays
  • Sequential file support

 

Starting Small Basic

We assume you have Small Basic installed and operational on your computer.  Once installed, to start Small Basic:

  • Click the Start button on the Windows task bar
  • Select Programs, then Small Basic
  • Click Microsoft Small Basic

(Some of the headings given here may differ slightly on your computer, but you should have no trouble finding the correct ones.)  The Small Basic program should start.

After installation and trying to start, you may see an error message that announces Small Basic cannot be started.  If this occurs, try downloading and installing the latest version of the Microsoft .NET framework at:  http: //msdn.microsoft.com/en-us/netframework/aa569263.aspx

This contains some files that Small Basic needs to operate and such files may not be on your computer.

Upon starting, my screen shows:

This window displays the Small Basic Development Environment.  There are many areas of interest on the screen.  At the top of the window is the Title Bar.  The title bar gives us information about what program we're using and what Small Basic program we are working with.

Below the title bar is a Toolbar.  Here, little buttons with pictures allow us to control Small Basic.

In the middle of the screen is the Editor.  This is where we will write our Small Basic programs.  To the right is a Help area.  Small Basic has great help features when writing programs.  This area will display hints and tips while we write code.

Running a Small Basic Program

Let's write our first Small Basic program.  When you start, a new editor window appears.  You can also get a new editor window by clicking the New toolbar button.  Type these two lines in the editor window:

TextWindow.Title= "Hello Program"

TextWindow.WriteLine("This is the first line of the program.")

The editor window should look like this:

Notice as you started typing the first line, this popped-up:

Small Basic has 'IntelliSense' and uses this to make typing suggestions.  You can just keep typing or accept its suggestion by scrolling through the pop-up list and pressing the Enter key.

Also, notice this appeared in the help area: 

Once you typed TextWindow, the help feature displayed all it knows about the TextWindow to help you in your programming.

The TextWindow is a Small Basic object.  It displays text output.  The object has properties, methods and events.  There are many objects in Small Basic.  They will be reviewed in Chapter 2.

Let's run the program.  Simply click the Run button on the toolbar to see:

This is the text window displaying the program output.  I have resized the window a bit.  To stop the program, click the Xin the upper right corner of the window.

That's all there is to writing a Small Basic program.  Type the code in the editor window.  Click the Run button to run the code.  We will learn a lot of Small Basic code as we build the games in this course.  Chapter 3 reviews most elements of the Small Basic language.

Other useful toolbar buttons are:

  • Open - Open a previously saved Small Basic program

  • Save -  Save a Small Basic program

  • Save As - Save a Small Basic program with a different name

We suggest saving each Small Basic program in its own folder.

There are also the Cut, Copy, Paste, Undo, and Redo buttons for common editing tasks.  Learn to use these ? they will save you lots of time typing code.

Chapter Review

This completes our overview of the Small Basic environment and a brief demonstration of how to write a Small Basic program.  If you?ve used Small Basic before, this material should be familiar.  If you?ve programmed with other languages, you should have a fairly clear understanding of what?s going on.

After completing this chapter, you should understand:

  • A little of the history of Small Basic.
  • The various parts of the Small Basic integrated development environment.
  • The utility of 'IntelliSense' and the Small Basic help panel.
  • How to write code using the code editor.
  • How to run a Small Basic program.

Before starting the game programs in Chapter 5, we need to review the objects used to build programs (Chapter 2), the language of Small Basic (Chapter 3), and Small Basic debugging (Chapter 4).

For another online chapter, see Programming Games with Small Basic: Chapter 6: Tic Tac Toe Program.

To purchase this book in its entirety, please see the Computer Science For Kids web site.

 

Excerpt © Copyright 2010-2017 By Kidware Software LLC All Rights Reserved. Computer Science For Kids, the Computer Science For Kids logo, and related trade dress are trademarks or registered trademarks of Kidware Software LLC. Philip Conrod & Lou Tylee have co-authored dozens of books and tutorials for beginning Microsoft Basic, Small Basic, Visual Basic, and Visual C# developers of all ages for over 25 years.

 
Small Basic > Small Basic Books > Programming Games with Small BasicChapter 1:  Writing Programs