MrMonotone
2015-02-13 09:52:32
I was trying to get around using arrays because I wanted to have my data be more dynamic. I wanted to be able to remove and insert values easily. So I made the following code. I was wondering if there was an easier way to do this but maintain the same functionality. Please comment if I need to explain further.
Thanks for the help.
MM
//TLDR : I want a list of TActivity and I think I did it in a ghetto way.
Thanks for the help.
MM
//TLDR : I want a list of TActivity and I think I did it in a ghetto way.
program test;
{$DEFINE SMART}
{$i AeroLib/AeroLib.Simba}
{$i Reflection/Reflection.simba}
{$i SimbaExt/SimbaExt.simba}
type TActivity = record
Name: String;
Gear: TStringArray;
end;
SkillsCanLevel = (Cooking, Fletching, Fishing, Firemaking, Woodcutting);
const
Skills : array [SkillsCanLevel] of String = ['Cooking', 'Fletching', 'Fishing', 'Firemaking', 'Woodcutting'];
var
SkillsToLevel: TStringList;
CurActivity: TActivity;
s: String;
procedure setActivity(TheSkill : String);
begin
case TheSkill of
Skills[Cooking]:
begin
with CurActivity do
begin
Name := TheSkill;
Gear := [];
end;
end;
Skills[Fletching]:
begin
with CurActivity do
begin
Name := TheSkill;
Gear := ['Knife'];
end;
end;
Skills[Fishing]:
begin
with CurActivity do
begin
Name := TheSkill;
Gear := ['Fishing Rod'];
end;
end;
Skills[Firemaking]:
begin
with CurActivity do
begin
Name := TheSkill;
Gear := ['Tinderbox'];
end;
end;
Skills[Woodcutting]:
begin
with CurActivity do
begin
Name := TheSkill;
Gear := ['Axe'];
end;
end;
end;
end;
function GearInInv() : Boolean;
begin
Result:= true;
end;
function GearInEquip() : Boolean;
begin
Result:= true;
end;
function TActivity.HasGear() : Boolean;
begin
Result:= GearInEquip OR GearInInv;
end;
procedure TActivity.DoActivity;
begin
Writeln('We are: ', Name,' with ', Gear);
case Name of
Skills[Cooking]:
begin
//cooking
end;
Skills[Fletching]:
begin
// Fletch;
end;
Skills[Fishing]:
begin
//Fish;
end;
Skills[Firemaking]:
begin
//Fire
end;
Skills[Woodcutting]:
begin
//woodcut
end;
end;
end;
begin
SkillsToLevel.Init();
SkillsToLevel.Add(Skills[Cooking]);
SkillsToLevel.Add(Skills[Firemaking]);
while (true) do
begin
setActivity(SkillsToLevel.getStrings(Random(0, SkillsToLevel.getCount - 1)));
CurActivity.DoActivity();
wait(5000);
end;
end.