Writing a #javascript game 3

So, I have been making slow but steady progress with my Javascript text adventure game.  So far I have implemented quests which can be started at the village.  Each quest is a series of challenges which I have encoded in a json file.  Each challenge script requires the player to pick from a list of statistics in Top Trumps style in an attempt to defeat the challenge.  Failure to beat the challenge results in pain, damage, death or failure of the quest.  Completing a challenge will result in experience points that can be used to increase your stats (not yet implemented).  Completing quests will result in more things becoming unlocked in the village (starting with the village healer and the tavern).  I have also implemented a json file containing a variety of artefacts that can be discovered and used by the player.  Some artefacts are 'static' in that they always apply one or more bonus or penalty to the player's stats.  Non static objects can be activated.  Last night I implemented weapons (the player can only have one weapon at a time) and armour (which can only be worn when the player is not currently engaged in a quest).

I have decided to use Sweet Alert for all the message boxes in the game.  This is because Sweet Alert is really, well, sweet, and also because it is very easy to use.  Below is an image of a Sweet Alert message box in action.

An example of a sweet alert message.
SweetAlert was created by Tristan Edwards, you can follow him on Twitter or Dribbble for updates and other cool projects!

See you next time for more Have Spell Will Travel updates.

Writing a #javascript game 2

Today I started writing the game data, starting with the stats that describe the player.  In the game of Have Spell Will Travel you take the role of a fantasy character questing through various challenges.  Anyone who played the Unofficial Talisman Game might know what I'm doing here.  Each player is a list of statistics that they use to defeat challenges.  The player chooses a race and a profession.  This combination determines their overall statistics.

Today I wrote some scripts for choosing a combination of race and profession and then providing a character sheet that can be opened and closed with some JavaScript, as in the images below.

Choosing one of the different races.  More coming soon.

Today I have been creating these collapsible stats boxes.  

Writing a #javascript game 1



So, with a little time on my hands and a desire to learn some more Javascript I've been working on a new game.  "Have Spell Will Travel" is a  browser game set in a fantasy Dungeons and Dragons meets Top Trumps/Talisman-esque world.  I will avoid writing too much about the game play for now until there is something to actually play.

My first step was to define the various css box-model elements and make sure they work across all platforms.  Next step was to define some nice styles for the background images, and dialogue boxes.  I have chosen to use styled paragraphs with onclick=() methods rather than hyperlinks for navigation.

The page can be broken down into a heading box, (an initially hidden) status box, and a dialogue box that contains the navigation.

I am rather pleased with the progress so far.  More posts soon...


If there was a programming language for Yorkshire



Being a typical Yorkshire lad, I do often struggle with the strict syntax of most modern scripting languages.  The solution is 'Ayup' - a programming language for Yorkshire folk.  It is powerful enough to quickly parse web pages when you are half way up to your neck in mud; need to run a regular expression when lost on Ilkley moor, and is easy enough to write even when you are steaming from an afternoon in the Dog and Ferret in Harrogate.

Starting a script in Ayup requires the shebang line:

#!/usr/bin/ayup

This provides a path to your Ayup interpretter.

Writing 'Hello World' to the terminal is as simple as:

#!/usr/bin/ayup
wri'aht("Ay up, World!")

It is useful to use a pragma to eliminate unsafe constructs in the dialect.  The following code demonstrates this.

#!/usr/bin/ayup
use none o' thy nonsense
wri'aht("Ay up, World!")
cop aye

All scripts in Ayup return 'aye' (true).

Iteration.

Iteration can be performed in a number of ways.  Consider the following code fragments.

Displaying all the elements of a list:

#!/usr/bin/ayup
use none o' thy nonsense
fer apiece o'these i' t' (ham):
wri'aht( thi' )
cop aye


Obtaining an iterator from an iterable list:

#!/usr/bin/ayup
use none o' thy nonsense
fer peas in (ham):
wri'aht( peas )
cop aye


Repeating until a condition is met:

#!/usr/bin/ayup
use none o' thy nonsense
repea':
#do something useful
keep buggerin' on until (<condition>)
cop aye

Selection

Boolean statements always evaluate as either 'Aye' or 'Nay' in Yorkshire.  Consider:


is (foo > nowt):
aye:
wri'aht("champion")
nay:
wri'aht("eeh by gum")
cop aye


Breaking out of a loop.  You can break out of any iteration simply with the pack it in statement.
Consider:

#!/usr/bin/ayup
use none o' thy nonsense
fer apiece o'these i' t' (ham):
wri'aht( thi' )
is (thi' is "peas"):
aye:
pack it in
cop aye


User defined functions

Functions are defined using the keyword mek.  Note the use of exception handling in this example.

#!/usr/bin/ayup
use none o' thy nonsense
fram maths impoart random

mek addition( thi' ) wang ValueErrorException:
a = thi' plus t'random.randa(1)
cop a

wri'aht( addition(5) )
aye

That's all for today.  Join us next time when we will look at object-oriented Yorkshire, and global (you're not from round here) variables.

Label