導航:首頁 > 編程語言 > 貪吃蛇java程序

貪吃蛇java程序

發布時間:2023-07-11 15:43:21

java貪吃蛇技術選型怎麼寫的

Java貪吃蛇技術選型一般需要考慮以下幾點:

② 求貪吃蛇Java代碼

#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<conio.h>
#include<time.h>

#define Map_long 20
#define Map_high 15

typedef struct snake{
int goods_class;
int direction;
}SNAKE;

/*-------------------------------------------------------*/
/* 全局變數聲明區 */

/* 二維結構體數組里goods_class的值,0代表活動區域(空格),
* 1代表■(地圖磚頭),2代表★(食物),3代表●(蛇頭)
* 3之後的數字代表◎(蛇身),3+蛇長度-1表示◎(蛇尾)*/
/*direction表示蛇移動的方向,↑8,↓2,←4,→6*/
SNAKE Snake[Map_high][Map_long] = { { 0 } };

unsigned die = 0; //1表示游戲結束
unsigned snake_move = 0; //移動成功,用來跳出三重循環
unsigned eat_food = 0; //1表示碰到食物,2表示用來跳出循環
unsigned snake_long = 3; //記錄蛇的長度

void Move(int ch); //蛇移動的函數

void HideCursor(); //隱藏游標函數

int main(void)
{
system("mode con:cols=43 lines=20"); //將控制台設置成長41,高18
HideCursor();

/*定義局部變數區域*/
unsigned i, j;
unsigned food = 0; //食物存在的標志,1代表食物存在
unsigned food_x, food_y; //產生食物的臨時坐標
unsigned score = 0; //統計分數
char ch = '\0'; //用來獲取↑↓←→

/*播種子*/
srand((unsigned)time(NULL));

/*初始化地圖*/
for (i = 0; i < Map_long; i++)
{
Snake[0][i].goods_class = 1;
Snake[Map_high - 1][i].goods_class = 1;
}
for (i = 0; i < Map_high; i++)
{
Snake[i][0].goods_class = 1;
Snake[i][Map_long - 1].goods_class = 1;
}

/*初始化蛇的位置*/
for (i = 0; i < snake_long; i++)
Snake[Map_high / 2][Map_long / 2 + i].goods_class = snake_long + i;

while (1)
{
while (!_kbhit())
{
switch (ch)
{
case 72:Move(8); break;
case 75:Move(4); break;
case 77:Move(6); break;
case 80:Move(2); break;
default:break;
}

if (eat_food == 2) //2表示吃到食物,開始重置狀態
{
food = 0; //食物沒有了
eat_food = 0; //重新判定是否吃到食物
snake_long++; //蛇的長度加1
score++; //增加分數
}

/*產生食物*/
do{
if (food == 1)
break;
food_x = rand() % Map_long;
food_y = rand() % Map_high;
if (Snake[food_y][food_x].goods_class == 0)
{
Snake[food_y][food_x].goods_class = 2;
food++;
break;
}
} while (1);

printf("Grade:%u\n", score);
for (i = 0; i < Map_high; i++)
{
if (die == 1)
break;

for (j = 0; j < Map_long; j++)
{
switch (Snake[i][j].goods_class)
{
case 0:printf(" "); break;
case 1:printf("■"); break;
case 2:printf("★"); break;
case 3:printf("●"); break;
default:printf("◎"); break;
}
}
putchar('\n');
}
printf("Up↑ Down↓ Left← Right→ Other Pause.");

Sleep(50);
system("cls");

if (die == 1)
break;
}
if (die == 1)
break;

do{
ch = _getch();
} while (ch != -32 && ch != 80 && ch != 72 && ch != 77 && ch != 75);
ch = _getch();
}
system("cls");
printf("Game Over,your grade is %u.\n", score);
getchar();
return 0;
}

void Move(int ch)
{
int i, j, n;
int direction; //臨時存儲方向

for (n = 0; n < snake_long; n++)
for (i = 0; i < Map_high; i++)
{
if (snake_move == 1)
{
snake_move = 0;
break;
}
if (eat_food == 2)
break;
for (j = 0; j < Map_long; j++)
if (Snake[i][j].goods_class == 3 + n)
{
/*第一次獲取按鍵,初始化蛇的運動狀態*/
if (Snake[i][j].goods_class == 3 && Snake[i][j].direction == 0)
{
Snake[i][j].direction = ch;
Snake[i][j + 1].direction = 4;
Snake[i][j + 2].direction = 4;
}
else if (Snake[i][j].goods_class == 3) //重置蛇頭的方向
Snake[i][j].direction = ch;

/*進行移動前,先判斷蛇頭是否碰到死亡因子*/
if (Snake[i][j].goods_class == 3)
{
if (Snake[i][j].direction == 8 && Snake[i - 1][j].goods_class != 0 && Snake[i - 1][j].goods_class != 2)
die++;

else if (Snake[i][j].direction == 2 && Snake[i + 1][j].goods_class != 0 && Snake[i + 1][j].goods_class != 2)
die++;

else if (Snake[i][j].direction == 4 && Snake[i][j - 1].goods_class != 0 && Snake[i][j - 1].goods_class != 2)
die++;

else if (Snake[i][j].direction == 6 && Snake[i][j + 1].goods_class != 0 && Snake[i][j + 1].goods_class != 2)
die++;
}

/*進行移動前,先判斷蛇頭是否碰到食物*/
if (Snake[i][j].goods_class == 3)
{
if (Snake[i][j].direction == 8 && Snake[i - 1][j].goods_class == 2)
eat_food++;

else if (Snake[i][j].direction == 2 && Snake[i + 1][j].goods_class == 2)
eat_food++;

else if (Snake[i][j].direction == 4 && Snake[i][j - 1].goods_class == 2)
eat_food++;

else if (Snake[i][j].direction == 6 && Snake[i][j + 1].goods_class == 2)
eat_food++;
}

if (die == 1)
break;

/*蛇尾的移動*/
if (Snake[i][j].goods_class == 3 + snake_long - 1)
{
if (eat_food == 1) //吃到食物就更新蛇尾
{
if (Snake[i][j].direction == 8)
{
direction = Snake[i - 1][j].direction;
Snake[i - 1][j] = Snake[i][j];
Snake[i - 1][j].direction = direction;
Snake[i][j].goods_class = 3 + snake_long;
}
else if (Snake[i][j].direction == 2)
{
direction = Snake[i + 1][j].direction;
Snake[i + 1][j] = Snake[i][j];
Snake[i + 1][j].direction = direction;
Snake[i][j].goods_class = 3 + snake_long;
}
else if (Snake[i][j].direction == 4)
{
direction = Snake[i][j - 1].direction;
Snake[i][j - 1] = Snake[i][j];
Snake[i][j - 1].direction = direction;
Snake[i][j].goods_class = 3 + snake_long;
}
else if (Snake[i][j].direction == 6)
{
direction = Snake[i][j + 1].direction;
Snake[i][j + 1] = Snake[i][j];
Snake[i][j + 1].direction = direction;
Snake[i][j].goods_class = 3 + snake_long;
}
snake_move++;
eat_food++;
break;
}
else{
if (Snake[i][j].direction == 8)
{
Snake[i][j].direction = Snake[i - 1][j].direction;
Snake[i - 1][j] = Snake[i][j];
Snake[i][j].goods_class = 0;
}
else if (Snake[i][j].direction == 2)
{

③ 用Java語言寫一個約1500行代碼的貪吃蛇游戲

Runnable

}

if (i.util.Date.start();args) {

Thread new Thread(new Thread1());0;one = new Thread(new Thread2()).printStackTrace();

public

if (i %

one.start();

two;class Thread2

Thread implements class Thread1 {

while(true){

i++;
System.out.println(new i = run() {

while (true) {

two = Date().toLocaleString());
} catch try {
Thread.sleep(10000);Runnable {

break;

}
}
}
}
import java;Client {

public static void main(String[] );

public void run()
}
}
}
}<pre t="code" l="java">public class 4 == 0) {

System.out.println(;*******<pre t="code" l="java">public implements {

private int (InterruptedException e) {
e;{

public void 100)nbsp

④ java貪吃蛇代碼注釋求解

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
public class InterFace extends JFrame {
/**
* WIDTH:寬
* HEIGHT:高
* SLEEPTIME:可以看作蛇運動的速度
* L = 1,R = 2, U = 3, D = 4 左右上下代碼
*/
public static final int WIDTH = 800, HEIGHT = 600, SLEEPTIME = 200, L = 1,R = 2, U = 3, D = 4;
BufferedImage offersetImage= new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_3BYTE_BGR);;
Rectangle rect = new Rectangle(20, 40, 15 * 50, 15 * 35);
Snake snake;
Node node;
public InterFace() {
//創建"蛇"對象
snake = new Snake(this);
//創建"食物"對象
createNode();
this.setBounds(100, 100, WIDTH, HEIGHT);
//添加鍵盤監聽器
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
System.out.println(arg0.getKeyCode());
switch (arg0.getKeyCode()) {
//映射上下左右4個鍵位
case KeyEvent.VK_LEFT:
snake.dir = L;
break;
case KeyEvent.VK_RIGHT:
snake.dir = R;
break;
case KeyEvent.VK_UP:
snake.dir = U;
break;
case KeyEvent.VK_DOWN:
snake.dir = D;
}
}
});
this.setTitle("貪吃蛇 0.1 By : Easy");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
//啟動線程,開始執行
new Thread(new ThreadUpadte()).start();
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) offersetImage.getGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, WIDTH, HEIGHT);
g2d.setColor(Color.black);
g2d.drawRect(rect.x, rect.y, rect.width, rect.height);
//如果蛇碰撞(吃)到食物,則創建新食物
if (snake.hit(node)) {
createNode();
}
snake.draw(g2d);
node.draw(g2d);
g.drawImage(offersetImage, 0, 0, null);
}
class ThreadUpadte implements Runnable {
public void run() {
//無限重繪畫面
while (true) {
try {
Thread.sleep(SLEEPTIME);
repaint(); //
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/**
* 創建食物
*/
public void createNode() {
//隨機食物的出現位置
int x = (int) (Math.random() * 650) + 50,y = (int) (Math.random() * 500) + 50;
Color color = Color.blue;
node = new Node(x, y, color);
}
public static void main(String args[]) {
new InterFace();
}
}
/**
* 節點類(包括食物和蛇的身軀組成節點)
*/
class Node {
int x, y, width = 15, height = 15;
Color color;
public Node(int x, int y, Color color) {
this(x, y);
this.color = color;
}
public Node(int x, int y) {
this.x = x;
this.y = y;
this.color = color.black;
}
public void draw(Graphics2D g2d) {
g2d.setColor(color);
g2d.drawRect(x, y, width, height);
}
public Rectangle getRect() {
return new Rectangle(x, y, width, height);
}
}
/**
* 蛇
*/
class Snake {
public List<Node> nodes = new ArrayList<Node>();
InterFace interFace;
int dir=InterFace.R;
public Snake(InterFace interFace) {
this.interFace = interFace;
nodes.add(new Node(20 + 150, 40 + 150));
addNode();
}
/**
* 是否碰撞到食物
* @return true 是 false 否
*/
public boolean hit(Node node) {
//遍歷整個蛇體是否與食物碰撞
for (int i = 0; i < nodes.size(); i++) {
if (nodes.get(i).getRect().intersects(node.getRect())) {
addNode();
return true;
}
}
return false;
}
public void draw(Graphics2D g2d) {
for (int i = 0; i < nodes.size(); i++) {
nodes.get(i).draw(g2d);
}
move();
}
public void move() {
nodes.remove((nodes.size() - 1));
addNode();
}
public synchronized void addNode() {
Node nodeTempNode = nodes.get(0);
//如果方向
switch (dir) {
case InterFace.L:
//判斷是否會撞牆
if (nodeTempNode.x <= 20) {
nodeTempNode = new Node(20 + 15 * 50, nodeTempNode.y);
}
nodes.add(0, new Node(nodeTempNode.x - nodeTempNode.width,
nodeTempNode.y));
break;
case InterFace.R:
//判斷是否會撞牆
if (nodeTempNode.x >= 20 + 15 * 50 - nodeTempNode.width) {
nodeTempNode = new Node(20 - nodeTempNode.width, nodeTempNode.y);
}
nodes.add(0, new Node(nodeTempNode.x + nodeTempNode.width,
nodeTempNode.y));
break;
case InterFace.U:
//判斷是否會撞牆
if (nodeTempNode.y <= 40) {
nodeTempNode = new Node(nodeTempNode.x, 40 + 15 * 35);
}
nodes.add(0, new Node(nodeTempNode.x, nodeTempNode.y - nodeTempNode.height));
break;
case InterFace.D:
//判斷是否會撞牆
if (nodeTempNode.y >= 40 + 15 * 35 - nodeTempNode.height) {
nodeTempNode = new Node(nodeTempNode.x,40 - nodeTempNode.height);
}
nodes.add(0, new Node(nodeTempNode.x, nodeTempNode.y + nodeTempNode.height));
break;
}
}
}

⑤ 用JAVA設計游戲:貪吃蛇游戲

用MVC方式實現的貪吃蛇游戲,共有4個類。運行GreedSnake運行即可。主要是觀察者模式的使用,我已經添加了很多注釋了。
1、
/*
* 程序名稱:貪食蛇
* 原作者:BigF
* 修改者:algo
* 說明:我以前也用C寫過這個程序,現在看到BigF用Java寫的這個,發現雖然作者自稱是Java的初學者,
* 但是明顯編寫程序的素養不錯,程序結構寫得很清晰,有些細微得地方也寫得很簡潔,一時興起之
* 下,我認真解讀了這個程序,發現數據和表現分開得很好,而我近日正在學習MVC設計模式,
* 因此嘗試把程序得結構改了一下,用MVC模式來實現,對源程序得改動不多。
* 我同時也為程序增加了一些自己理解得注釋,希望對大家閱讀有幫助。
*/

package mvcTest;

/**
* @author WangYu
* @version 1.0
* Description:
* </pre>
* Create on :Date :2005-6-13 Time:15:57:16
* LastModified:
* History:
*/
public class GreedSnake {
public static void main(String[] args) {
SnakeModel model = new SnakeModel(20,30);
SnakeControl control = new SnakeControl(model);
SnakeView view = new SnakeView(model,control);
//添加一個觀察者,讓view成為model的觀察者
model.addObserver(view);

(new Thread(model)).start();
}
}

-------------------------------------------------------------
2、

package mvcTest;

//SnakeControl.java
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
* MVC中的Controler,負責接收用戶的操作,並把用戶操作通知Model
*/
public class SnakeControl implements KeyListener{
SnakeModel model;

public SnakeControl(SnakeModel model){
this.model = model;
}

public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (model.running){ // 運行狀態下,處理的按鍵
switch (keyCode) {
case KeyEvent.VK_UP:
model.changeDirection(SnakeModel.UP);
break;
case KeyEvent.VK_DOWN:
model.changeDirection(SnakeModel.DOWN);
break;
case KeyEvent.VK_LEFT:
model.changeDirection(SnakeModel.LEFT);
break;
case KeyEvent.VK_RIGHT:
model.changeDirection(SnakeModel.RIGHT);
break;
case KeyEvent.VK_ADD:
case KeyEvent.VK_PAGE_UP:
model.speedUp();
break;
case KeyEvent.VK_SUBTRACT:
case KeyEvent.VK_PAGE_DOWN:
model.speedDown();
break;
case KeyEvent.VK_SPACE:
case KeyEvent.VK_P:
model.changePauseState();
break;
default:
}
}

// 任何情況下處理的按鍵,按鍵導致重新啟動游戲
if (keyCode == KeyEvent.VK_R ||
keyCode == KeyEvent.VK_S ||
keyCode == KeyEvent.VK_ENTER) {
model.reset();
}
}

public void keyReleased(KeyEvent e) {
}

public void keyTyped(KeyEvent e) {
}
}
-------------------------------------------------------------
3、
/*
*
*/

package mvcTest;

/**
* 游戲的Model類,負責所有游戲相關數據及運行
* @author WangYu
* @version 1.0
* Description:
* </pre>
* Create on :Date :2005-6-13 Time:15:58:33
* LastModified:
* History:
*/
//SnakeModel.java
import javax.swing.*;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Observable;
import java.util.Random;

/**
* 游戲的Model類,負責所有游戲相關數據及運行
*/
class SnakeModel extends Observable implements Runnable {
boolean[][] matrix; // 指示位置上有沒蛇體或食物
LinkedList nodeArray = new LinkedList(); // 蛇體
Node food;
int maxX;
int maxY;
int direction = 2; // 蛇運行的方向
boolean running = false; // 運行狀態

int timeInterval = 200; // 時間間隔,毫秒
double speedChangeRate = 0.75; // 每次得速度變化率
boolean paused = false; // 暫停標志

int score = 0; // 得分
int countMove = 0; // 吃到食物前移動的次數

// UP and DOWN should be even
// RIGHT and LEFT should be odd
public static final int UP = 2;
public static final int DOWN = 4;
public static final int LEFT = 1;
public static final int RIGHT = 3;

public SnakeModel( int maxX, int maxY) {
this.maxX = maxX;
this.maxY = maxY;

reset();
}

public void reset(){
direction = SnakeModel.UP; // 蛇運行的方向
timeInterval = 200; // 時間間隔,毫秒
paused = false; // 暫停標志
score = 0; // 得分
countMove = 0; // 吃到食物前移動的次數

// initial matirx, 全部清0
matrix = new boolean[maxX][];
for (int i = 0; i < maxX; ++i) {
matrix[i] = new boolean[maxY];
Arrays.fill(matrix[i], false);
}

// initial the snake
// 初始化蛇體,如果橫向位置超過20個,長度為10,否則為橫向位置的一半
int initArrayLength = maxX > 20 ? 10 : maxX / 2;
nodeArray.clear();
for (int i = 0; i < initArrayLength; ++i) {
int x = maxX / 2 + i;//maxX被初始化為20
int y = maxY / 2; //maxY被初始化為30
//nodeArray[x,y]: [10,15]-[11,15]-[12,15]~~[20,15]
//默認的運行方向向上,所以游戲一開始nodeArray就變為:
// [10,14]-[10,15]-[11,15]-[12,15]~~[19,15]
nodeArray.addLast(new Node(x, y));
matrix[x][y] = true;
}

// 創建食物
food = createFood();
matrix[food.x][food.y] = true;
}

public void changeDirection(int newDirection) {
// 改變的方向不能與原來方向同向或反向
if (direction % 2 != newDirection % 2) {
direction = newDirection;
}
}

/**
* 運行一次
* @return
*/
public boolean moveOn() {
Node n = (Node) nodeArray.getFirst();
int x = n.x;
int y = n.y;

// 根據方向增減坐標值
switch (direction) {
case UP:
y--;
break;
case DOWN:
y++;
break;
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
}

// 如果新坐標落在有效范圍內,則進行處理
if ((0 <= x && x < maxX) && (0 <= y && y < maxY)) {

if (matrix[x][y]) { // 如果新坐標的點上有東西(蛇體或者食物)
if (x == food.x && y == food.y) { // 吃到食物,成功
nodeArray.addFirst(food); // 從蛇頭贈長

// 分數規則,與移動改變方向的次數和速度兩個元素有關
int scoreGet = (10000 - 200 * countMove) / timeInterval;
score += scoreGet > 0 ? scoreGet : 10;
countMove = 0;

food = createFood(); // 創建新的食物
matrix[food.x][food.y] = true; // 設置食物所在位置
return true;
} else // 吃到蛇體自身,失敗
return false;

} else { // 如果新坐標的點上沒有東西(蛇體),移動蛇體
nodeArray.addFirst(new Node(x, y));
matrix[x][y] = true;
n = (Node) nodeArray.removeLast();
matrix[n.x][n.y] = false;
countMove++;
return true;
}
}
return false; // 觸到邊線,失敗
}

public void run() {
running = true;
while (running) {
try {
Thread.sleep(timeInterval);
} catch (Exception e) {
break;
}

if (!paused) {
if (moveOn()) {
setChanged(); // Model通知View數據已經更新
notifyObservers();
} else {
JOptionPane.showMessageDialog(null,
"you failed",
"Game Over",
JOptionPane.INFORMATION_MESSAGE);
break;
}
}
}
running = false;
}

private Node createFood() {
int x = 0;
int y = 0;
// 隨機獲取一個有效區域內的與蛇體和食物不重疊的位置
do {
Random r = new Random();
x = r.nextInt(maxX);
y = r.nextInt(maxY);
} while (matrix[x][y]);

return new Node(x, y);
}

public void speedUp() {
timeInterval *= speedChangeRate;
}

public void speedDown() {
timeInterval /= speedChangeRate;
}

public void changePauseState() {
paused = !paused;
}

public String toString() {
String result = "";
for (int i = 0; i < nodeArray.size(); ++i) {
Node n = (Node) nodeArray.get(i);
result += "[" + n.x + "," + n.y + "]";
}
return result;
}
}

class Node {
int x;
int y;

Node(int x, int y) {
this.x = x;
this.y = y;
}
}
------------------------------------------------------------
4、

package mvcTest;

//SnakeView.java
import javax.swing.*;
import java.awt.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Observable;
import java.util.Observer;

/**
* MVC模式中得Viewer,只負責對數據的顯示,而不用理會游戲的控制邏輯
*/
public class SnakeView implements Observer {
SnakeControl control = null;
SnakeModel model = null;

JFrame mainFrame;
Canvas paintCanvas;
JLabel labelScore;

public static final int canvasWidth = 200;
public static final int canvasHeight = 300;

public static final int nodeWidth = 10;
public static final int nodeHeight = 10;

public SnakeView(SnakeModel model, SnakeControl control) {
this.model = model;
this.control = control;

mainFrame = new JFrame("GreedSnake");

Container cp = mainFrame.getContentPane();

// 創建頂部的分數顯示
labelScore = new JLabel("Score:");
cp.add(labelScore, BorderLayout.NORTH);

// 創建中間的游戲顯示區域
paintCanvas = new Canvas();
paintCanvas.setSize(canvasWidth + 1, canvasHeight + 1);
paintCanvas.addKeyListener(control);
cp.add(paintCanvas, BorderLayout.CENTER);

// 創建底下的幫助欄
JPanel panelButtom = new JPanel();
panelButtom.setLayout(new BorderLayout());
JLabel labelHelp;
labelHelp = new JLabel("PageUp, PageDown for speed;", JLabel.CENTER);
panelButtom.add(labelHelp, BorderLayout.NORTH);
labelHelp = new JLabel("ENTER or R or S for start;", JLabel.CENTER);
panelButtom.add(labelHelp, BorderLayout.CENTER);
labelHelp = new JLabel("SPACE or P for pause", JLabel.CENTER);
panelButtom.add(labelHelp, BorderLayout.SOUTH);
cp.add(panelButtom, BorderLayout.SOUTH);

mainFrame.addKeyListener(control);
mainFrame.pack();
mainFrame.setResizable(false);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
}

void repaint() {
Graphics g = paintCanvas.getGraphics();

//draw background
g.setColor(Color.WHITE);
g.fillRect(0, 0, canvasWidth, canvasHeight);

// draw the snake
g.setColor(Color.BLACK);
LinkedList na = model.nodeArray;
Iterator it = na.iterator();
while (it.hasNext()) {
Node n = (Node) it.next();
drawNode(g, n);
}

// draw the food
g.setColor(Color.RED);
Node n = model.food;
drawNode(g, n);

updateScore();
}

private void drawNode(Graphics g, Node n) {
g.fillRect(n.x * nodeWidth,
n.y * nodeHeight,
nodeWidth - 1,
nodeHeight - 1);
}

public void updateScore() {
String s = "Score: " + model.score;
labelScore.setText(s);
}

public void update(Observable o, Object arg) {
repaint();
}
}
-------------------------------------------------------------

閱讀全文

與貪吃蛇java程序相關的資料

熱點內容
庫房管理系統源碼 瀏覽:59
安卓應用多為什麼會卡 瀏覽:10
php程序員工作職責 瀏覽:306
程序員可以轉行做運維嗎 瀏覽:323
如何檢測到伺服器埠是否通 瀏覽:851
linuxsed正則 瀏覽:109
linux安裝gz文件 瀏覽:357
linux如何卸載編譯的軟體 瀏覽:929
高三解壓活動視頻 瀏覽:780
如何把伺服器卡爆 瀏覽:949
餓了么java程序員 瀏覽:960
python編譯時找不到路徑 瀏覽:910
jpg轉換pdf軟體 瀏覽:103
php讀取json文件 瀏覽:866
螺桿壓縮機的功率計算 瀏覽:74
谷輪壓縮機c 瀏覽:338
蘋果app如何復制到另一個手機 瀏覽:834
javasession超時 瀏覽:831
易金通app怎麼更改手機號 瀏覽:493
plc數控編程的方法 瀏覽:989