Autor Beitrag
speck12
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Do 17.07.08 17:37 
Hallo

ich versuche gerade einen Tetrisklon zu machen. Wirklich weit bin ich noch nicht. Als kurzen Test wollte ich die erstellten Steine, die auf einem Image dargestellt werden sollen, runterfallen zu lassen. Doch dort kommt die Zugriffsverletzung und ich stehe auf dem Schlauch .. :(

hier mal der Quelltext :

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, tetris_unit, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    feld: TImage;
    Timer1: TTimer;
    Button1: TButton;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
   Steinliste : TList;
   Spielfeld : Array[1..24of Array[1..32of integer;
   procedure init;
   procedure abspielen;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.init;
 var i,n : integer;
     farbe : Tcolor;
  begin
   randomize;

   Steinliste := TList.Create;


   for i := 0 to 99 do
    begin
 //    n := Random(7) +1 ;
     farbe := Random($FFFFFF);
     Steinliste.Add(TTetris.Create(farbe));
     TTetris(Steinliste.Items[i]).position := i*15 + 15 ;
    end;

  end;


procedure TForm1.abspielen;
 var i,m,n : integer;
  begin
  for i := 0 to 99 do
   begin
    if TTetris(Steinliste.Items[i]).position >= 1 then
     begin
      with TTetris(Steinliste.Items[i]) do
       begin

        if a[1,1then Spielfeld[11,TTetris(Steinliste.Items[i]).position] := 1;
        if a[2,1then Spielfeld[12,TTetris(Steinliste.Items[i]).position] := 1;
        if a[3,1then Spielfeld[13,TTetris(Steinliste.Items[i]).position] := 1;
        if a[4,1then Spielfeld[14,TTetris(Steinliste.Items[i]).position] := 1;
        if a[1,2then Spielfeld[11,TTetris(Steinliste.Items[i]).position+1] := 1;
        if a[2,2then Spielfeld[12,TTetris(Steinliste.Items[i]).position+1] := 1;
        if a[3,2then Spielfeld[13,TTetris(Steinliste.Items[i]).position+1] := 1;
        if a[4,2then Spielfeld[14,TTetris(Steinliste.Items[i]).position+1] := 1;
        if a[1,3then Spielfeld[11,TTetris(Steinliste.Items[i]).position+2] := 1;
        if a[2,3then Spielfeld[12,TTetris(Steinliste.Items[i]).position+2] := 1;
        if a[3,3then Spielfeld[13,TTetris(Steinliste.Items[i]).position+2] := 1;
        if a[4,3then Spielfeld[14,TTetris(Steinliste.Items[i]).position+2] := 1;
        if a[1,4then Spielfeld[11,TTetris(Steinliste.Items[i]).position+3] := 1;
        if a[2,4then Spielfeld[12,TTetris(Steinliste.Items[i]).position+3] := 1;
        if a[3,4then Spielfeld[13,TTetris(Steinliste.Items[i]).position+3] := 1;
        if a[4,4then Spielfeld[14,TTetris(Steinliste.Items[i]).position+3] := 1;

       end;
    for m := 11 to 14 do
     for n := TTetris(Steinliste.Items[i]).position to TTetris(Steinliste.Items[i]).position +3 do
      begin
       if Spielfeld[m,n] = 1 then
        begin
         Feld.Canvas.Pen.Color := clBlack;
         Feld.Canvas.Brush.Color := TTetris(Steinliste.Items[i]).color;
         Feld.Canvas.Rectangle(m*20,n*20,(m+1)*20,(n+1)*20);
        end;
      end;
   end;
  end;

  end;




procedure TForm1.Timer1Timer(Sender: TObject);
var i : integer;
 begin
   for i := 0 to 99 do
    begin
     Inc(TTetris(Steinliste.Items[i]).position);
    end;
   abspielen;
 end;

procedure TForm1.FormCreate(Sender: TObject);
 begin
  init;
 end;

procedure TForm1.Button1Click(Sender: TObject);
 begin
  timer1.Enabled := true;
 end;

end.


und hier die unit mit der TTetris: (Im moment verwende ich nur TTetris, die Abkömmlinge (TTetris1..7) kommen später hinzu)
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
unit tetris_unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;


type
    TTetris = class(TObject)
               color : TColor;
               typ   : integer;
               position : integer;
               a : Array[1..4of Array[1..4of Boolean;  {darstellung}
               constructor Create(Farben : TColor);
               procedure Rotate; virtual ;
               Destructor Destroy(); override;
              end;

    TTetris1 = class(TTetris)
                constructor Create(Farbe : TColor);
                procedure Rotate; override ;
                Destructor Destroy(); override;
               end;

    TTetris2 = class(TTetris)
                constructor Create(Farbe : TColor);
                procedure Rotate; override ;
                Destructor Destroy(); override;
               end;

    TTetris3 = class(TTetris)
                constructor Create(Farbe : TColor);
                procedure Rotate; override ;
                Destructor Destroy(); override;
               end;

    TTetris4 = class(TTetris)
                constructor Create(Farbe : TColor);
                procedure Rotate; override ;
                Destructor Destroy(); override;
               end;
    TTetris5 = class(TTetris)
                constructor Create(Farbe : TColor);
                procedure Rotate; override ;
                Destructor Destroy(); override;
               end;

    TTetris6 = class(TTetris)
                constructor Create(Farbe : TColor);
                procedure Rotate; override ;
                Destructor Destroy(); override;
               end;

    TTetris7 = class(TTetris)
                constructor Create(Farbe : TColor);
                procedure Rotate; override ;
                Destructor Destroy(); override;
               end;



implementation

constructor TTetris.Create(Farben : TColor);
 begin
  Inherited Create;
  color := Farben ;
  typ := 0;
  position := 0;
     a[1,1] := false; a[2,1] := false; a[3,1] := false; a[4,1] := false;    {oooo}
     a[2,1] := TRUE ; a[2,2] := TRUE ; a[3,2] := false; a[4,2] := false;    {xxoo}
     a[3,1] := TRUE ; a[3,2] := TRUE ; a[3,3] := false; a[4,3] := false;    {xxoo}
     a[4,1] := false; a[4,2] := false; a[4,3] := false; a[4,4] := false;    {oooo}

 end;

procedure TTetris.Rotate;
 begin
  //
 end;

destructor TTetris.Destroy;
 begin
  Inherited Destroy;
 end;

constructor TTetris1.Create(Farbe : TColor);
 begin
  Inherited Create(Farbe);
  typ := 1;

     a[1,1] := false; a[2,1] := false; a[3,1] := false; a[4,1] := false;    {oooo}
     a[2,1] := TRUE ; a[2,2] := TRUE ; a[3,2] := false; a[4,2] := false;    {xxoo}
     a[3,1] := TRUE ; a[3,2] := TRUE ; a[3,3] := false; a[4,3] := false;    {xxoo}
     a[4,1] := false; a[4,2] := false; a[4,3] := false; a[4,4] := false;    {oooo}

 end;

procedure TTetris1.Rotate;
 begin
  //
 end;

destructor TTetris1.Destroy;
 begin
  Inherited Destroy;
 end;

constructor TTetris2.Create(Farbe : TColor);
 begin
  Inherited Create(Farbe);
  typ := 2;

    a[1,1] := false; a[2,1] := false; a[3,1] := false; a[4,1] := false;    {oooo}
    a[2,1] := false; a[2,2] := TRUE ; a[3,2] := false; a[4,2] := false;    {oxoo}
    a[3,1] := TRUE ; a[3,2] := TRUE ; a[3,3] := TRUE ; a[4,3] := false;    {xxxo}
    a[4,1] := false; a[4,2] := false; a[4,3] := false; a[4,4] := false;    {oooo}

 end;

procedure TTetris2.Rotate;
 begin
  //
 end;

destructor TTetris2.Destroy;
 begin
  Inherited Destroy;
 end;

constructor TTetris3.Create(Farbe : TColor);
 begin
  Inherited Create(Farbe);
  typ := 3 ;

    a[1,1] := false; a[2,1] := TRUE ; a[3,1] := false; a[4,1] := false;    {oxoo}
    a[2,1] := false; a[2,2] := TRUE ; a[3,2] := false; a[4,2] := false;    {oxoo}
    a[3,1] := TRUE ; a[3,2] := TRUE ; a[3,3] := false; a[4,3] := false;    {xxoo}
    a[4,1] := false; a[4,2] := false; a[4,3] := false; a[4,4] := false;    {oooo}
 end;

procedure TTetris3.Rotate;
 begin
  //
 end;

destructor TTetris3.Destroy;
 begin
  Inherited Destroy;
 end;

constructor TTetris4.Create(Farbe : TColor);
 begin
  Inherited Create(Farbe);
  typ := 4;

    a[1,1] := false; a[2,1] := TRUE ; a[3,1] := false; a[4,1] := false;    {oxoo}
    a[2,1] := false; a[2,2] := TRUE ; a[3,2] := false; a[4,2] := false;    {oxoo}
    a[3,1] := false; a[3,2] := TRUE ; a[3,3] := TRUE ; a[4,3] := false;    {oxxo}
    a[4,1] := false; a[4,2] := false; a[4,3] := false; a[4,4] := false;    {oooo}
 end;

procedure TTetris4.Rotate;
 begin
  //
 end;

destructor TTetris4.Destroy;
 begin
  Inherited Destroy;
 end;

constructor TTetris5.Create(Farbe : TColor);
 begin
  Inherited Create(Farbe);
  typ := 5;

    a[1,1] := false; a[2,1] := TRUE ; a[3,1] := false; a[4,1] := false;    {oxoo}
    a[2,1] := false; a[2,2] := TRUE ; a[3,2] := false; a[4,2] := false;    {oxoo}
    a[3,1] := false; a[3,2] := TRUE ; a[3,3] := false; a[4,3] := false;    {oxoo}
    a[4,1] := false; a[4,2] := TRUE ; a[4,3] := false; a[4,4] := false;    {oxoo}
 end;

procedure TTetris5.Rotate;
 begin
  //
 end;

destructor TTetris5.Destroy;
 begin
  Inherited Destroy;
 end;

constructor TTetris6.Create(Farbe : TColor);
 begin
  Inherited Create(Farbe);
  typ := 6;

    a[1,1] := false; a[2,1] := false; a[3,1] := false; a[4,1] := false;    {oooo}
    a[2,1] := false; a[2,2] := TRUE ; a[3,2] := TRUE ; a[4,2] := false;    {oxxo}
    a[3,1] := TRUE ; a[3,2] := TRUE ; a[3,3] := false; a[4,3] := false;    {xxoo}
    a[4,1] := false; a[4,2] := false; a[4,3] := false; a[4,4] := false;    {oooo}
 end;

procedure TTetris6.Rotate;
 begin
  //
 end;

destructor TTetris6.Destroy;
 begin
  Inherited Destroy;
 end;

constructor TTetris7.Create(Farbe : TColor);
 begin
  Inherited Create(Farbe);
  typ := 7;

    a[1,1] := false; a[2,1] := false; a[3,1] := false; a[4,1] := false;    {oooo}
    a[2,1] := TRUE ; a[2,2] := TRUE ; a[3,2] := false; a[4,2] := false;    {xxoo}
    a[3,1] := false; a[3,2] := TRUE ; a[3,3] := TRUE ; a[4,3] := false;    {oxxo}
    a[4,1] := false; a[4,2] := false; a[4,3] := false; a[4,4] := false;    {oooo}
 end;

procedure TTetris7.Rotate;
 begin
  //
 end;

destructor TTetris7.Destroy;
 begin
  Inherited Destroy;
 end;

end.


evlt findet ihr ja den Fehler..
Danke im Vorraus

mfg
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 17.07.08 17:51 
Was machst du denn, bevor der Fehler auftritt?

1. Wenn der Fehler auftaucht, zeigt dir Delphi die Stelle an, wo er auftritt.
2. Suchen -> Zu Adresse springen -> Die Adresse eintragen, wo die Zugriffsverletzung auftritt -> auch hiermit springt Delphi zu der entsprechenden Zeile.
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Do 17.07.08 18:02 
hmmm. die Fehleradresse ist 0041376D..
ich kann danach suchen, aber dann wird mir nur das CPU-Fenster angezeigt, jeodoch nicht die Stelle im Quelltext

mfg
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Do 17.07.08 18:42 
Hi,

Bei Auftreten des Fehlers müsste Delphi direkt an die Stelle im Quelltext springen(was bei mir so alle 1000 Mal nicht der Fall ist^^).

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)