//---------------------------------------------------------------------- // ナンバーライン(スリザーリンク/ロジカルサーキット) // // Copyright(C) 1996 Hirofumi Fujiwara // 本プログラムは、改造も含め、その商用利用は禁止します。 //---------------------------------------------------------------------- import java.awt.*; import java.applet.*; import java.lang.*; import java.io.*; import java.util.*; import java.net.*; public class NumberLine extends Applet { final static int CTRLPANEL_Y = 5; final static int CTRLPANEL_H = 45; public String postpage; // 正解の時に表示するページ final int XLIM = 40; final int YLIM = 40; final int VERTEX_POS = 1; final int EDGE_POS = 2; final int FACE_POS = 3; Dimension app_size; // アプレットのサイズ public int xn, yn; // サイズ int unit, wd; // マスサイズ、線幅 int bd_off_x, bd_off_y; // 盤のボーダーオフセット boolean ishint; // ヒント状態かどうか boolean ischecked = false; // チェック状態か Panel controlPanel; // 指定周辺稜線数:初期化時に、数値の与えられた個所にだけ数字が入り、他は0 public Area areainfo[][]; // 稜線:稜線状態を管理するためのデータ。 public Edge edgeinfo[][]; // 頂点:頂点状態を管理するためのデータ。 public Vertex vertexinfo[][]; final Color backcolor = Color.white; final Color forecolor = Color.black; final Color errorcolor = Color.red; public void init() { postpage = getParameter("post"); String filename = getParameter( "problemfile" ); loadData( filename ); app_size = this.size(); unit = (int)(app_size.width*0.92)/xn; wd = (unit+40)/20; setLayout( new BorderLayout() ); setBackground( Color.white ); controlPanel = new Panel(); controlPanel.setLayout(new FlowLayout()); controlPanel.add( new ControlButton( this, "Clear", " Clear " ) ); controlPanel.add( new ControlButton( this, "Check", " Check " ) ); controlPanel.add( new ControlButton( this, "Hint", " Hint " ) ); ishint = false; add( "North", controlPanel ); controlPanel.reshape( 0, CTRLPANEL_Y, app_size.width, CTRLPANEL_H ); bd_off_x = ( app_size.width - unit * xn ) / 2; bd_off_y = CTRLPANEL_H + bd_off_x; Label copyright = new Label("Number Line V0.12" + " " + "Copyright(C)1997 Hirofumi Fujiwara.", Label.CENTER ); add( "South", copyright ); // copyright.reshape( 0, app_size.height-22, app_size.width, 20 ); } //---------------------------------------------------------------- // ボードの配列を確保する void newBoard() { areainfo = new Area[xn][yn]; for( int x=0; xcheck()" ); boolean bad = false; // 数字の周囲の線の数をチェック for( int i=0; i 1 ) bad = true; } ishint = false; System.out.println( "bad="+bad+" postpage="+postpage ); if( (!bad) && (postpage != null) ) { try { URL url = new URL( getCodeBase() + postpage ); getAppletContext().showDocument( url ); } catch( MalformedURLException e ) { } } repaint(); } //---------------------------------------------------------------- // 検査なしの状態に戻す public void uncheck() { for( int i=0; i 1 ) e.color = Color.red; e = v.pairEdge(numline,e); v = (e.lowVertex(numline)==v) ? e.highVertex(numline) : e.lowVertex(numline); } return true; } } //================================================================================ // 頂点の情報 //================================================================================ class Vertex { int x, y; public int n; // 構築子 Vertex ( int i, int j ) { x = i; y = j; } public void check( NumberLine numline ) { n = 0; if( ! ( x<0 || numline.xn0 && (numline.edgeinfo[x*2][y*2-1].draw == 1 ) ) ++n; // 左 if( x>0 && (numline.edgeinfo[x*2-1][y*2].draw == 1 ) ) ++n; // 下 if( y0 ) { // 上 pe = numline.edgeinfo[x*2][y*2-1]; if( (pe != ed) && (pe.draw == 1) ) return pe; } if( x>0 ) { // 左 pe = numline.edgeinfo[x*2-1][y*2]; if( (pe != ed) && (pe.draw == 1) ) return pe; } if( y