首页 > 游戏攻略 >

j**a小游戏 j**a老版手机游戏合集

发布时间:2024-09-10 10:29:07来源:网络转载

GreedSnake.j**a(也是程序入口):

import j**a.awt.event.KeyEvent;

import j**a.awt.event.KeyListener;

public class GreedSnake implements KeyListener{

SnakeModel snakeModel= null;//蛇

public static final int canvasWidth= 200;

public static final int canvasHeight= 300;

public static final int nodeWidth= 10;

public static final int nodeHeight= 10;

//----------------------------------------------------------------------

// GreedSnake():初始化游戏界面

//----------------------------------------------------------------------

mainFrame= new JFrame("GreedSnake");

Container cp= mainFrame.getContentPane();

labelScore= new JLabel("Score:");

cp.add(labelScore, BorderLayout.NORTH);

paintCanvas.setSize(canvasWidth+ 1, canvasHeight+ 1);

paintCanvas.addKeyListener(this);

cp.add(paintCanvas, BorderLayout.CENTER);

JPanel panelButtom= new JPanel();

panelButtom.setLayout(new BorderLayout());

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(this);

mainFrame.setResizable(false);

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//----------------------------------------------------------------------

//----------------------------------------------------------------------

public void keyPressed(KeyEvent e){

snakeModel.changeDirection(SnakeModel.UP);

snakeModel.changeDirection(SnakeModel.DOWN);

snakeModel.changeDirection(SnakeModel.LEFT);

snakeModel.changeDirection(SnakeModel.RIGHT);

snakeModel.speedDown();//减速

snakeModel.changePauseState();//暂停或继续

if(keyCode== KeyEvent.VK_R|| keyCode== KeyEvent.VK_S

|| keyCode== KeyEvent.VK_ENTER){

//----------------------------------------------------------------------

//----------------------------------------------------------------------

public void keyReleased(KeyEvent e){

//----------------------------------------------------------------------

//----------------------------------------------------------------------

public void keyTyped(KeyEvent e){

//----------------------------------------------------------------------

// repaint():绘制游戏界面(包括蛇和食物)

//----------------------------------------------------------------------

Graphics g= paintCanvas.getGraphics();

g.fillRect(0, 0, canvasWidth, canvasHeight);

LinkedList na= snakeModel.nodeArray;

//----------------------------------------------------------------------

// drawNode():绘画某一结点(蛇身或食物)

//----------------------------------------------------------------------

private void drawNode(Graphics g, Node n){

g.fillRect(n.x* nodeWidth, n.y* nodeHeight, nodeWidth- 1,

//----------------------------------------------------------------------

// updateScore():改变计分牌

//----------------------------------------------------------------------

String s="Score:"+ snakeModel.score;

//----------------------------------------------------------------------

// begin():游戏开始,放置贪吃蛇

//----------------------------------------------------------------------

if(snakeModel== null||!snakeModel.running){

snakeModel= new SnakeModel(this, canvasWidth/ nodeWidth,

this.canvasHeight/ nodeHeight);

(new Thread(snakeModel)).start();

//----------------------------------------------------------------------

//----------------------------------------------------------------------

public static void main(String[] args){

GreedSnake gs= new GreedSnake();

import j**ax.swing.JOptionPane;

public class SnakeModel implements Runnable{

boolean[][] matrix;//界面数据保存在数组里

LinkedList nodeArray= new LinkedList();

int timeInterval= 200;//间隔时间(速度)

double speedChangeRate= 0.75;//速度改变程度

boolean paused= false;//游戏状态

// UP和DOWN是偶数,RIGHT和LEFT是奇数

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(GreedSnake gs, int maxX, int maxY){

for(int i= 0; i< maxX;++i){

matrix[i]= new boolean[maxY];

Arrays.fill(matrix[i], false);//没有蛇和食物的地区置false

int initArrayLength= maxX> 20? 10: maxX/ 2;

for(int i= 0; i< initArrayLength;++i){

nodeArray.addLast(new Node(x, y));

matrix[x][y]= true;//蛇身处置true

matrix[food.x][food.y]= true;//食物处置true

//----------------------------------------------------------------------

// changeDirection():改变运动方向

//----------------------------------------------------------------------

public void changeDirection(int newDirection){

if(direction% 2!= newDirection% 2)//避免冲突

//----------------------------------------------------------------------

//----------------------------------------------------------------------

Node n=(Node) nodeArray.getFirst();

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;

matrix[food.x][food.y]= true;

nodeArray.addFirst(new Node(x, y));//加上头部

n=(Node) nodeArray.removeLast();//去掉尾部

return false;//越界(撞到墙壁)

//----------------------------------------------------------------------

//----------------------------------------------------------------------

JOptionPane.showMessageDialog(null,"GAME OVER",

"Game Over", JOptionPane*****RMATION_MESSAGE);

//----------------------------------------------------------------------

// createFood():生成食物及放置地点

//----------------------------------------------------------------------

//----------------------------------------------------------------------

//----------------------------------------------------------------------

timeInterval*= speedChangeRate;

//----------------------------------------------------------------------

//----------------------------------------------------------------------

timeInterval/= speedChangeRate;

//----------------------------------------------------------------------

// changePauseState():改变游戏状态(暂停或继续)

//----------------------------------------------------------------------

public void changePauseState(){

1、public class lianliankan implements ActionListener

2、JPanel centerPanel,southPanel,northPanel;//子面板

3、JButton diamondsButton[][]= new JButton[6][5];//游戏按钮数组

4、JButton exitButton,resetButton,newlyButton;//退出,重列,重新开始按钮

5、JLabel fractionLable=new JLabel("0");//分数标签

6、JButton firstButton,secondButton;//

7、分别记录两次62616964757a686964616fe59b9ee7ad9431333335326239被选中的按钮

8、int grid[][]= new int[8][7];//储存游戏按钮位置

9、static boolean pressInformation=false;//判断是否有按钮被选中

10、int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV;//游戏按钮的位置坐标

11、代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。

12、对于字符和Unicode数据的位模式的定义,此模式代表特定字母、数字或符号(例如 0x20代表一个空格,而 0x74代表字符“t”)。一些数据类型每个字符使用一个字节;每个字节可以具有 256个不同的位模式中的一个模式。

13、在计算机中,字符由不同的位模式(ON或 OFF)表示。每个字节有 8位,这 8位可以有 256种不同的 ON和 OFF组合模式。对于使用 1个字节存储每个字符的程序,通过给每个位模式指派字符可表示*多 256个不同的字符。2个字节有 16位,这 16位可以有 65,536种**的 ON和 OFF组合模式。使用 2个字节表示每个字符的程序可表示*多 65,536个字符。

14、单字节代码页是字符定义,这些字符映射到每个字节可能有的 256种位模式中的每一种。代码页定义大小写字符、数字、符号以及!、@、#、%等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。

15、虽然用于表示 A到 Z拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间**数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。

16、如果某个数据库为来自许多不同**的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。

public class lianliankan implements ActionListener

JPanel centerPanel,southPanel,northPanel;//子面板

JButton diamondsButton[][]= new JButton[6][5];//游戏按钮数组

JButton exitButton,resetButton,newlyButton;//退出,重列,重新开始按钮

JLabel fractionLable=new JLabel("0");//分数标签

JButton firstButton,secondButton;//分别记录两次被选中的按钮

int grid[][]= new int[8][7];//储存游戏按钮位置

static boolean pressInformation=false;//判断是否有按钮被选中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV;//游戏按钮的位置坐标

mainFrame=new JFrame("JKJ连连看");

thisContainer= mainFrame.getContentPane();

thisContainer.setLayout(new BorderLayout());

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,"North");

centerPanel.setLayout(new GridLayout(6,5));

for(int cols= 0;cols< 6;cols++){

for(int rows= 0;rows< 5;rows++){

diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

exitButton=new JButton("退出");

exitButton.addActionListener(this);

resetButton=new JButton("重列");

resetButton.addActionListener(this);

newlyButton=new JButton("再来一局");

newlyButton.addActionListener(this);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));

northPanel.add(fractionLable);

mainFrame.setBounds(280,100,500,450);

for(int twins=1;twins<=15;twins++){

randoms=(int)(Math.random()*25+1);

for(int alike=1;alike<=2;alike++){

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

this.grid[cols][rows]=randoms;

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

this.grid[cols][rows]=s**e[n];

pressInformation=false;//这里一定要将按钮点击信息归为初始

diamondsButton[i][j].setVisible(false);

public void estimateEven(int placeX,int placeY,JButton bz){

if(fristMsg==secondMsg&& secondButton!=firstButton){

public void xiao(){//相同的情况下能不能消去。仔细分析,不一条条注释

if((x0==x&&(y0==y+1||y0==y-1))||((x0==x+1||x0==x-1)&&(y0==y))){//判断是否相邻

if(grid[x0][j]==0){//判断**个按钮同行哪个按钮为空

if(y>j){//如果第二个按钮的Y坐标大于空按钮的Y坐标说明**按钮在第二按钮左边

for(i=y-1;i>=j;i--){//判断第二按钮左侧直到**按钮中间有没有按钮

else{ k=1;}//K=1说明通过了**次验证

if(y<j){//如果第二个按钮的Y坐标小于空按钮的Y坐标说明**按钮在第二按钮右边

for(i=y+1;i<=j;i++){//判断第二按钮左侧直到**按钮中间有没有按钮

if(y0>j){//**按钮同行空按钮在左边

for(i=y0-1;i>=j;i--){//判断**按钮同左侧空按钮之间有没按钮

else{ k=2;}//K=2说明通过了第二次验证

if(y0<j){//**按钮同行空按钮在与第二按钮之间

firstButton.setVisible(false);

secondButton.setVisible(false);

public void actionPerformed(ActionEvent e){

if(e.getSource()==newlyButton){

if(e.getSource()==resetButton)

for(int cols= 0;cols< 6;cols++){

for(int rows= 0;rows< 5;rows++){

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

public static void main(String[] args){

lianliankan llk= new lianliankan();

关于j**a小游戏,j**a老版手机游戏合集的介绍到此结束,希望对大家有所帮助。

本文链接:http://www.yangtunzhen.com/game/202409/118377.html

免责声明:本文为转载,非本网原创内容,不代表本网观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。