Hi all! I created an account primarily for this question, but I hope to be able to contribute to this community in the future.
I’ve been working on trying to figure a gun into my work, so I can have some tension with an enemy character (working on that). I’ve got the gun created and workable, roughly. I’m going to present a rough code sequence that is intended to showcase the gun. This has come about thanks to some searching on this very forum and some finagling of my own.
[code]“Shooting Range” by Anubis
Testing Room is a room. “This is the room Anubis has made to test out his awesome gun functionality.”
The target is scenery in the testing room. “This is a target painted on the wall. Don’t worry, the wall can take your shots.”
A gun is a kind of thing. A gun can be loaded, half-loaded, or unloaded.
Definition: A thing is ungunlike if it is not a gun.
Understand “shoot [gun] at [something ungunlike]” as shooting it with. Understand “shoot [something] with [something]” as shooting it with.
Understand “shoot [something] at [something]” as shooting it with (with nouns reversed). Understand “fire [gun] at [something ungunlike]” as shooting it with (with nouns reversed). Understand “fire at [something ungunlike] with [gun]” as shooting it with. Understand “fire at [something] with [something]” as shooting it with.
Shooting it with is an action applying to two things.
Check shooting something with something:
if the player is not carrying a gun, say “Shoot? With what gun?” instead;
if the noun is the player, say “That would be a spectacularly horrible idea.[if pistol is unloaded] Besides, the pistol’s empty.[end if]” instead;
if the second noun is not a gun, say “Try a gun, you dope.” instead.
Carry out shooting the target with the pistol:
if the pistol is loaded:
now the pistol is half-loaded;
say “BANG! Bulls-eye!”;
reject the player’s command;
if the pistol is half-loaded:
now the pistol is unloaded;
say “BANG! Bulls-eye!”;
reject the player’s command;
if the pistol is unloaded:
say “It’s out of ammo!”;
reject the player’s command.
The pistol is in the testing room. The pistol is a gun. The pistol is loaded. The description of the pistol is “It’s a compact two-barrelled pistol, meant to fit in one’s pocket for emergencies. [if the pistol is loaded]Both barrels are loaded[otherwise if the pistol is half-loaded]One barrel is fired, and one is still loaded[otherwise if the pistol is unloaded]Both barrels are fired and empty[end if].”
[/code]
You can play the above code here to see how it works: http://parchment.googlecode.com/svn/trunk/parchment.html?story=https%3A//dl.dropboxusercontent.com/u/38920383/Shooting%2520Range.zblorb
So far, so good? I’d say so. My problem is this: I feel like I’ve built up code on code, and I’m not sure how to streamline it. I’d like to make the individual “loaded/half-loaded/unloaded” checking be something that happens every time someone tries to use the pistol, regardless of what one is shooting at. Any ideas?