Hi all!
I am currently working on a text-adventure for Lazarus. I have a class called "Room" in a seperate unit, where I declare that each room has 6 possible Connections (North, East, South, West, Up, Down). In my main unit I have specified what rooms lay in that direction. However, I want to make sure that the game is somewhat interesting and replayable, so that is not enough. What I want is that, on button-click, randomly selected entrances close off and you can't go through them anymore.
I have tried to make two declarations : one where the exits are absolute/real (the ones that never change) and then in addition to that the ones that DO change (based off the real ones, but some of the Connections have been turned into nil values.
Any help is much appreciated
P.S. I have also put the names of all the rooms of which I want to randomize their descriptions into an array, as I though I could do a loop with that but it din't work.
My Code:
Main unit: unit uAction;
{$mode objfpc}{$H+}
interface
uses
uRoom, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, LCLType,Dialogs,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Edit1: TEdit;
Memo1: TMemo;
Memo2: TMemo;
procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
Intro, Tutorial,
Start,
L0R1, L0R2, L0R3, L0R4, L0R5, L0R6, L0R7,
L1R1, L1R2, L1R3, L1R4, L1R5, L1R6, L1R7,
L2R1, L2R2, L2R3, L2R4, L2R5,
L3R1, L3R2, L3R3, L3R4, L3R5, L3R6,
L4R1, L4R2, L4R3, L4R4, L4R5,
L5R1, L5R2, L5R3, L5R4, L5R5, L5R6, L5R7, L5R8,
L6R1, L6R2, L6R3, L6R4,
Treasure : Room; //Alle Räume (L = Level; R: Room) Start&Treasure sind Spezialräume
CurrentRoom : Room;
ConnectionRandomizer1, ConnectionRandomizer2,
ConnectionRandomizer3, ConnectionRandomizer4,
LadderRandomizer1, LadderRandomizer2,
TrapdoorRandomizer,
TypeRandomizer, DescriptionRandomizer : integer;
i : integer = 1;
r, c : integer;
RoomArray: array [1..60] of string;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Intro := Room.create; Tutorial := Room.create;
Start := Room.create;
L0R1 := Room.create; L0R2 := Room.create; L0R3 := Room.create; L0R4 := Room.create; L0R5 := Room.create; L0R6 := Room.create; L0R7 := Room.create;
L1R1 := Room.create; L1R2 := Room.create; L1R3 := Room.create; L1R4 := Room.create; L1R5 := Room.create; L1R6 := Room.create; L1R7 := Room.create;
L2R1 := Room.create; L2R2 := Room.create; L2R3 := Room.create; L2R4 := Room.create; L2R5 := Room.create;
L3R1 := Room.create; L3R2 := Room.create; L3R3 := Room.create; L3R4 := Room.create; L3R5 := Room.create; L3R6 := Room.create;
L4R1 := Room.create; L4R2 := Room.create; L4R3 := Room.create; L4R4 := Room.create; L4R5 := Room.create;
L5R1 := Room.create; L5R2 := Room.create; L5R3 := Room.create; L5R4 := Room.create; L5R5 := Room.create; L5R6 := Room.create; L5R7 := Room.create; L5R8 := Room.create;
L6R1 := Room.create; L6R2 := Room.create; L6R3 := Room.create; L6R4 := Room.create;
Treasure := Room.create;
Memo1.clear;
RoomArray
:= 'L0R1'; i := i + 1; //1
RoomArray := 'L0R2'; i := i + 1; //2
RoomArray := 'L0R3'; i := i + 1; //3
RoomArray := 'L0R4'; i := i + 1; //4
RoomArray := 'L0R5'; i := i + 1; //5
RoomArray := 'L0R6'; i := i + 1; //6
RoomArray := 'L0R7'; i := i + 1; //7
RoomArray := 'L1R1'; i := i + 1; //8
RoomArray := 'L1R2'; i := i + 1; //9
RoomArray := 'L1R2'; i := i + 1; //10
RoomArray := 'L1R3'; i := i + 1; //11
RoomArray := 'L1R4'; i := i + 1; //12
RoomArray := 'L1R5'; i := i + 1; //13
RoomArray := 'L1R6'; i := i + 1; //14
RoomArray := 'L1R7'; i := i + 1; //15
RoomArray := 'L2R1'; i := i + 1; //16
RoomArray := 'L2R2'; i := i + 1; //17
RoomArray := 'L2R3'; i := i + 1; //18
RoomArray := 'L2R4'; i := i + 1; //19
RoomArray := 'L2R5'; i := i + 1; //20
RoomArray := 'L3R1'; i := i + 1; //21
RoomArray := 'L3R2'; i := i + 1; //22
RoomArray := 'L3R3'; i := i + 1; //23
RoomArray := 'L3R4'; i := i + 1; //24
RoomArray := 'L3R5'; i := i + 1; //25
RoomArray := 'L3R6'; i := i + 1; //26
RoomArray := 'L4R1'; i := i + 1; //27
RoomArray := 'L4R2'; i := i + 1; //28
RoomArray := 'L4R3'; i := i + 1; //29
RoomArray := 'L4R4'; i := i + 1; //30
RoomArray := 'L4R5'; i := i + 1; //31
RoomArray := 'L5R1'; i := i + 1; //32
RoomArray := 'L5R2'; i := i + 1; //33
RoomArray := 'L5R3'; i := i + 1; //34
RoomArray := 'L5R4'; i := i + 1; //35
RoomArray := 'L5R5'; i := i + 1; //36
RoomArray := 'L5R6'; i := i + 1; //37
RoomArray := 'L5R7'; i := i + 1; //38
RoomArray := 'L5R8'; i := i + 1; //39
RoomArray := 'L6R1'; i := i + 1; //40
RoomArray := 'L6R2'; i := i + 1; //41
RoomArray := 'L6R3'; i := i + 1; //42
RoomArray := 'L6R4'; i := i + 1; //43
//static Infos: NR ER SR WR UR DR Depth
Start.Real (L0R6, nil, nil, nil, nil, nil); Start.Depth :=0;
L0R1.Real (nil, L0R2, L0R5, nil, nil, L1R1); L0R1.Depth :=0;
L0R2.Real (nil, L0R3, L0R6, L0R1, nil, nil); L0R2.Depth :=0;
L0R3.Real (nil, nil, L0R4, L0R2, nil, L1R2); L0R3.Depth :=0;
L0R4.Real (L0R3, nil, L0R7, nil, nil, L1R5); L0R4.Depth :=0;
L0R5.Real (L0R1, L0R6, nil, nil, nil, L1R3); L0R5.Depth :=0;
L0R6.Real (L0R2, L0R7, Start, L0R5, nil, L1R6); L0R6.Depth :=0;
L0R7.Real (L0R4, nil, nil, L0R6, nil, L1R7); L0R7.Depth :=0;
L1R1.Real (nil, nil, L1R3, nil, L0R1, L2R1); L1R1.Depth :=1;
L1R2.Real (nil, nil, L1R5, nil, L0R3, L2R2); L1R2.Depth :=1;
L1R3.Real (L1R1, L1R4, L1R6, nil, L0R5, L2R3); L1R3.Depth :=1;
L1R4.Real (nil, L1R5, nil, L1R3, nil, L2R4); L1R4.Depth :=1;
L1R5.Real (L1R2, nil, L1R7, L1R4, L0R4, nil); L1R5.Depth :=1;
L1R6.Real (L1R3, L1R7, nil, nil, L0R6, L2R5); L1R6.Depth :=1;
L1R7.Real (L1R5, nil, nil, L1R6, L0R7, nil); L1R7.Depth :=1;
L2R1.Real (nil, L2R2, L2R3, nil, L1R1, L3R1); L2R1.Depth :=2;
L2R2.Real (nil, nil, L2R4, L2R1, L1R2, L3R2); L2R2.Depth :=2;
L2R3.Real (L2R1, L2R4, L2R5, nil, L1R3, L3R4); L2R3.Depth :=2;
L2R4.Real (L2R2, nil, nil, L2R3, L1R4, L3R6); L2R4.Depth :=2;
L2R5.Real (L2R3, nil, nil, nil, L1R6, L3R5); L2R5.Depth :=2;
L3R1.Real (nil, L3R2, L3R4, nil, L2R1, L4R1); L3R1.Depth :=3;
L3R2.Real (nil, L3R3, nil, L3R1, nil, nil); L3R2.Depth :=3;
L3R3.Real (nil, nil, L3R6, L3R2, L2R2, L4R2); L3R3.Depth :=3;
L3R4.Real (L3R1, L3R5, nil, nil, L2R3, L4R3); L3R4.Depth :=3;
L3R5.Real (nil, L3R6, nil, L3R4, L2R5, L4R5); L3R5.Depth :=3;
L3R6.Real (L3R3, nil, nil, L3R5, L2R4, nil); L3R6.Depth :=3;
L4R1.Real (nil, L4R2, L4R3, nil, L3R1, L5R1); L4R1.Depth :=4;
L4R2.Real (nil, nil, L4R4, L4R1, L3R3, L5R3); L4R2.Depth :=4;
L4R3.Real (L4R1, L4R4, L4R5, nil, L3R4, L5R4); L4R3.Depth :=4;
L4R4.Real (L4R2, nil, nil, L4R3, nil, L5R6); L4R4.Depth :=4;
L4R5.Real (L4R3, nil, nil, nil, L3R5, L5R8); L4R5.Depth :=4;
L5R1.Real (nil, L5R2, L5R4, L5R7, L4R1, L6R1); L5R1.Depth :=5;
L5R2.Real (nil, L5R3, L5R5, L5R1, nil, L6R2); L5R2.Depth :=5;
L5R3.Real (nil, nil, L5R6, L5R2, L4R2, L6R3); L5R3.Depth :=5;
L5R4.Real (L5R1, L5R5, L5R7, nil, L4R3, nil); L5R4.Depth :=5;
L5R5.Real (L5R2, L5R6, L5R8, L5R4, nil, L6R4); L5R5.Depth :=5;
L5R6.Real (L5R3, nil, nil, L5R5, nil, nil); L5R6.Depth :=5;
L5R7.Real (L5R4, L5R8, nil, nil, nil, nil); L5R7.Depth :=5;
L5R8.Real (L5R6, nil, nil, L5R7, L4R5, nil); L5R8.Depth :=5;
L6R1.Real (nil, L6R2, nil, nil, L5R1, nil); L6R1.Depth :=6;
L6R2.Real (nil, L6R3, L6R4, L6R1, L5R2, nil); L6R2.Depth :=6;
L6R3.Real (nil, nil, nil, L6R2, L5R2, nil); L6R3.Depth :=6;
L6R4.Real (L6R2, nil, Treasure, nil, L5R5, nil); L6R4.Depth :=6;
Treasure.Real (L6R4, nil, nil, nil, nil, nil); Treasure.Depth :=6;
end.
uRoom (My class for the Room-Objects):
unit uRoom;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
Room = class
private
NorthR, EastR, SouthR, WestR, UpR, DownR: Room;
North, East, South, West, Up, Down: Room;
procedure Real (NR, ER, SR, WR, UR, DR: Room);
procedure Move (N, E, S, W, U, D: Room);
end;
implementation
procedure Room.Real (NR, ER, SR, WR, UR, DR: Room);
begin
self.NorthR := NR;
self.EastR :=ER;
self.SouthR :=SR;
self.WestR :=WR;
self.UpR :=UR;
self.DownR :=DR;
end;
procedure Room.Move (N, E, S, W, U, D: Room);
begin
self.North := N;
Self.East := E;
self.South := S;
self.West := W;
self.Up := U;
self.Down := D;
end;
end.