Program Adventure Games with the BIFF Framework

As a passionate adventure game player and programmer, from the 1980s onwards, I’ve decided that the time has come to help other programmers embark on the noble quest of developing retro-style adventure games. I’ve already taught a course and written a book (available on Amazon US, Amazon UK and worldwide) on writing adventure games in C#. But if you’ve never written a game before you might still find it hard to implement all the features needed. Wouldn’t it be great if someone had already written a library of classes that encapsulated all the essential behaviour needed for a game – a parser to interpret text commands, Rooms to create a map, Treasures to create objects, actions to let the player look at objects, take, and drop them or put one object inside another one?

Welcome to BIFF!

BIFF is short for The Bitwise Interactive Fiction Framework. I’ve spent much of the last year writing this framework in Java and now I’m starting work on translating it into C#. The Java version of BIFF is currently more complete – it can handle reasonably complicated commands such as “Put the small golden egg into the big carved wooden box” or “Unlock the treasure chest with the magic brass key”. I will make BIFF for Java freely available later in the year.

Since many people have already read my C’# book or followed my course, I decided that, rather than wait until the C# release of BIFF has all the features in the Java version, I would release BIFF for C# in incremental stages so that existing readers and students can carry on developing their games using the new features. This necessarily means that the early releases will always be substantially incomplete. However, if you want to deepen your understanding of game programming, this is a great opportunity for you to try to modify the latest release by adding on additional features. You are free to modify BIFF as required as long as you leave my copyright notice in the comments of the source code.

To download the code of my C# adventure game book (whether or not you’ve actually bought it!) as well as the current release of BIFF for C#, just sign up to our mailing list at www.bitwisebooks.com. Meanwhile, here is a short introduction to BIFF…

The Little Book Of Adventure Game Programming

Our newest book is The Little Book Of Adventure Game Programming. This provides a step-by-step guide to creating a retro text adventure game in C#, which is one of the most important languages on Windows and is also available on macOS and Linux. The programming principles and techniques explained in the book can also be used to write adventure games in other languages such as Java, Ruby or Object Pascal. Short examples (source code also available for download) are provided in those languages. As well as teaching adventure games specifically, this book can also be used as a tutorial to writing C# programs. It covers all the most important features of the C# language.

This book explains…

  • How to write Interactive Fiction (IF) games
  • Creating class hierarchies
  • How to create a map of linked ‘rooms’
  • Moving the player around the map
  • Adding treasures to rooms
  • How to take and drop treasures
  • Putting objects into containers (sacks, treasure chests etc.)
  • Using lists and dictionaries
  • Overridden methods
  • Overloaded methods
  • How to save and load games
  • Designing a game with a user interface
  • Designing a command-line game to run at the system prompt
    …and much more

Available in paperback or for Kindle from Amazon (US): https://www.amazon.com/dp/1913132080 and (UK): https://www.amazon.co.uk/dp/1913132080

Visual Studio 2019 – Using its Strange New Project Dialog

I have no idea why Microsoft decided to change the New Project dialog in Visual Studio 2019. The old New Project dialog worked just fine. I’m not aware of huge numbers of people requesting any changes. If you read the comments here, you’ll see that the change has not been universally welcomed: https://devblogs.microsoft.com/visualstudio/redesigning-the-new-project-dialog/

As far as I can seem the new version is far inferior to the old version. Put simply, it’s an unstructured, sprawling mess. Even so, I suppose we are going to have to learn to live with it (unless Microsoft sees the error of its ways and gives us back the old New Project dialog). So, here’s a quick guide to using it…

Create a New Project At Startup

If you want to create a new project as soon as you start Visual Studio 2019…
• Start Visual Studio.
• In the Startup screen, select Create A New Project

 

If you don’t want to create a new project at this stage, you can click ‘Continue without code’. You can start a new project later on as explained below.

Create a New C# Project From Within VS 2019

If you are programming C#: To start a new project from within Visual Studio…
• Select File, New, Project
• From the Language dropdown list, select C#
• From the Platform dropdown list, select Windows
• From the Project Type dropdown list, select Desktop
• From the project list select Windows Forms App
• Click Next
• Name the project, and browse to a location on disk
• Click Create

Create a New C Project From Within VS 2019

If you are programming C: To start a new project from within Visual Studio…
• Select File, New, Project
• From the Language dropdown list, select C++
• From the Platform dropdown list, select Windows
• From the Project Type dropdown list, select Empty Project.
• Click Next
• Name the project, and browse to a location on disk
• Click Create
Visual Studio now creates a new project with separate folders for Header Files, Resource Files and Source Files.

• Right-click the Source Files folder.
• From the popup menu, select Add | New Item
• Select Code | C++ (.cpp) file.
• In the Name field, change the file name to: main.c
• Click Add.

Edit the contents of this source file to the following:

#include <stdio.h>

int main(){
  printf("Hello world\n");
  return 0;
}

Shortcut Project Creation

There is a slightly faster way to cut through the mess of this horrible new dialog. You can select a project type more quickly by using the search box on the Create New Project dialog. For example, with a C# Windows Forms project, you could search for Winforms. For a C project, you could search for C++:

Once you’ve created a new project, the procedures for adding and editing files, compiling and debugging are the same in Visual 2019 as in other versions of Visual Studio.

C Pointers Explained in 3 Minutes

You can’t get away from pointers in C. Programmers familiar with other languages in which you never (or very rarely) see pointers (for example, Java, C#, Ruby or Python) often find pointers one of the hardest parts of learning C. Here is a very short video that explains the fundamentals of pointers in just three minutes!

Of course, there is much more to pointers than I’ve been able to cover in this video. If you really need to master pointers, take a look at my book, The Little Book Of Pointers.

Recursion For Programmers

Recursion is a powerful – in fact, an essential – technique that all programmers need to be comfortable using. But initially it can be hard to grasp. How can a function call itself? What happens when the values of variables change from one recursive function call to another. And what the heck are ‘stack frames’ and why do you need to know about them? This short video gives you an overview of a recursive function and how it works.

I’ll post some more information on recursion in my next blog post. If you need an in-depth guide to recursion, debugging recursion, recursing tree structures, disk directories and more, you may want to take a look at my book, The Little Book Of Recursion. Or, if you prefer a more interactive guide to recursion, see my online video course.

Add C File Templates in Visual Studio

In my last post I explained how to start a C Project in Visual Studio. But you now have the problem of adding C code files, instead of the default C++ files. This video explains how to simplify this by create C file programming templates so that you can just click an icon to create a file.c, a main.c or other types of code file.

Compile C Projects in Microsoft Visual Studio

Yes, it can be done! For some reason, Microsoft doesn’t have an option to create a C project in Visual Studio. When you select File/New Project, it lets you start a C++ project but not a C one. But don’t be fooled. Visual Studio is a great IDE for creating, compiling and debugging C. If you want to know how to get started, just watch this short video…

Incidentally, one comment beneath this video on YouTube mentions that it may be necessary to set the project properties specifically to C. This will, I think, only be required if you have applied a global setting to default to C++. I’ve certainly never had to go through this additional step. However, just in case you encounter this problem, all you have to do to fix it is right-click the project node in the Solution Explorer and select Properties from the popup menu. Find the entry for C/C++ in the left-hand pane. Select the Advanced heading. Then make sure that the Compile As property is set either to Default or to Compile As C Code.