//======================================================================= // JAVA JanKen Applet Ver 3.10 (FreeSoft) // BakuretuKen 1997-2003 // Home Page http://www.vector.co.jp/authors/VA006860/ //======================================================================= import java.applet.Applet; import java.awt.*; import java.net.*; import java.io.*; import java.util.Random; import java.applet.AudioClip; import java.awt.image.*; // =============================================================== public class JanKenGame extends Applet implements Runnable { Image image[], backimage; Graphics bg; boolean isSound; boolean isAiko; AudioClip au1, au2, au3, au4, au5, au6; MediaTracker mt; Thread thread; int flag = 0; int youhp = 10; // 相手のHP(10固定) int life, life_b; // 自分のHP(life_bは自分のHP最大値) boolean my[], you[]; Color bc; String jumpURL; boolean isPaint; // --------------------------------------------------------------- // init( ) 初期処理 public void init() { int i; String s; String imagename = null; Image img; isPaint = false; s = getParameter("image"); if (s != null) imagename = s; s = getParameter("life"); life = 5; life = Integer.valueOf(s).intValue(); if (life < 0) life = 1; if (life > 7) life = 7; life_b = life; jumpURL = null; s = getParameter("jump"); if (s != null) jumpURL = s; isSound=false; s = getParameter("sound"); if (s != null) isSound = s.equals("on"); mt = new MediaTracker(this); backimage = createImage( 64*4, 102*4 ); bg = backimage.getGraphics(); image = new Image[6]; // 画像読み込み try{ // ゲーム画像 image[0] = getImage(getDocumentBase(), imagename ); // タイトル他 img = getImage(getDocumentBase(), "00_janken.gif"); image[1] = getRectImage_A( img, 194, 0, 63, 64 ); // ぐー image[2] = getRectImage_A( img, 194+64, 0, 63, 64 ); // ちょき image[3] = getRectImage_A( img, 194+2*64, 0, 63, 64 ); // ぱー image[4] = getRectImage_A( img, 0, 0, 194, 96 ); // タイトル image[5] = getRectImage_A( img, 194, 64, 20, 20 ); // はーと } catch(Exception err){ System.out.println("CG READ ERROR !!"); System.exit(0); } for( i=0; i<5; i++) mt.addImage( image[i], 0); bc = new Color( 21,234,138); // sound読み込み if (isSound){ au1 = getAudioClip( getDocumentBase(), "00_jan1.au"); au2 = getAudioClip( getDocumentBase(), "00_jan2.au"); au3 = getAudioClip( getDocumentBase(), "00_jan3.au"); au4 = getAudioClip( getDocumentBase(), "00_jan4.au"); au5 = getAudioClip( getDocumentBase(), "00_jan5.au"); au6 = getAudioClip( getDocumentBase(), "00_jan6.au"); } flag = 0; isAiko = false; my = new boolean [3]; you = new boolean [3]; for (i=0; i<3; i++){ my[i]=false; you[i]=false; } System.out.println("<< JAVA JanKen applet Ver 3.10 (FreeSoft)>>"); System.out.println(" (C) BakuretuKen 1997"); System.out.println(" Homepage: http://www.vector.co.jp/authors/VA006860/"); // スレッドスタート thread = new Thread(this); thread.start(); } // init() // --------------------------------------------------------------- // Paint( ) public void paint(Graphics g) { int i; // << エラー >> if (mt.isErrorID(0)) { g.setColor(Color.red); g.fillRect(0, 0, size().width, size().height); g.setColor(Color.yellow); g.setFont(new Font("Dialog", Font.ITALIC, 20 )); g.drawString("Error", 20, 60); return; } // << Loading >> if ( ! mt.checkID(0)) { Dimension d = size(); g.setColor( bc ); g.fillRect( 0, 0, d.width, d.height ); g.setColor(Color.red); g.setFont(new Font("Dialog", Font.ITALIC, 16 )); g.drawString("Now Loading .....", size().width/2-50, size().height/2); g.setColor(Color.blue); g.setFont(new Font("Dialog", Font.ITALIC, 14 )); g.drawString(" JanKen Applet Ver 3.10 (C)BakuretuKen 1997 (FreeSoft)", 2, 20); return; } // << 作画 >> if (isPaint) { g.setColor( bc ); g.fillRect( 256, 0, 244, 400 ); g.drawImage(backimage, 0, 0, this); //キャラ作画 g.drawImage( image[4], 256, 0, this);//タイトル if (you[0]) i=1; else i=0; g.drawImage( image[1], 257, 100 + i*30, this);//ぐー if (my[0]) i=1; else i=0; g.drawImage( image[1], 257, 300 - i*30, this);//ぐー if (you[1]) i=1; else i=0; g.drawImage( image[2], 257+64, 100 + i*30, this);//ちょき if (my[1]) i=1; else i=0; g.drawImage( image[2], 257+64, 300 - i*30, this);//ちょき if (you[2]) i=1; else i=0; g.drawImage( image[3], 257+128,100 + i*30, this);//ぱー if (my[2]) i=1; else i=0; g.drawImage( image[3], 257+128,300 - i*30, this);//ぱー for ( i=0; i>"+pno+" "+aite); if( !isAiko && isSound ) { sstop(); au2.play(); } if( isAiko && isSound ) { sstop(); au5.play(); } if ( pno == aite ) isAiko = true; else isAiko = false; my [pno] =true; you[aite]=true; // 勝敗判定 if ( pno == aite ) { flag = 4; repaint(); return; } if ( (pno==0&&aite==1) || (pno==1&&aite==2) || ( pno==2&&aite==0 ) ) { youhp--; CGmove(true); flag = 2; if ( youhp==0 ){ flag = 5; if(isSound){ sstop(); au3.play(); } } repaint(); } else { life--; flag = 3; if ( life==0 ){ flag = 6; if(isSound) { sstop(); au6.play(); } } repaint(); } return; } // pon() // --------------------------------------------------------------- // URLジャンプ private boolean jumpHTML( String phtml ) { if ( phtml == null ) { System.err.println( "No File !! Jump!! :"); return false; } try { this.getAppletContext().showDocument( new URL(getDocumentBase(),phtml ), "_self"); } catch ( IOException e ) { System.err.println("URL JUMP Error !!! :"+phtml ); return false; } return true; } // jumpHTML() // =============================================================== // getRectImage 本体 private Image getRectImage_A(Image image,int x,int y,int w,int h) throws InterruptedException{ int pixel[]=new int[w*h]; PixelGrabber pg=new PixelGrabber(image,x,y,w,h,pixel,0,w); pg.grabPixels(); MemoryImageSource mis=new MemoryImageSource(w,h,pixel,0,w); return(createImage(mis)); } // --------------------------------------------------------------- } // End of Class