線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:654
推到 Plurk!
推到 Facebook!

C++如何轉Delphi

尚未結案
momo500
一般會員


發表:1
回覆:0
積分:0
註冊:2004-10-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-24 18:50:10 IP:218.171.xxx.xxx 未訂閱
要如何轉成Delphi ? 這程式是寫ox的,有點長  ><" 有人可以教我嗎? #include  int z=1; bool ba,bb,bc,bd,be,bf,bg,bh,bi; char a,b,c,d,e,f,g,h,i; char syma,symb,symc; int x_step() { int step; do{ cout << "X's input: "; cin >> step; if (step>10)cout << "Invalid move."<9) ); return step; } int y_step () { int step; do{ cout << "O's input: "; cin >> step; if (step>10)cout << "Invalid move."<9) ); return step; } bool valid(int step) { bool temp=false; switch (step) { case 1: temp=ba;break; case 2: temp=bb;break; case 3: temp=bc;break; case 4: temp=bd;break; case 5: temp=be;break; case 6: temp=bf;break; case 7: temp=bg;break; case 8: temp=bh;break; case 9: temp=bi;break; } return temp; } bool win (int step) { bool wi; int turn; wi=false; turn=z%2; switch (step) { case 1: { if (turn==0)a=symb; else a=symc;} ba=true;break; case 2: { if (turn==0)b=symb; else b=symc;} bb=true;break; case 3: { if (turn==0)c=symb; else c=symc;} bc=true;break; case 4: { if (turn==0)d=symb; else d=symc;} bd=true;break; case 5: { if (turn==0)e=symb; else e=symc;} be=true;break; case 6: { if (turn==0)f=symb; else f=symc;} bf=true;break; case 7: { if (turn==0)g=symb; else g=symc;} bg=true;break; case 8: { if (turn==0)h=symb; else h=symc;} bh=true;break; case 9: { if (turn==0)i=symb; else i=symc;} bi=true;break; } cout << a << "|"<< b <<"|"<< c <9 && !winner) cout << "Fair game."; else if (((z-1)%2)==0) cout<< "O wins."; else if (((z-1)%2)!=0) cout<< "X wins."; } 發表人 - momo500 於 2004/11/24 18:51:45
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-24 20:52:23 IP:220.131.xxx.xxx 未訂閱
自行在改改  
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.
 
網海無涯,唯學是岸! 因為擁有,所以分享!
系統時間:2024-06-29 15:44:10
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!