网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 交易代码 > Java精品代码 > 正文

java小游戏-贪吃蛇-JSP教程,Java技巧及代码

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务
bel.settext( "pause[space] - exit[esc]" );

  }

  private void movesnake( int direction )

  {

  if( mainsnake.checkbeanin( this.bean ) )

  {

  this.score += 100;

  this.scorelabel.settext( this.info + " current score:" + this.score );

  this.eatedbean.add( new point(this.bean) );

  this.createbean( this.bean );

  }

  mainsnake.changedirection( (point) mainsnake.getlast(), direction );

  point temp = (point) mainsnake.getfirst();

  if( eatedbean.size() != 0 )

  {

  if( eatedbean.getfirst().equals( temp ) )

  {

  eatedbean.remove( 0 );

  }

  else

  {

  mainsnake.clearendsnakepiece( getgraphics(), temp.x, temp.y,

  singlewidthx, singleheighty, coopos );

  mainsnake.removetail();

  }

  }

  else

  {

  mainsnake.clearendsnakepiece( getgraphics(), temp.x, temp.y,

  singlewidthx, singleheighty, coopos );

  mainsnake.removetail();

  }

  }

  private void drawbeanandebean( graphics g )

  {

  g.setcolor( colorgroup.color_bean );

  this.drawpiece( g, this.bean.x, this.bean.y );

  g.setcolor( colorgroup.color_eatedbean );

  snakesq = eatedbean.iterator();

  while ( snakesq.hasnext() )

  {

  point temppoint = (point)snakesq.next();

  this.drawpiece( g, temppoint.x, temppoint.y );

  }

  }

  private void drawpiece( graphics g, int x, int y )

  {

  g.fillroundrect( this.singlewidthx * x + 1,

  this.singleheighty * y + 1,

  this.singlewidthx - 2,

  this.singleheighty - 2,

  this.coopos,

  this.coopos );

  }

  private void createbean( point temp )

  {

  lp:

  while( true )

  {

  temp.x = (int) (math.random() * this.horizontalgrid);

  temp.y = (int) (math.random() * this.verticalgrid);

  snakesq = mainsnake.iterator();

  while ( snakesq.hasnext() )

  {

  if( snakesq.next().equals( new point( temp.x, temp.y ) ) )

  {

  continue lp;

  }

  }

  break;

  }

  }

  }

  configmenu.java

  package snakegame;

  import java.awt.*;

  import java.awt.event.*;

  import javax.swing.*;

  public class configmenu extends jmenubar

  {

  gameframe owner;

  jmenu[] menu;

  jmenuitem[] menuitem;

  jradiobuttonmenuitem[] speeditem, modelitem, standarditem;

  private uimanager.lookandfeelinfo looks[];

  public configmenu( gameframe owner )

  {

  this.owner = owner;

  owner.setjmenubar( this );

  string[] menu_name = {"snake game", "game configure", "game help"};

  menu = new jmenu[menu_name.length];

  for( int i = 0; i < menu_name.length; i++ )

  {

  menu[i] = new jmenu( menu_name[i] );

  menu[i].setfont( new font( "courier", font.plain, 12 ) );

  this.add( menu[i] );

  }

  string[] menuitem_name = {"start game", "stop game", "exit game",

  "game color",

  "about..."};

  menuitem = new jmenuitem[menuitem_name.length];

  for( int i = 0; i < menuitem_name.length; i++ )

  {

  menuitem[i] = new jmenuitem( menuitem_name[i] );

  menuitem[i].setfont( new font( "courier", font.plain, 12 ) );

  menuitem[i].addactionlistener( new actionhandler() );

  }

  menu[0].add( menuitem[0] );

  menu[0].add( menuitem[1] );

  menu[0].addseparator();

  menu[0].add( menuitem[2] );

  menu[1].add( menuitem[3] );

  menu[2].add( menuitem[4] );

  string[] inner_menu_name = {"game speed", "window model", "game standard "};

  jmenu[] inner_menu = new jmenu[inner_menu_name.length];

  for( int i = 0; i < inner_menu_name.length; i++ )

  {

  inner_menu[i] = new jmenu( inner_menu_name[i] );

  inner_menu[i].setfont( new font( "courier", font.plain, 12 ) );

  menu[1].add( inner_menu[i] );

  }

  buttongroup temp1 = new buttongroup();

  string[] speeditem_name = {"speed-1", "

  • 上一篇资讯: 记事本的JAVA源代码
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师