# DelphiManager

by Matt Tucker: L6 Age ~16 (when he developed the program in 2008)

## Introduction

This remarkable soccer simulation game gives minute-by-minute updates of the score of your matches and frequent highlights. There are hundreds of different realistic scenarios coded and selected randomly. Injury time and extra time are built-in.

The following screen shot shows a highlight.

You have a choice of a friendly match or a cup or league competition. Names of eight squads of 20 players (from 2008) are already hard-coded into the program. You can choose your team and its starting formation. For a league competition, the league table is shown after each set of matches. A record of the scorers is kept for a whole competition.

A knowledge of football is helpful. For example, the goalkeeper selected must have a squad number of 1 or 12. You can intervene in order to substitute players, change the formation, and/or obtain the current statistics for the match. Be prepared to make a decision about which substitute to bring on when a player is injured.

We suggest that you try a friendly game to begin with and accept the default players and formations. Play a game through and see the match statistics. Statistics include scorers, chances, and yellow and red cards.

The program has over 5000 lines of code so we just give three examples here. Now (in 2014) that browsers are much faster than they were four years ago, we supply the full formatted code (on our Heroku website). You can download the whole program and copy it into Lazarus or Delphi in order to experiment with the code. We can easily understand many of the variable names in the code but may struggle with others. How much of the code can you understand?

## The Program Excerpts

The first extract from the program shows some of the many options available to the user.

```
procedure settings;
var
t:integer;
begin
write('Do you want to change any team settings? y/n ');
If choice = 'y' then
begin
hsetup;
write('  Do you want to pick your penalty taker? y/n ');
If choice = 'y' then
begin
For t:= 1 to 11 do writeln(t,'. ',HPlayer[t]);
repeat
writeln;
write('Pick your penalty taker using the squad numbers ');
until (pen < 12)
and (pen > 1);
writeln(HPlayer[pen],' will be taking ',Home,'s penalties!');
writeln;
end;
write('  Do you want to pick your free-kick taker? y/n ');
If choice = 'y' then
begin
For t:= 1 to 11 do writeln(t,'. ',HPlayer[t]);
repeat
writeln;
write('Pick your free-kick taker using the squad numbers ');
until (fkt < 12)
and (fkt > 1);
writeln(HPlayer[fkt],' will be taking ',Home,'s free-kicks!');
writeln;
end;
write('  Do you want to pick your corner taker? y/n ');
If choice = 'y' then
begin
For t:= 1 to 11 do writeln(t,'. ',HPlayer[t]);
repeat
writeln;
write('Pick your corner taker using the squad numbers ');
until (ckt < 12)
and (ckt > 1);
writeln(HPlayer[ckt],' will be taking ',Home,'s corners!');
writeln;
end;
write('  Do you want to pick your captain? y/n ');
If choice = 'y' then
begin
For t:= 1 to 11 do writeln(t,'. ',HPlayer[t]);
repeat
writeln;
write('Pick your captain using the squad numbers ');
until (capt < 12)
and (capt > 0);
writeln(HPlayer[capt],' will be ',Home,'s captain!');
end;
end;
end;
```

The following procedure selects at random the number of a player for attack (9 or 10), wide midfield (7 or 11), central midfield (4 or 8) and back four (2, 3, 5 or 6). These players may then take part in the next highlight, along with the goalkeeper and the selected kick takers. We include only the code for the 4-4-2 formation.

```procedure ranformpick;
begin
If formation = '4-4-2' then
begin
ap:=random(2);
ap:=ap+9;
mw:=random(2);
mw:=4*mw;
mw:=mw+7;
cm:=random(2);
cm:=cm+1;
cm:=4*cm;
df:=random(4);
case df of
0: df:= 2;
1: df:= 3;
2: df:= 5;
3: df:= 6;
end;
end;
.
.
.

```

The following code is for the home highlight resulting from one of 44 possible values of chance. The whole of the highlights procedure has over 2000 lines of code!

```  glopp:=10+setupno;
glran:=random(glopp);
If chances < homerat then
begin
chance:=random(44);
case chance of
0: begin
writeln('Shot by, ',HPlayer[ap],'...');
If glran > 4 then
begin
writeln('Into the bottom right hand corner!');
writeln('GOAL for ',home,'!!!');
HPTot[ap]:=HPTot[ap]+9;
APTot[1]:=APTot[1]+3;
hscore:=hscore+1;
ScTime[hscore+ascore]:=time;
Scorer[hscore+ascore]:=HPlayer[ap];
ScClub[hscore+ascore]:=home;
end;
If glran < 5 then
begin
writeln('Good save from ',APlayer[1],' that was close');
HPTot[ap]:=HPTot[ap]+6;
APTot[1]:=APTot[1]+8;
end;
HPChan[ap]:=HPChan[ap]+1;
APChan[1]:=APChan[1]+1;
end;
.
.
.

```

## Remarks

Can you think of a program like this that you could write?

Programming - a skill for life!

Student programs to inspire you!