157 lines
11 KiB
Plaintext
157 lines
11 KiB
Plaintext
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="generator" content="TempleOS V5.03">
|
||
|
<meta name="viewport" content="width=device-width">
|
||
|
<link rel="stylesheet" href="/style/templeos.css">
|
||
|
<script src="/script/templeos.js"></script>
|
||
|
<style type="text/css">
|
||
|
.cF0{color:#000000;background-color:#ffffff;}
|
||
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
||
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
||
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
||
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
||
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
||
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
||
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
||
|
.cF8{color:#555555;background-color:#ffffff;}
|
||
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
||
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
||
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
||
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
||
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
||
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
||
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<pre id="content">
|
||
|
<a name="l1"></a><span class=cF1>I8</span><span class=cF0> board [9];
|
||
|
<a name="l2"></a></span><span class=cF9>I64</span><span class=cF0> board_x[9]={150,250,350,150,250,350,150,250,350};
|
||
|
<a name="l3"></a></span><span class=cF9>I64</span><span class=cF0> board_y[9]={150,150,150,250,250,250,350,350,350};
|
||
|
<a name="l4"></a>
|
||
|
<a name="l5"></a></span><span class=cF1>U0</span><span class=cF0> DrawX(</span><span class=cF9>CDC</span><span class=cF0> *dc,</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y)
|
||
|
<a name="l6"></a>{
|
||
|
<a name="l7"></a> dc->thick=5;
|
||
|
<a name="l8"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,x-20,y-20,0,x+20,y+20,0);
|
||
|
<a name="l9"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,x+20,y-20,0,x-20,y+20,0);
|
||
|
<a name="l10"></a>}
|
||
|
<a name="l11"></a>
|
||
|
<a name="l12"></a></span><span class=cF1>U0</span><span class=cF0> DrawO(</span><span class=cF9>CDC</span><span class=cF0> *dc,</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y)
|
||
|
<a name="l13"></a>{
|
||
|
<a name="l14"></a> dc->thick=5;
|
||
|
<a name="l15"></a> </span><span class=cF5>GrCircle3</span><span class=cF0>(dc,x,y,0,25);
|
||
|
<a name="l16"></a>}
|
||
|
<a name="l17"></a>
|
||
|
<a name="l18"></a></span><span class=cF1>U0</span><span class=cF0> DrawBoard(</span><span class=cF9>I64</span><span class=cF0> player)
|
||
|
<a name="l19"></a>{
|
||
|
<a name="l20"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
||
|
<a name="l21"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc=</span><span class=cF5>DCAlias</span><span class=cF0>;
|
||
|
<a name="l22"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
|
||
|
<a name="l23"></a> dc->thick=5;
|
||
|
<a name="l24"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,200,100,0,200,400,0);
|
||
|
<a name="l25"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,300,100,0,300,400,0);
|
||
|
<a name="l26"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,100,200,0,400,200,0);
|
||
|
<a name="l27"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc,100,300,0,400,300,0);
|
||
|
<a name="l28"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<9;i++)
|
||
|
<a name="l29"></a> </span><span class=cF1>switch</span><span class=cF0> (board[i]) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l30"></a> </span><span class=cF1>case</span><span class=cF0> 1:
|
||
|
<a name="l31"></a> DrawX(dc,board_x[i],board_y[i]);
|
||
|
<a name="l32"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l33"></a> </span><span class=cF1>case</span><span class=cF0> 2:
|
||
|
<a name="l34"></a> DrawO(dc,board_x[i],board_y[i]);
|
||
|
<a name="l35"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l36"></a>
|
||
|
<a name="l37"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l38"></a></span><span class=cF2>//ms.pos.x,ms.pos.y are mouse x,y.</span><span class=cF0>
|
||
|
<a name="l39"></a> </span><span class=cF2>//ms.lb</span><span class=cF0> </span><span class=cF2>is mouse left bttn</span><span class=cF0>
|
||
|
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (player==1)
|
||
|
<a name="l41"></a> DrawX(dc,</span><span class=cFB>ms</span><span class=cF0>.pos.x-</span><span class=cF5>Fs</span><span class=cF0>->pix_left,</span><span class=cFB>ms</span><span class=cF0>.pos.y-</span><span class=cF5>Fs</span><span class=cF0>->pix_top);
|
||
|
<a name="l42"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l43"></a> DrawO(dc,</span><span class=cFB>ms</span><span class=cF0>.pos.x-</span><span class=cF5>Fs</span><span class=cF0>->pix_left,</span><span class=cFB>ms</span><span class=cF0>.pos.y-</span><span class=cF5>Fs</span><span class=cF0>->pix_top);
|
||
|
<a name="l44"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
|
||
|
<a name="l45"></a>}
|
||
|
<a name="l46"></a>
|
||
|
<a name="l47"></a></span><span class=cF1>U0</span><span class=cF0> TakeTurn(</span><span class=cF9>I64</span><span class=cF0> player)
|
||
|
<a name="l48"></a>{
|
||
|
<a name="l49"></a> </span><span class=cF9>I64</span><span class=cF0> i,x=0,y=0;
|
||
|
<a name="l50"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>100<=x<400</span><span class=cF7>)</span><span class=cF0> || !</span><span class=cF7>(</span><span class=cF0>100<=y<400</span><span class=cF7>)</span><span class=cF0> || board[i]) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l51"></a> </span><span class=cF1>if</span><span class=cF0> (player==1)
|
||
|
<a name="l52"></a> </span><span class=cF5>Beep</span><span class=cF0>;
|
||
|
<a name="l53"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l54"></a> </span><span class=cF5>Beep</span><span class=cF0>(74);
|
||
|
<a name="l55"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cFB>ms</span><span class=cF0>.lb) {
|
||
|
<a name="l56"></a> DrawBoard(player);
|
||
|
<a name="l57"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
|
||
|
<a name="l58"></a> }
|
||
|
<a name="l59"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cFB>ms</span><span class=cF0>.lb) {
|
||
|
<a name="l60"></a> DrawBoard(player);
|
||
|
<a name="l61"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
|
||
|
<a name="l62"></a> }
|
||
|
<a name="l63"></a> x=</span><span class=cFB>ms</span><span class=cF0>.pos.x-</span><span class=cF5>Fs</span><span class=cF0>->pix_left;
|
||
|
<a name="l64"></a> y=</span><span class=cFB>ms</span><span class=cF0>.pos.y-</span><span class=cF5>Fs</span><span class=cF0>->pix_top;
|
||
|
<a name="l65"></a> i=(x-100)/100+(y-100)/100*3;
|
||
|
<a name="l66"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l67"></a> board[i]=player;
|
||
|
<a name="l68"></a>}
|
||
|
<a name="l69"></a>
|
||
|
<a name="l70"></a></span><span class=cF1>Bool</span><span class=cF0> CheckWinner(</span><span class=cF9>I64</span><span class=cF0> player)
|
||
|
<a name="l71"></a>{
|
||
|
<a name="l72"></a> </span><span class=cF1>if</span><span class=cF0> ( player==board[0]==board[1]==board[2] ||
|
||
|
<a name="l73"></a> player==board[3]==board[4]==board[5] ||
|
||
|
<a name="l74"></a> player==board[6]==board[7]==board[8] ||
|
||
|
<a name="l75"></a>
|
||
|
<a name="l76"></a> player==board[0]==board[3]==board[6] ||
|
||
|
<a name="l77"></a> player==board[1]==board[4]==board[7] ||
|
||
|
<a name="l78"></a> player==board[2]==board[5]==board[8] ||
|
||
|
<a name="l79"></a>
|
||
|
<a name="l80"></a> player==board[0]==board[4]==board[8] ||
|
||
|
<a name="l81"></a> player==board[2]==board[4]==board[6] )
|
||
|
<a name="l82"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l83"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l84"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l85"></a>}
|
||
|
<a name="l86"></a>
|
||
|
<a name="l87"></a></span><span class=cF1>U0</span><span class=cF0> DoGame()
|
||
|
<a name="l88"></a>{
|
||
|
<a name="l89"></a> </span><span class=cF9>I64</span><span class=cF0> moves=0;
|
||
|
<a name="l90"></a> </span><span class=cF5>MemSet</span><span class=cF0>(board,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>board</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l91"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l92"></a> TakeTurn(1);
|
||
|
<a name="l93"></a> </span><span class=cF1>if</span><span class=cF0> (CheckWinner</span><span class=cF7>(</span><span class=cF0>1</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l94"></a> </span><span class=cF5>Beep</span><span class=cF0>;
|
||
|
<a name="l95"></a> </span><span class=cF5>Beep</span><span class=cF0>;
|
||
|
<a name="l96"></a> </span><span class=cF5>Beep</span><span class=cF0>;
|
||
|
<a name="l97"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l98"></a> }
|
||
|
<a name="l99"></a> </span><span class=cF1>if</span><span class=cF0> (++moves==9) </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l100"></a>
|
||
|
<a name="l101"></a> TakeTurn(2);
|
||
|
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (CheckWinner</span><span class=cF7>(</span><span class=cF0>2</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l103"></a> </span><span class=cF5>Beep</span><span class=cF0>(74);
|
||
|
<a name="l104"></a> </span><span class=cF5>Beep</span><span class=cF0>(74);
|
||
|
<a name="l105"></a> </span><span class=cF5>Beep</span><span class=cF0>(74);
|
||
|
<a name="l106"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l107"></a> }
|
||
|
<a name="l108"></a> </span><span class=cF1>if</span><span class=cF0> (++moves==9) </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l109"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l110"></a>}
|
||
|
<a name="l111"></a>
|
||
|
<a name="l112"></a></span><span class=cF1>U0</span><span class=cF0> TicTacToe()
|
||
|
<a name="l113"></a>{
|
||
|
<a name="l114"></a> </span><span class=cF5>WinMax</span><span class=cF0>; </span><span class=cF2>//Maximize window</span><span class=cF0>
|
||
|
<a name="l115"></a> </span><span class=cF5>DocClear</span><span class=cF0>; </span><span class=cF2>//Clear window text.</span><span class=cF0>
|
||
|
<a name="l116"></a> </span><span class=cF6>"$GREEN$CTRL-ALT-c$FG$ to exit.\n"</span><span class=cF0>;
|
||
|
<a name="l117"></a> </span><span class=cF1>try</span><span class=cF0>
|
||
|
<a name="l118"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
|
||
|
<a name="l119"></a> DoGame;
|
||
|
<a name="l120"></a> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l121"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
|
||
|
<a name="l122"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
|
||
|
<a name="l123"></a>}
|
||
|
<a name="l124"></a>
|
||
|
<a name="l125"></a>TicTacToe;
|
||
|
</span></pre></body>
|
||
|
</html>
|