LEARN TO PROGRAM WITH SMALL BASIC: An Introduction to Programming with Games, Art, Science, and Math (2016)

INTRODUCTION

Have you ever wondered how people create computer programs? Have you ever wanted to conjure up your own video game? Have you ever flipped through a programming book and been discouraged by its dull language and boring examples? If so, there may be a computer programmer lurking inside you, waiting to be unleashed. Welcome to Learn to Program with Small Basic!

Microsoft Small Basic is a free, text-based programming language designed for beginners. It provides a complete programming environment that helps you write, test, and fine-tune your creations. This book shows you how to install Small Basic and how to use it to do amazing things. We’ll show you that programming can be fun, rewarding, and—best of all—easy!

Who Should Read This Book?

You! This book introduces you to Small Basic in a fun, engaging, and interactive way. We offer an abundance of sample programs that you can run, explore, and tweak to make your own. Try every exercise and dig in to the extra online resources, review questions, and practice exercises. By the time you’re done with this book, you’ll be creating your own games!

If you’re feeling inspired, you can share your Small Basic creations on the Small Basic MSDN forum, where the Small Basic Community Council will be waiting to answer any questions and check out all your awesome work.

What’s in This Book?

Each chapter builds on the last one to help you hone your programming skills. We’ll start you with the basics, and by the end, you’ll be a total whiz!

• Chapter 1: Introducing Small Basic explains Small Basic’s features and gets you set up. Then you’ll create your first program.

• Chapter 2: Getting Started walks you through creating simple programs using Small Basic’s built-in text window.

• Chapter 3: Drawing Basics shows you how to write programs that draw shapes in the graphics window.

• Chapter 4: Using Variables explains how variables keep track of information. Variables play a huge role in programming, and you’ll use them throughout the book.

• Chapter 5: Drawing Shapes with Turtle Graphics teaches you how to command your own artistic turtle. You’ll draw intricate geometric shapes and patterns that would be tiresome to do by hand.

• Chapter 6: Getting User Input shows you how to bring your programs to life by making them interactive. You’ll write a program that can greet you by name.

• In Chapter 7: Empowering Programs with Math, you’ll use math to make games, like a dice game that uses a random number generator.

• Chapter 8: Making Decisions with If Statements shows you how to control the logic and flow of your programs. With If statements under your belt, you’ll be able to create even more powerful and exciting programs.

• In Chapter 9: Using Decisions to Make Games, you’ll build on your knowledge of If statements and use them to make complex games.

• In Chapter 10: Solving Problems with Subroutines, you’ll break down your code into simple sections that you use again and again. Then you’ll put all your code together to make a game where you battle a fire-breathing dragon!

• In Chapter 11: Event-Driven Programming, you’ll make interactive programs, such as a simple drawing program, that respond to user input.

• Chapter 12: Building Graphical User Interfaces covers how to create a full application with buttons, labels, and all the bells and whistles of a professional program. You’ll build on your simple drawing program and create buttons that let your user change the pen color.

• Chapter 13: Repeating For Loops will show you how to use For loops in your programs to avoid repeating code. You’ll learn how to automate boring tasks and draw a bunch of pictures in just a few lines of code.

• Chapter 14: Creating Conditional While Loops discusses more advanced conditional programming and ends with making a game of rock-paper-scissors you can play against the computer.

• Chapter 15: Grouping Data in One-Dimensional Arrays introduces arrays and how to store large amounts of data. Storing and manipulating data is another important aspect of programming, and you’ll take advantage of it to program a magic 8 ball.

• Chapter 16: Storing Data with Associative Arrays shows you how to store strings in descriptive arrays. You’ll transform your computer into a poet by writing a program that generates poems all on its own.

• Once you have a handle on arrays, in Chapter 17: Expanding to Higher-Dimension Arrays, you’ll take arrays up to two or more dimensions, which lets you put a lot more data in them. At the end you’ll create your own treasure-hunting game.

• Chapter 18: Advanced Text Magic teaches you how to handle and process text in your programs. Then you’ll use your knowledge to write a simple spell-check program.

• Chapter 19: Receiving File Input and Output helps you build bigger programs by teaching you how to handle files full of data. You’ll then use that knowledge to create a program featuring a math wizard.

Online Resources

Visit http://www.nostarch.com/smallbasic/ to download the extra book resources and to find updates. You’ll find these additional resources and review questions for teachers and students:

Book Programs and Solutions Download the finished programs, all the images you’ll need, some skeleton code for the Programming Challenges, and the solutions to the Programming Challenges and Try It Out exercises. This will save wear and tear on your typing fingers!

Additional Resources These are online articles that relate to the topics covered in this book. Many of these were written just to supplement the book!

Review Questions Test your knowledge (or your student’s knowledge).

Practice Exercises In addition to the Try It Out exercises and the Programming Challenges in the book, you can even find more exercises to practice. This is also great for teachers who want more options for assignments.

A Note to the Reader

When learning a new skill, there’s nothing more important than practice. Reading this book is only the first step. To become a great programmer, you must program! The more of the book’s resources you use, the more you learn. Don’t be afraid to experiment. No matter what buttons you press or what commands you give, you won’t hurt the computer. We promise.

With a little patience and dedication, you’ll soon amaze your friends with the wonderful things you’ll create. We want to empower you to make fun games and even to change the world!