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

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

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

  snakegame.java

  package snakegame;

  import javax.swing.*;

  public class snakegame

  {

  public static void main( string[] args )

  {

  jdialog.setdefaultlookandfeeldecorated( true );

  gameframe temp = new gameframe();

  }

  }

  snake.java

  package snakegame;

  import java.awt.*;

  import java.util.*;

  class snake extends linkedlist

  {

  public int snakedirection = 2;

  public int snakeredirection = 4;

  public snake()

  {

  this.add( new point( 3, 3 ) );

  this.add( new point( 4, 3 ) );

  this.add( new point( 5, 3 ) );

  this.add( new point( 6, 3 ) );

  this.add( new point( 7, 3 ) );

  this.add( new point( 8, 3 ) );

  this.add( new point( 9, 3 ) );

  this.add( new point( 10, 3 ) );

  }

  public void changedirection( point temp, int direction )

  {

  this.snakedirection = direction;

  switch( direction )

  {

  case 1://up

  this.snakeredirection = 3;

  this.add( new point( temp.x, temp.y - 1 ) );

  break;

  case 2://right

  this.snakeredirection = 4;

  this.add( new point( temp.x + 1, temp.y ) );

  break;

  case 3://down

  this.snakeredirection = 1;

  this.add( new point( temp.x, temp.y + 1 ) );

  break;

  case 4://left

  this.snakeredirection = 2;

  this.add( new point( temp.x - 1, temp.y ) );

  break;

  }

  }

  public boolean checkbeanin( point bean )

  {

  point temp = (point) this.getlast();

  if( temp.equals( bean ) )

  {

  return true;

  }

  return false;

  }

  public void removetail()

  {

  this.remove( 0 );

  }

  public void drawsnake( graphics g, int singlewidthx, int singleheighty, int coopos )

  {

  g.setcolor( colorgroup.color_snake );

  iterator snakesq = this.iterator();

  while ( snakesq.hasnext() )

  {

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

  this.drawsnakepiece( g, temppoint.x, temppoint.y,

  singlewidthx, singleheighty, coopos );

  }

  }

  public void drawsnakepiece( graphics g, int temp1, int temp2,

  int singlewidthx, int singleheighty, int coopos )

  {

  g.fillroundrect( singlewidthx * temp1 + 1,

  singleheighty * temp2 + 1,

  singlewidthx - 2,

  singleheighty - 2,

  coopos,

  coopos );

  }

  public void clearendsnakepiece( graphics g, int temp1, int temp2,

  int singlewidthx, int singleheighty, int coopos )

  {

  g.setcolor( colorgroup.color_back );

  g.fillroundrect( singlewidthx * temp1 + 1,

  singleheighty * temp2 + 1,

  singlewidthx - 2,

  singleheighty - 2,

  coopos,

  coopos );

  }

  }

  gameframe.java

  package snakegame;

  import java.awt.*;

  import java.awt.event.*;

  import javax.swing.*;

  import java.util.*;

  import java.awt.geom.*;

  class gameframe extends jframe

  {

  private toolkit tempkit;

  private int horizontalgrid, verticalgrid;

  private int singlewidthx, singleheighty;

  private int coopos;

  private snake mainsnake;

  private linkedlist eatedbean;

  {

  eatedbean = new linkedlist();

  }

  private iterator snakesq;

  public javax.swing.timer snaketimer;

  private int direction = 2;

  private int score;

  private string info;

  private point bean, eatbean;

  {

  bean = new point();

  }

  private boolean flag;

  private jmenubar infomenu;

  private jmenu[] tempmenu;

  private jmenuitem[] tempmenuitem;

  private jradiobuttonmenuitem[] levelmenuitem, versionmenuitem;

  private jlabel scorelabel;

  {

  scorelabel = new jlabel();

  }

  private graphics2d g;

  private imageicon snakehead;

  {

  snakehead = new imageicon( "logo.gif" );

  }

  private configmenu configmenu;

  private boolean hasstoped = true;

  public gameframe()

  {

  this.tempkit = this.gettoolkit();

  this.setsize( tempkit.getscreensize() );

  this.setgrid( 60, 40, 5

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