Trapped

by Reggie: Y9 Age: ~14

Introduction

Reggie had the idea of combining a story with elements of game-play so that the user does not know what to expect next. Further instalments are planned and you will be able to follow the unfolding story here.

The program compiled with Free Pascal on the Raspberry Pi using the Lazarus IDE. We took this screenshot showing typical dialogue using the scrot utility on the Pi.

Trapped running on the Pi

Trapped running on the Pi

The Code

program Trapped;
{
    Copyright (c) 2013 Reggie

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/ }

{$mode objfpc}{$H+}

uses
  crt,  SysUtils;
const
  MaxX = 80;
  MaxY = 25;
var
  response, Name : string;
  c : char;
  pX, pY, dX, dY, The_Internet, Dead  : integer;

procedure fail;
begin
  textbackground(black);
  clrscr;
  gotoxy(20, 7);
  writeln('Game Over. Hard luck!');
  sleep(7000);
  halt;
end;

begin
  pX := 10;
  pY := 10;
  dX := 40;
  dY := 20;
  The_Internet := 42;
  Dead := 1337;

  writeln('You have woken up in a military facility.');
  writeln('What do you do, sleep or scream?');
  Readln(response);

  if (response = 'sleep') or (response = 'Sleep') then
    begin
      writeln('Zzzzz');
      sleep(5000);
      fail;
      sleep(7000);
    end
  else if (response = 'scream') or (response = 'Scream') then
    begin
      writeln('AHHHHH!');
      readln;
      writeln('Welcome, test subject 256!');
      readln;
      writeln('You do not know where you are, or who you once were.');
      writeln('We have erased all previous memory, bar the ability to move.');
      writeln('Try it, move around with wasd');
      readln;
      textbackground(Black);
      textColor(White);
      clrscr;
      cursoroff;
      repeat
        if keypressed = True then
          begin
            c := readkey;
            case c of
              'a' : Dec(pX);
              'd' : Inc(pX);      //This code executes a check for if you press a key.
              'w' : Dec(pY);      //If 'wasd' is pressed, then  move the floaty per-cent-person.
              's' : Inc(pY);
              #27 : halt;
            end;
          end;
        if pX < 1 then
          pX := MaxX;
        if pY < 1 then
          pY := MaxY;
        //This code <-- makes the character appear on the other side of the screen if he is off it.
        if pX > MaxX then
          pX := 1;
        if pY > MaxY then
          pY := 1;
        clrscr;
        gotoxy(pX, pY);
        Write('%');
        gotoxy(dX, dY);
        Write('@');
        sleep(25);
        if (pX = dX) and (pY = dY) then
          begin
            clrscr;
            writeln('Well, you succeeded in this task.');
            writeln('But that is not all we have to ask of you.');
            break;  //PPS Why?
            readln;
          end;
      until The_Internet = Dead;

      readln;
      textbackground(red);
      clrscr;
      writeln('<????> You, right there, wake up!');
      readln;
      writeln('*You awake, and stare through blurry eyes.');
      writeln('*You see a man in a kilt in front, do you A: Ask who he is, or B: scream?');
      readln(response);
      if (response = 'A') or (response = 'a') then
        begin
          writeln('<????> My name is Belethor. No surname.');
          sleep(700);
          writeln('<Belethor> I''m effectively your master now.');
          writeln('<Belethor> Don''t try running either.');
          writeln('<Belethor> I have you strapped to the table. With my mind.');
          readln;
        end;
      if (response = 'b') or (response = 'B') then
        begin
          writeln('<????> Quiet, you wuss.');
          writeln('<????> You''re clearly not cut out for this.');
          writeln('<????> Goodbye. Man up and come back.');
          sleep(3000);
          fail;
        end;
      sleep(2000);
      writeln('<Belethor> Do you think you are ready?');
      writeln('<Belethor> Well you aren''t. There is much to learn.');
      writeln('<Belethor> Are you ready for TRAINING?');
      readln(response);
      if ((CompareText(response, 'AYE')) = 0) or ((comparetext(response, 'YES')) = 0) then  //PPS: One must be 0
        begin
          writeln('<Belethor> Well OK then. I shall begin when you are ready.');
          writeln('<Belethor> Type OK or ok when ready. Whatever that means.');
          readln(response);
          if (response = 'OK') or (response = 'ok') then
            begin
              textbackground(blue);
              clrscr;
              sleep(3000);
              gotoxy(0, 15);
              writeln('<Belethor> Look, a sword! Type ''pick'' to pick it up!');
              repeat
                readln(response);
              until response = 'pick';
              if response = 'pick' then
                begin
                  writeln('SWORD GRABBED!');
                  writeln('Nothing happened! Uses: None!');
                  sleep(1000);
                  writeln('<Belethor> That sword is utterly useless, due to no combat functions as of yet.');
                  writeln('<Belethor> Fun, eh?');
                  readln;
                end;
              writeln('<Belethor> Would you like me to explain it?');
              sleep(700);
              writeln('<Belethor> Well, I''ll tell you anyway.');
              writeln('<Belethor> It can be picked up, and then not used!');
              writeln('<BELETHOR: SHOUTING> DO YOU GET IT!?');
              writeln('<BELETHOR: SHOUTING> IT IS USELESS.');
              readln;
              writeln('*You now renickname him');
              writeln('*Choose your name for him:');
              readln(Name);
              sleep(700);
              writeln('*Successful naming. His name is now: ' + Name);
              Write('<');
              Write(Name);
              Write('> Well, are you ready to move on?');
              readln(response);
              writeln(response, '? Well let''s move on then!');
              sleep(3000);
            end;
          begin
            textbackground(black);
            clrscr;
            gotoxy(30, 12);
            writeln('Chapter 2...');
            writeln('Back to the left of the screen.');
            writeln('You picked a sword up, named a guy ' + Name +
              ', and even made an attempt at humour in Chapter 1.');
            sleep(5000);
          end;
          clrscr;
          writeln('<' + Name + '> So, we''re in Ch. 2 now.');
          writeln('<' + Name + '> Any questions before we move on?');
          readln(response);
          writeln('<' + Name + '> So, you want to ask ' + response + '?');
          writeln('<' + Name + '> WELL TOOOOOOUGH LUCK!');
          sleep(5000);
          writeln('<' + Name + '> So, where to? You have two options.');
          writeln('<' + Name + '> A or B, or a or b.');
          repeat
            readln(response);
          until (response = 'a') or (response = 'b') or (response = 'A') or (response = 'B');

          writeln('<' + Name + '> WELL! YOU CHOSE ' + response + '? That was silly.');
          readln;
          writeln('<' + Name + '> Well we are going to the Sion.');
          readln;

          //savehub world!
          clrscr;
          sleep(5000);
          writeln('<' + Name +
            '> Welcome to the Sion. Our save point. From here, you can enter a code to go back to the point you want to be at.');
          writeln('It''s a decent way to play.');
          readln;

          writeln('Have you got a code?'); //Note, no codes are implemented as of yet.
          readln(response);
          if response = 'yes' then
            begin
              writeln('Oh? Enter it below!');
              readln(response);
            end
          else
            writeln('Well let us move on then.');
          writeln('Where to?');
          readln(response);
          writeln('So you want to go to ' + response + '?');
          writeln('That''s a decent choice.');
          writeln('Let''s go then!');
          sleep(3000);
          clrscr;
          writeln('Let''s go then!');
          sleep(2000);
          clrscr;
          writeln('Let''s...');
          sleep(1000);
          clrscr;
          //Update coming soon...ish.
        end;
    end;
end.

Programming - a skill for life!

Student programs to inspire you!