C++如何轉Delphi |
尚未結案
|
momo500
一般會員 發表:1 回覆:0 積分:0 註冊:2004-10-17 發送簡訊給我 |
要如何轉成Delphi ?
這程式是寫ox的,有點長
><" 有人可以教我嗎?
#include
|
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
自行在改改
program Project1; {$APPTYPE CONSOLE} uses SysUtils; var z:integer=1; ba,bb,bc,bd,be,bf,bg,bh,bi:boolean; a,b,c,d,e,f,g,h,i:char; syma,symb,symc:char; winner:boolean=False; xstep,ystep:integer; function x_step:integer; var step:integer; begin Repeat Write('X input:'); ReadLn(step); if (step >10) then WriteLn('Invalid move.'); until ((step<=0)or(step>9)); result:=step; end; function y_step:integer; var step:integer; begin Repeat Write('O input:'); ReadLn(step); if (step >10) then WriteLn('Invalid move.'); until ((step<=0)or(step>9)); result:=step; end; function valid(step:integer):boolean; begin case step of 1: result:=ba; 2: result:=bb; 3: result:=bc; 4: result:=bd; 5: result:=be; 6: result:=bf; 7: result:=bg; 8: result:=bh; 9: result:=bi; end; end; function win(step:integer):boolean; var wi:boolean; turn:integer; begin wi:=False; turn:=z Mod 2; case step of 1:begin if (turn=0) then a:=symb else a:=symc;ba:=true;end; 2:begin if (turn=0) then b:=symb else b:=symc;bb:=true;end; 3:begin if (turn=0) then c:=symb else c:=symc;bc:=true;end; 4:begin if (turn=0) then d:=symb else d:=symc;bd:=true;end; 5:begin if (turn=0) then e:=symb else e:=symc;be:=true;end; 6:begin if (turn=0) then f:=symb else f:=symc;bf:=true;end; 7:begin if (turn=0) then g:=symb else g:=symc;bg:=true;end; 8:begin if (turn=0) then h:=symb else h:=symc;bh:=true;end; 9:begin if (turn=0) then i:=symb else i:=symc;bi:=true;end; end; WriteLn( a, '|', b ,'|', c); WriteLn( '- - -'); WriteLn( d, '|', e ,'|', f); WriteLn( '- - -'); WriteLn( g, '|', h ,'|', i); if ((a=b) and (b=c) and (b<>syma)) then begin WriteLn('a'); wi:=true; end else if ((d=e) and (e=f) and (e<>syma)) then begin WriteLn('b'); wi:=true; end else if ((g=h) and (h=i) and (g<>syma)) then begin WriteLn('c'); wi:=true; end else if ((a=d) and (d=g) and (d<>syma)) then begin WriteLn('d'); wi:=true; end else if ((b=e) and (e=h) and (e<>syma)) then begin WriteLn('e'); wi:=true; end else if ((c=f) and (f=i) and (f<>syma)) then begin WriteLn('f'); wi:=true; end else if ((a=e) and (e=i) and (e<>syma)) then begin WriteLn('g'); wi:=true; end else if ((c=e) and (e=g) and (g<>syma)) then begin WriteLn('h'); wi:=true; end else wi:=False; result:=wi; end; begin { TODO -oUser -cConsole Main : Insert code here } syma:=' '; symb:='O'; symc:='X'; a := syma; b := syma; c := syma; d := syma; e := syma; f := syma; g := syma; h := syma; i := syma; ba:=False; bb:=False; bc:=False; bd:=False; be:=False; bf:=False; bg:=False; bh:=False; bi:=False; While ( (Not winner) and (z<=9) ) do begin Repeat xstep:=x_step; until (valid(xstep)); valid(xstep); winner:=win(xstep); winner:=win(xstep); z:=z 1; if ((Not winner) and (z<=9) ) then begin Repeat ystep:=y_step; until (valid(ystep)); winner:=win(ystep); z:=z 1; end; end; if ((z>9) and (Not winner)) then WriteLn('Fair game.') else if (((z-1) mod 2)=0) then WriteLn('O wins.') else if (((z-1) mod 2)<>0) then WriteLn('X wins.'); readLn; end.網海無涯,唯學是岸! 因為擁有,所以分享! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |