快速业务通道

改进后的Java英文字母打字游戏 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-20
ypedSum+isWrongTypedSum+isOmittedSum; if(sum==0) { percent=0f; showPercent=0;} else { percent=(float)isTypedSum/sum; showPercent=(int)(percent*100); } g.drawString("击中"+isTypedSum+" 错击"+isWrongTypedSum+" 漏掉"+isOmittedSum+" 正确率"+showPercent+"%",200,200); } else { g.drawString("击中"+isTypedSum+" 错击"+isWrongTypedSum+" 漏掉"+isOmittedSum+" 正确率"+showPercent+"%",200,200); } } } class C extends MouseAdapter { public void mousePressed(MouseEvent e) { showPopup(e); } public void mouseReleased(MouseEvent e) { showPopup(e); } public void showPopup(MouseEvent e) { if(e.isPopupTrigger()) jmp.show(e.getComponent(),e.getX(),e.getY()); } } class D extends KeyAdapter { public void keyPressed(KeyEvent e) { char key=e.getKeyChar(); if(isTyped(key)) { } else { } } public boolean isTyped(char key) { for(int i=0;i<myletter.exist_letter_num;i++) { if((char)(key-32)==myletter.cc[i].charAt(0)) { isTypedSum++; myletter.reStart(i); return true; } } isWrongTypedSum++; return false; } } public void stop() { newthread=null; } } class letter { MyPanel game; final int Max; boolean let[]; int X[]; int Y[]; int speed[]; int exist_letter_num; int XY[]; int ini; StringBuffer c[]; String cc[]; Random ran=new Random(); Color mycolor[]={Color.red,Color.green}; int aa[]; public letter(MyPanel game) { Max=9; //将字母最多设置为9个。此数为不可改变的。 this.game=game; let=new boolean[Max]; XY=new int[Max]; ini=50; initArray(); exist_letter_num=3; //初始化,刚开始落下字母的个数。 } public void initArray() { for(int i=0;i<Max;i++) { let[i]=false; XY[i]=ini; ini+=70; } } public void randomLetters() //随机产生n个不同数字的值。 { X=new int[exist_letter_num]; Y=new int[exist_letter_num]; speed=new int[exist_letter_num]; aa=new int[100]; for(int i=0,n=0;i<exist_letter_num;i++)//通过9个不同的位置来随机产生字母出现的坐标位置。 { aa[n]=ran.nextInt(9); if(i!=0) { while(check(aa,n)) { aa[n]=ran.nextInt(9); } } X[i]=XY[aa[n]]; Y[i]=ran.nextInt(11)-10; speed[i]=ran.nextInt(8)+1; let[aa[n]]=true; //保存下放字母的位置。 n++; } randomStrings(); } public void randomStrings() { c=new StringBuffer[exist_letter_num]; cc=new String[exist_letter_num]; while(true) { for(int i=0;i<exist_letter_num;i++) { c[i]=new StringBuffer(); cc[i]=new String(); c[i].setLength(1); c[i].setCharAt(0,(char)(ran.nextInt(26)+65)); cc[i]=""+c[i]; } if(checkChar(c)) break; } } public boolean checkChar(StringBuffer c[]) { if(exist_letter_num==1) return true; for(int i=0;i<exist_letter_num-1;i++) for(int j=i+1;j<exist_letter_num;j++) { if(c[i].equals(c[j])) return false; } return true; } public boolean check(int aa[],int n) { for(int i=0;i<n;i++) for(int j=i+1;j<=n;j++) { if(aa[i]==aa[j]) return true; } return false; } public void paintLetters(Graphics g) { for(int temp=0;temp<exist_letter_num;temp++) { g.setColor(mycolor[ran.nextInt(2)]); g.fill3DRect(X[temp],Y[temp],20,20,true); g.setC

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号