java贪吃蛇小程序源代码_贪吃蛇源代码Java_Applet小程序doc

41528d3028836879cd698677c3999917.gif贪吃蛇源代码Java_Applet小程序doc

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 intsnakeDirection = 2; public intsnakeReDirection = 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 booleancheckBeanIn( 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, intsingleWidthX, intsingleHeightY, intcooPos ) { 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, intsingleWidthX, intsingleHeightY, intcooPos ) { g.fillRoundRect( singleWidthX * temp1 + 1, singleHeightY * temp2 + 1, singleWidthX - 2, singleHeightY - 2, cooPos, cooPos ); } public void clearEndSnakePiece( Graphics g, int temp1, int temp2, intsingleWidthX, intsingleHeightY, intcooPos ) { 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 inthorizontalGrid, verticalGrid; private intsingleWidthX, singleHeightY; private intcooPos; private Snake mainSnake; private LinkedListeatedBean; { eatedBean = new LinkedList(); } private Iterator snakeSq; public javax.swing.TimersnakeTimer; private int direction = 2; private int score; private String info; private Point bean, eatBean; { bean = new Point();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值