Autor Beitrag
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Di 16.11.10 20:14 
Hey,

das war auch mein 1. Gedanke, einfach ein Array mit den Namen der Datein. Dann kann man ja ganz normal gucken ob die Datein da sind oder nich...

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Tharian Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Di 16.11.10 20:29 
user profile iconplatzwart hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
If(FileExists('Hier steht die Datei inkl. Pfad'))then
 begin
  // Datei existiert.
 end
else
 begin
  // Datei existiert nicht.
 end;


Ok, eigentlich logisch, danke. Ich nehme an wenn ich keinen Pfad angebe wird automatisch der Pfad genommen, in dem die .exe ist?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 16.11.10 20:42 
user profile iconTharian hat folgendes geschrieben Zum zitierten Posting springen:
Ich nehme an wenn ich keinen Pfad angebe wird automatisch der Pfad genommen, in dem die .exe ist?

Nein, das ist nicht so. Funktioniert zwar manchmal, aber das sollte man sich keinesfalls angewöhnen. Den Pfad der Exe bekommt man mit ExtractFilePath(ParamStr(0));, und der gehört in diese Abfrage mit rein. ;-)

_________________
We are, we were and will not be.
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Di 16.11.10 20:43 
ausblenden Delphi-Quelltext
1:
FileExists(ExtractFilePath(ParamStr(0)) + 'datei.dat')					

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
Tharian Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Di 16.11.10 22:12 
user profile iconplatzwart hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
FileExists(ExtractFilePath(ParamStr(0)) + 'datei.dat')					


Ok, danke. Hab ich jetzt noch nicht mit drin, weil die Stelle bisher auch so klappt (ich werds ändern wenn es läuft ;) ).
Allerdings kommt da irgendwas durcheinander mit den X bzw. O... Die sollen natürlich abwechselnd kommen, aber irgendwie klappt das nicht immer. Es scheint auch auf die Felder anzukommen, die man anklickt, wie lange es 'gut geht'. Irgendwie erkenne ich da kein Muster :/

Habt ihr eine Idee? Ich wollte erst am Anfang dem Playersymbol einen Wert (ein X) zuweisen, aber das hat auch nicht wirklich was genützt...

Und ja, ich weis, das könnte man alles viel kompakter machen mit case und so, aber das hab ich auch noch vor ;)

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:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Timer1: TTimer;
    Button10: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Playersymbol :char;

implementation

{$R *.dfm}


procedure TForm1.Timer1Timer(Sender: TObject);
begin
begin
 If(FileExists('X1.txt'))then
 begin
  Form1.Button1.Caption:='X';
 Playersymbol:='X';
 end;
 end;

begin
 If(FileExists('X2.txt'))then
 begin
  Form1.Button2.Caption:='X';
Playersymbol:='X';
  end;
 end;

begin
 If(FileExists('X3.txt'))then
 begin
  Form1.Button3.Caption:='X';
Playersymbol:='X';
end;
 end;

begin
 If(FileExists('X4.txt'))then
 begin
  Form1.Button4.Caption:='X';
Playersymbol:='X';
end;
 end;

begin
 If(FileExists('X5.txt'))then
 begin
  Form1.Button5.Caption:='X';
Playersymbol:='X';
end;
 end;

begin
 If(FileExists('X6.txt'))then
 begin
  Form1.Button6.Caption:='X';
Playersymbol:='X';
end;
 end;

 begin
 If(FileExists('X7.txt'))then
 begin
  Form1.Button7.Caption:='X';
Playersymbol:='X';
end;
 end;

begin
 If(FileExists('X8.txt'))then
 begin
  Form1.Button8.Caption:='X';
Playersymbol:='X';
end;
 end;

begin
 If(FileExists('X9.txt'))then
 begin
  Form1.Button9.Caption:='X';
Playersymbol:='X';
end;
 end;

begin
 If(FileExists('O1.txt'))then
 begin
  Form1.Button1.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O2.txt'))then
 begin
  Form1.Button2.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O3.txt'))then
 begin
  Form1.Button3.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O4.txt'))then
 begin
  Form1.Button4.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O5.txt'))then
 begin
  Form1.Button5.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O6.txt'))then
 begin
  Form1.Button6.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O7.txt'))then
 begin
  Form1.Button7.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O8.txt'))then
 begin
  Form1.Button8.Caption:='O';
Playersymbol:='O';
end;
 end;

begin
 If(FileExists('O9.txt'))then
 begin
  Form1.Button9.Caption:='O';
Playersymbol:='O';
end;


end;


end;


procedure TForm1.Button1Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button1.Caption:=Playersymbol;

end;

begin
  if FileExists(Playersymbol+'1.txt'then
    begin
      AssignFile(f, Playersymbol+'1.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'1.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;





end;
end;



procedure TForm1.Button2Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button2.Caption:=Playersymbol;

end;

begin
  if FileExists(Playersymbol+'2.txt'then
    begin
      AssignFile(f, Playersymbol+'2.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'2.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;





end;

end;

procedure TForm1.Button3Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button3.Caption:=Playersymbol;

end;

begin
  if FileExists(Playersymbol+'3.txt'then
    begin
      AssignFile(f, Playersymbol+'3.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'3.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;

end;


end;


procedure TForm1.Button4Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button4.Caption:=Playersymbol;

end;

begin
  if FileExists(Playersymbol+'4.txt'then
    begin
      AssignFile(f, Playersymbol+'4.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'4.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;



end;
end;


procedure TForm1.Button5Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button5.Caption:=Playersymbol;

end;

begin
  if FileExists(Playersymbol+'5.txt'then
    begin
      AssignFile(f, Playersymbol+'5.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'5.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;

end;





end;


procedure TForm1.Button6Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button6.Caption:=Playersymbol;

end;


begin
  if FileExists(Playersymbol+'6.txt'then
    begin
      AssignFile(f, Playersymbol+'6.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'6.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;

end;




end;



procedure TForm1.Button7Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button7.Caption:=Playersymbol;

end;


begin
  if FileExists(Playersymbol+'7.txt'then
    begin
      AssignFile(f, Playersymbol+'7.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
      end
    else
    begin
      AssignFile(f, Playersymbol+'7.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;

end;
end;





procedure TForm1.Button8Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button8.Caption:=Playersymbol;

end;

begin
  if FileExists(Playersymbol+'8.txt'then
    begin
      AssignFile(f, Playersymbol+'8.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'8.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;

end;





end;



procedure TForm1.Button9Click(Sender: TObject);
var f: Textfile;
begin

begin

if
    Playersymbol='O'
    then Playersymbol:='X'
    else Playersymbol:='O';

Button9.Caption:=Playersymbol;


end;

begin
  if FileExists(Playersymbol+'9.txt'then
    begin
      AssignFile(f, Playersymbol+'9.txt');
      Append(f);
      Writeln(f, '');
      CloseFile(f);
    end
  else
    begin
      AssignFile(f, Playersymbol+'9.txt');
      Rewrite(f);
      Writeln(f, '');
      CloseFile(f);
  end;

end;




end;




procedure TForm1.Button10Click(Sender: TObject);
begin


begin
  if MessageDLG('Spiel zurücksetzen und neu beginnen?',mtConfirmation, [mbYes,mbNo],0)=mrYes
  then begin

If (FileExists('X1.txt'))then
 Deletefile('X1.txt');

If(FileExists('X2.txt'))then
 Deletefile('X2.txt');

If(FileExists('X3.txt'))then
 Deletefile('X3.txt');

If(FileExists('X4.txt'))then
 Deletefile('X4.txt');

If(FileExists('X5.txt'))then
 Deletefile('X5.txt');

If(FileExists('X6.txt'))then
 Deletefile('X6.txt');

If(FileExists('X7.txt'))then
 Deletefile('X7.txt');

If(FileExists('X8.txt'))then
 Deletefile('X8.txt');

If(FileExists('X9.txt'))then
 Deletefile('X9.txt');

If(FileExists('O1.txt'))then
 Deletefile('O1.txt');

If(FileExists('O2.txt'))then
 Deletefile('O2.txt');

If(FileExists('O3.txt'))then
 Deletefile('O3.txt');

If(FileExists('O4.txt'))then
 Deletefile('O4.txt');

If(FileExists('O5.txt'))then
 Deletefile('O5.txt');

If(FileExists('O6.txt'))then
 Deletefile('O6.txt');

If(FileExists('O7.txt'))then
 Deletefile('O7.txt');

If(FileExists('O8.txt'))then
 Deletefile('O8.txt');

If(FileExists('O9.txt'))then
 Deletefile('O9.txt');

begin
Button1.Caption:='';
Button2.Caption:='';
Button2.Caption:='';
Button3.Caption:='';
Button4.Caption:='';
Button5.Caption:='';
Button6.Caption:='';
Button7.Caption:='';
Button8.Caption:='';
Button9.Caption:='';
end;

end;



end;
end;


end.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 16.11.10 22:23 
Sorry jetzt wird es OT aber IMHO solltest Du Dich mal mit TIniFile beschäftigen, das würde Deinen Dateienwald etwas eindampfen.

LG
Thomas

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Gerd Kayser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 632
Erhaltene Danke: 121

Win 7 32-bit
Delphi 2006/XE
BeitragVerfasst: Di 16.11.10 22:41 
user profile iconbummi hat folgendes geschrieben Zum zitierten Posting springen:
Sorry jetzt wird es OT aber IMHO solltest Du Dich mal mit TIniFile beschäftigen, das würde Deinen Dateienwald etwas eindampfen.
Wenn man es geschickt anfängt, kann man sogar den Umfang der Unit um über 90 Prozent kürzen, insbesondere die If- und Delete-Orgien.
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 17.11.10 00:24 
Hey,

also eig sind Datein ja dazu da, um was abzulegen, was man nochma benötigt, wenn man das Probgramm neu öffnet. Oder wenn es zu viel für den Arbeitsspeicher ist. Warum nimmst du nich einfach ein array[0..8of Boolean; Das ist unkompliziert, 1000 ma schneller als der Zugriff auf eine Datei und auch programmiertechnisch um weiten besser gelöst als die Sache mit den TXTs. Es sei denn du hast noch irgendetwas mit den TXTs vor (außer das Kreuz des Spielers zu speichern) dann nehm ich alles zurück.
Vlt soltlest du dir auch erstmal DAS angucken ;)

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Gerd Kayser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 632
Erhaltene Danke: 121

Win 7 32-bit
Delphi 2006/XE
BeitragVerfasst: Mi 17.11.10 04:30 
user profile iconBergmann89 hat folgendes geschrieben Zum zitierten Posting springen:
Es sei denn du hast noch irgendetwas mit den TXTs vor (außer das Kreuz des Spielers zu speichern) dann nehm ich alles zurück.
Das wird doch wohl hoffentlich nicht ein Tic-Tac-Toe-Spiel ... :autsch: