Hartnell: Code Snippits
Blind Archer Translation
// Blind Archer // A classic BASIC-style text-based guessing gmae extravaganza! // by Shawn Hartnell // You have full permission to use and abuse this code // It likes to be spanked #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() { int random_number; int i; // Set the random seed srand((unsigned)time(0)); // declare variables // player string a; // player text answer int x; // player left/right aim int y; // player up/down aim // goblinhawk int gh_x; // goblinhawk left/right location int gh_y; // goblinhawk up / down location int rnd_move_gh; // determins the random movement of goblinhawk // time limit int seconds; // seconds left to shoot the goblinhawk // intro // shown once at beginning of game cout << " BLIND ARCHER" << endl << endl; cout << " You are the great elven archer Dritmatz and you have been blinded during" << endl; cout << " an earlier attack by a goblin riding a goblinhawk. Your friend, Jasmund," << endl; cout << " had his hands mangled in the same attack. Now, the goblinhawk is speeding" << endl; cout << " towards your location. You have 10 seconds to shoot down the goblinhawk" << endl; cout << " before it finishes you off." << endl << endl; cout << " Would you like instructions? ( y / n ) " ; endl; cout << " > "; cin >> a } /* dim ghx as integer 'goblinhawk left/right location dim ghy as integer 'goblinhawk up/down location dim rndMoveGh as integer 'determines the random movement of goblinhawk dim seconds as integer 'seconds left to shoot the goblinhawk 'intro 'shown once at beginning of game print "Blind Archer" print print "You are the great elven archer Dritmatz and you have been blinded during" print "an earlier attack by a goblin riding a goblinhawk. Your friend, Jasmund," print "had his hands mangled in the same attack. Now, the goblinhawk is speeding" print "towards your location. You have 10 seconds to shoot down the goblinhawk" print "before it finishes you off." print print "Would you like instructions? (y/n)" print input "> ",a if a = "y" or a = "Y" then gosub instructions init: 'here the initial values of the important variables are set 'the player starts out with 10 seconds seconds = 10 'place the goblinhawk on a random place on the 10x10 grid ghx = int(rnd(1)*10)+1 ghy = int(rnd(1)*10)+1 main: 'each game loop begins here 'nudge the goblinhawk one unit in a random direction rndMoveGh = int(rnd(1)*4)+1 if rndMoveGh = 1 then ghx = ghx - 1 if rndMoveGh = 2 then ghx = ghx + 1 if rndMoveGh = 3 then ghy = ghy - 1 if rndMoveGh = 4 then ghy = ghy + 1 'the grid is a 10x10 grid numbered 1 to 10. If the goblinhawk is moved outside 'this range, move it back in if ghx < 1 then ghx = 1 if ghx > 10 then ghx = 10 if ghy < 1 then ghy = 1 if ghy > 10 then ghy = 10 'handle player input print sleep 1000 print "You have";seconds;" seconds left." print sleep 1000 print "Aim up/down :" print " 1 is all the way up." print " 10 is all the way down." print input "> ",y print print "Aim left/right :" print " 1 is all the way to the left." print " 10 is all the way to the right." print input "> ",x sleep 1000 'easter egg. If the player aims left/right 20 and up/down 1 then he hits 'and kills Jasmund. if x = 20 and y = 1 then goto jasmundHit 'if player aims lower than 1 or higher than 10, he wastes and arrow if x < 1 or x > 10 or y < 1 or y > 10 then gosub wasteArrow 'check for hit. if there is a hit, the player wins the game. if x = ghx and y = ghy then goto winGame 'decrease time by 1 seconds = seconds - 1 'check to see if time is up if seconds = 0 then goto loseGame 'Jasmund gives his report cls print "Jasmund says: It's farther"; if y > ghy then print " up"; if y < ghy then print " down"; if y <> ghy and x = ghx then print "." if y <> ghy and x <> ghx then print " and to the"; if x > ghx then print " left." if x < ghx then print " right." if seconds > 0 then goto main instructions: print print "You have the bow, Jasmund has the eyes. Each turn you will aim and fire" print "your bow. After each shot, Jasmund will tell you how to adjust your aim." print print "(press any key)" sleep return wasteArrow: print print "You shot is completely off and you waste an arrow. Try aiming between" print "1 and 10." return winGame: print print "Your arrow hits the goblinhawk in the heart. Its goblin rider looks" print "confused for a second and then realizes it is doomed. Both goblinhawk" print "and rider crash to the ground." goto playAgain end loseGame: print print "The goblinhawk reaches you and Jasmund. You hear a quick snap and a" print "sickening crunch. Then, you hear nothing..." goto playAgain sleep jasmundHit: print print "You hear a familar voice grunt as you hear your arrow thud into someting" print "solid. After a few moments of silence, you realize that you have just" print "killed Jasmund. You can do nothing now but wait to die." goto playAgain playAgain: print sleep 1000 print "Would you like to play again? (y/n)" print input "> ",a if a = "y" or a = "Y" then goto init end */
page_revision: 1, last_edited: 1245688489|%e %b %Y, %H:%M %Z (%O ago)