Up to Main Index Up to Journal for March, 2018 JOURNAL FOR SATURDAY 17TH MARCH, 2018 ______________________________________________________________________________ SUBJECT: Welcome to the cottage DATE: Sat 17 Mar 17:08:07 GMT 2018 Having received the emails, I know people like to use WolfMUD for learning, and sometimes for teaching. I also receive email asking how to start on such a project from scratch. This is true for the Go version, the previous Java version and all of the other versions of WolfMUD I’ve written over the years. I personally believe that MUDs — and single player text adventure games — are a great way to teach, learn and have fun while doing so. However, I also know that WolfMUD can be a daunting project to pick up and delve into. I would therefore like to present ‘The cottage’. A very simple, single player, ‘toy’ adventure game. It doesn’t do much, as this is intended as a starting point only, but there is a lot of potential. You can walk around 12 locations in and around a small cottage using the commands NORTH, EAST, SOUTH, WEST — or the shorter N, E, S and W. Locations can be redisplayed using the LOOK or L command. You can SNEEZE. You can also QUIT the game. I’ve given the code a very permissive “do what you want with it” Free Public License. This means you can take my code and make it yours — no strings attached. Typically, when rewriting WolfMUD from scratch — in any programming language, the cottage is what I would use as a starting point. I would then start adding the loading of data files, networking, multiplayer support, inventories and items, more commands, mobiles (non-player characters and creatures), skills, combat and other features. The order in which I add new functionality varies, depending mostly on what area I feel like working on. The cottage is about 225 lines of code, comments and notes. Another roughly 140 lines of code make up the location data. The location descriptions have been deliberately kept rather terse to keep the size of the code down. The code itself has been kept in a single, self contained file, no zip files or other archives to unpack. There is just a single file so that you can get started with a minimum of minimum of fuss. To get started: - Download and install Go from https://golang.org (probably the hardest bit) or install it using your package manager if your system has one. - Right-click this link and save the source code locally: cottage.go Windows users may find this version of the source code easier to work with, it has DOS line endings and works with Notepad: win/cottage.go (If you want to browse the code just left-click either link) - Open a command or terminal window and change to the directory/folder where the file cottage.go was saved. - In the command/terminal window run the code by typing: go run cottage.go This should display a greeting and the starting location: Welcome to the cottage! [Path outside a cottage] You are on a path leading north to a small, white cottage. You can see exits: north south west ? At the ‘?’ prompt type a command such as N, S, E, W, L or QUIT. You can edit cottage.go with a text editor, save your changes and run the results using ‘go run cottage.go’ again. Repeat as often as you like :) What is the point of the cottage and where is the potential? For teaching/learning it’s a very simple development environment[1]. All that is needed is Go and a simple text editor whether you are using Windows, MacOS or Linux (Raspberry Pi!). Children love it. The first thing they want to do is change things, add their own locations, recreate their home or their school — I’ve seen both. You don’t need to know any programming to play and have fun. Children, by looking at the loadWorld method, will see the pattern in the code for each location and will jump in to change locations and add their own with very little prompting, ignoring all of the code initially. The cottage code introduces a number of programming features, only some of which are specific to Go: - Constants (and iota) - Data types and variables - Embedded fields - Maps, indexing and checking for indexes - Pointers - If statements - Switch statements - Loops - Input/Output (Reader/Writer) - Functions - Methods One omission is that it does not use any slices. With the code being all in a single file there are also no exported methods, functions or types except those used from the standard library. Some people may look at the code and think “ugh!”. That’s okay, show me how you would do it — the cottage is certainly not perfect. If you can see mistakes or better ways to do something then that’s good. The cottage is merely a starting point for your own ideas. The real potential here are is in the things that are missing and can be added or improved upon. Some examples, in no particular order: - Add more exit directions such as UP and DOWN or NE,SE,SW,NE. - Add new action commands based on SNEEZE. - Add multiple starting locations and pick one at random to start from. - Add a function to format the list of exits, e.g. ‘north, east and west.’ - Add a function/method to wrap/fold long line of text for output. - Update locations to use *location for exits. - Rewrite loadWorld so locations can be added in a more friendly way. - Add error checking when adding locations and exits and warn if references are not unique or exits go to an invalid reference. - Rewrite loadWorld function to read the data from a file or database. - Rewrite newPlayer function and msg method so input/output is over the network. - Process commands with more than one word. - Add colors to the output. - Add narrative items so that a player can examine their environment. - Add items that a player can GET, DROP and EXAMINE. - Refactor the code into packages. Due to the way the cottage has been written, most of the above focuses on changing and expanding specific functions or methods — bite sized pieces. This allows the code to slowly grow and develop as you, the programmer, grow and develop. The list is far from complete, indeed I could write may more journal entries on how to improve and expand the cottage until it becomes a fully fledged game. Depending on the level of interest I may write more about the cottage, maybe even have a dedicated area for it on the site somewhere. For anyone who wants to play with the cottage, I’m more than willing to answer questions, give advice or explain the code and ideas behind it. I’m always eager to help others code. Just drop me an email to have a friendly chat: diddymus@wolfmud.org Whether you look at the cottage, WolfMUD or work on your own code, remember to have fun. Programming should be enjoyable, not a chore. The cottage: cottage.go or: win/cottage.go -- Diddymus [1] Keeping programming simple and accessible is something that has been lost. Gone are the days of turning on a BBC Micro, Spectrum or other home computer and being placed at a prompt where you could start programming and having fun immediately. Up to Main Index Up to Journal for March, 2018