搜档网
当前位置:搜档网 › 扫雷游戏Java源代码详解

扫雷游戏Java源代码详解

扫雷游戏Java源代码详解
扫雷游戏Java源代码详解

扫雷游戏Java源代码

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.Font;

import java.awt.GridLayout;

import java.awt.Insets;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JPanel;

import javax.swing.Timer;

public class ScanLei1 extends JFrame implements ActionListener{

private static final long serialVersionUID = 1L;

private Container contentPane;

private JButton btn;

private JButton[] btns;

private JLabel b1;

private JLabel b2;

private JLabel b3;

private Timer timer;

private int row=9;

private int col=9;

private int bon=10;

private int[][] a;

private int b;

private int[] a1;

private JPanel p,p1,p2,p3;

public ScanLei1(String title){

super(title);

contentPane=getContentPane();

setSize(297,377);

this.setBounds(400, 100, 400, 500);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

timer =new Timer(1000,(ActionListener) this);

a = new int[row+2][col+2];

initGUI();

}

public void initGUI(){

p3=new JPanel();

b=bon;

JMenuBar menuBar=new JMenuBar();

JMenu menu1=new JMenu("游戏");

JMenu menu2=new JMenu("帮助");

JMenuItem mi1=new JMenuItem("初级");

JMenuItem mi2 = new JMenuItem("中级");

JMenuItem mi3 =new JMenuItem("高级");

mi1.addActionListener(this);

menu1.add(mi1);

mi2.addActionListener(this);

menu1.add(mi2);

mi3.addActionListener(this);

menu1.add(mi3);

menuBar.add(menu1);

menuBar.add(menu2);

p3.add(menuBar);

b1=new JLabel(bon+"");

a1=new int[bon];

btn =new JButton("开始");

btn.addActionListener(this);

b2=new JLabel("0");

b3=new JLabel("");

btns=new JButton[row*col];

p=new JPanel();

p.setLayout(new BorderLayout());

contentPane.add(p);

p.add(p3,BorderLayout.NORTH);

//combo=new JComboBox(new Object[]{"初级","中级","高级"} );

//加监听

/*combo.addItemListener(new ItemListener(){

}});*/

p1=new JPanel();

//在那个位置

//(( FlowLayout)p1.getLayout()).setAlignment( FlowLayout.RIGHT);

p1.add(b1);

p1.add(btn);

p1.add(b2);

p1.add(b3);

p.add(p3,BorderLayout.NORTH);

p.add(p1,BorderLayout.CENTER);

p2=new JPanel();

p2.setLayout(new GridLayout(row,col,0,0));

for(int i=0;i

btns[i]=new JButton("");

btns[i].setMargin(new Insets(0,0,0,0));

btns[i].setFont(new Font(null,Font.BOLD,25));

btns[i].addActionListener(this);

btns[i].addMouseListener(new NormoreMouseEvent());

p2.add(btns[i]);

}

contentPane.add(p,BorderLayout.NORTH);

contentPane.add(p2,BorderLayout.CENTER);

}

public void go(){

setVisible(true);

}

public static void main(String[] args){

new ScanLei1("扫雷").go();

}

public void out(int[][] a,JButton[] btns,ActionEvent e,int i,int x,int y){

int p=1;

if(a[x][y]==0){

a[x][y]=10;

btns[i].setEnabled(false); //33

for(int l=y-1;l<=y+1;l++){

int m=x-1-1;

int n=l-1;

p=1;

System.out.println(a[1][2]);

if(n>-1&&n-1&&m

{

for(int q=0;qrow;

if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){

if(a[x-1][l]!=0&&a[x-1][l]!=10){

btns[n+col*q].setText(a[x-1][l]+"");

a[x-1][l]=10;

btns[n+col*q].setEnabled(false);

}

else if(a[x-1][l]==0){

//a[x-1][l]=10;

btns[n+col*q].setEnabled(false);

out(a,btns,e,n+col*q,x-1,l);

////55////

a[x-1][l]=10;

btns[n+col*q].setEnabled(false);

}

p=0;

}

}

}

p=1;

m=x;

if(n>-1&&n-1&&m

{

for(int q=0;q

if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){

if(a[x+1][l]!=0&&a[x+1][l]!=10){

btns[n+col*q].setText(a[x+1][l]+"");

a[x+1][l]=10;

btns[n+col*q].setEnabled(false);

}

else if(a[x+1][l]==0){

out(a,btns,e,n+col*q,x+1,l);///55////

a[x+1][l]=10;

btns[n+col*q].setEnabled(false);

}

p=0;

}

}

}

}

int m=x-1;

int n=y-1-1;

if(n>-1&&n-1&&m

{

for(int q=0;q

if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){

if(a[x][y-1]!=0&&a[x][y-1]!=10){

btns[n+col*q].setText(a[x][y-1]+"");

a[x][y-1]=10;

btns[n+col*q].setEnabled(false);

}

else if(a[x][y-1]==0){

out(a,btns,e,n+col*q,x,y-1);

a[x][y-1]=10;

btns[n+col*q].setEnabled(false);

}

p=0;

}

}

}

p=1;

m=x-1;

n=y+1-1;

if(n>-1&&n-1&&m

{

for(int q=0;q

if(((n+col*q)>=(m*col))&&((n+col*q)<(m+1)*col)){

if(a[x][y+1]!=0&&a[x][y+1]!=10){

btns[n+col*q].setText(a[x][y+1]+"");

a[x][y+1]=10;

btns[n+col*q].setEnabled(false);

}

else if(a[x][y+1]==0){

out(a,btns,e,n+col*q,x,y+1);

a[x][y+1]=10;

btns[n+col*q].setEnabled(false);

}

p=0;

}

}

}

}

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand()=="初级"){

row=9;

col=9;

bon=10;

a1=new int[bon];

b=bon;

//setSize(297,377);

a = new int[row+2][col+2];

this.remove(p2);

timer.stop();

b1.setText("10");

b2.setText("0");

b3.setText("");

btns=new JButton[row*col];

p2=new JPanel();

p2.setLayout(new GridLayout(row,col,0,0));

for(int i=0;i

btns[i]=new JButton(" ");

btns[i].setMargin(new Insets(0,0,0,0));

btns[i].setFont(new Font(null,Font.BOLD,25));

btns[i].addActionListener(this);

btns[i].addMouseListener(new NormoreMouseEvent());

p2.add(btns[i]);

}

contentPane.add(p2,BorderLayout.CENTER);

//setSize(297,377);

this.pack();

for(int i=0;i

btns[i].setText(" ");

btns[i].setEnabled(true);

}

for(int i=0;i

for(int j=0;j

a[i][j]=0;

}

}

}else if(e.getActionCommand()=="中级"){

row=16;

col=16;

bon=40;

//setSize(33*col,33*row+80);

a1=new int[bon];

a = new int[row+2][col+2];

b=bon;

this.remove(p2);

timer.stop();

b1.setText("40");

b2.setText("0");

b3.setText("");

btns=new JButton[row*col];

p2=new JPanel();

p2.setLayout(new GridLayout(row,col,0,0));

for(int i=0;i

btns[i]=new JButton(" ");

btns[i].setMargin(new Insets(0,0,0,0));

btns[i].setFont(new Font(null,Font.BOLD,25));

btns[i].addActionListener(this);

btns[i].addMouseListener(new NormoreMouseEvent());

p2.add(btns[i]);

}

contentPane.add(p2,BorderLayout.CENTER);

this.pack();

//setSize(33*col,33*row+80);

for(int i=0;i

btns[i].setText("");

btns[i].setEnabled(true);

}

for(int i=0;i

for(int j=0;j

a[i][j]=0;

}

}

}else if(e.getActionCommand()=="高级"){

row=16;

col=32;

bon=99;

setSize(33*col,33*row+80);

a1=new int[bon];

a = new int[row+2][col+2];

b=bon;

this.remove(p2);

timer.stop();

b1.setText("99");

b2.setText("0");

b3.setText("");

btns=new JButton[row*col];

p2=new JPanel();

p2.setLayout(new GridLayout(row,col,0,0));

for(int i=0;i

btns[i]=new JButton(" ");

btns[i].setMargin(new Insets(0,0,0,0));

btns[i].setFont(new Font(null,Font.BOLD,25));

btns[i].addActionListener(this);

btns[i].addMouseListener(new NormoreMouseEvent());

p2.add(btns[i]);

}

contentPane.add(p2,BorderLayout.CENTER);

//setSize(33*col,33*row+80);

this.pack();

for(int i=0;i

btns[i].setText("");

btns[i].setEnabled(true);

}

for(int i=0;i

for(int j=0;j

a[i][j]=0;

}

}

}

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

timer.start();

b=bon;

b3.setText("");

//System.out.println(bon);

//清空

for(int i=0;i

btns[i].setText("");

btns[i].setEnabled(true);

}

for(int i=0;i

for(int j=0;j

a[i][j]=0;

}

}

//产生随机数

for(int i=0;i

{ int p=1;

int m=(int)(Math.random()*row*col);

while(p==1){

int l=1;

int j;

for( j=0;j

if(a1[j]==m){

m=(int)(Math.random()*row*col);

l=0;

}

}

if(j==i){

a1[i]=m;

p=0;

}

}

}

b1.setText(bon+"");

b2.setText("0");

//布雷

for(int i=0;i

int x=(a1[i]/col+1);

int y=(a1[i]%col+1);

a[x][y]=100;

}

for(int i=0;i

for(int j=0;j

if(i==0||j==0||i==row+1||j==col+1){

a[i][j]=0;

}

}

}

for(int i=1;i<=row;i++){

for(int j=1;j<=col;j++){

if(a[i][j]!=100){

for(int l=j-1;l<=j+1;l++){

if(a[i-1][l]==100){

a[i][j]++;

}

if(a[i+1][l]==100){

a[i][j]++;

}

}

if(a[i][j-1]==100){

a[i][j]++;

}

if(a[i][j+1]==100){

a[i][j]++;

}

}

}

}

}

if(e.getSource()==timer)

{

String time=b2.getText().trim();

int t=Integer.parseInt(time);

//System.out.println(t);

if(t>=600){

timer.stop();

}else{

t++;

b2.setText(t+"");

}

}

for(int i=0;i

if(btns[i].getText()!="★")

{

int x=i/col+1;

int y=i%col+1;

if(e.getSource()==btns[i]&&a[x][y]==100){

btns[i].setText("★");

btns[i].setEnabled(false);

a[x][y]=10;

for(int k=0;k

int m1=k/col+1;

int n1=k%col+1;

if(a[m1][n1]!=10&&btns[k].getText()=="★"){

btns[k].setText("*o*");

}

}

for(int j=0;j

int m=j/col+1;

int n=j%col+1;

if(a[m][n]==100){

btns[j].setText("★");

btns[j].setEnabled(false);

b3.setText("你输了!!");

}

btns[j].setEnabled(false);

a[m][n]=10;

}

timer.stop();

}

else if(e.getSource()==btns[i]){

if(a[x][y]==0){

out(a,btns,e,i,x,y);

a[x][y]=10;

btns[i].setEnabled(false);

}

if(a[x][y]!=0&&a[x][y]!=10){

btns[i].setText(a[x][y]+"");

btns[i].setEnabled(false);

a[x][y]=10;

}

}

}else if(btns[i].getText()=="★"){

}

}

}

class NormoreMouseEvent extends MouseAdapter{

public void mouseClicked(MouseEvent e) {

System.out.println(b);

for(int i=0;i

int x1=i/col+1;

int y1=i%col+1;

if(e.getSource()==btns[i]&&btns[i].getText()!="★"&&a[x1][y1]!=10) {

if(e.getButton()==MouseEvent.BUTTON3){

btns[i].setText("★");

b--;

if(b==0){

int flag=0;

for(int j=0;j

int x=j/col+1;

int y=j%col+1;

if(a[x][y]==100&&btns[j].getText()=="★"){

flag++;

}

}

if(flag==bon){

timer.stop();

b3.setText("你赢了!");

}

}

b1.setText(b+"");

}

}else

if(e.getSource()==btns[i]&&btns[i].getText()=="★"&&a[x1][y1]!=-1){

if(e.getButton()==MouseEvent.BUTTON3){

btns[i].setText("");

b++;

if(b>bon){

b1.setText(bon+"");

}

else{

b1.setText(b+"");

}

btns[i].setEnabled(true);

}

}

}

}

}

}

FLASH游戏之贪吃蛇游戏源代码

scorecommand("allowscale", "false"); fscommand("showmenu", "false"); loadedbytes=0; total=_root.getBytesTotal(); loadedbytes=_root.getBytesLoaded() if (loadedbytes==total){nextScene();} else{bfb=int((loadedbytes/total*100))+"%";} stop(); fscommand("allowscale", "false"); fscommand("showmenu", "false"); music=new Sound() music.attachSound("music"); music.stop() music.start(0,10000) musicstart=true onClipEvent(keyDown){ temp=Key.getCode(); if(!keyon){;} else if(game=="stop" and (temp==189 or temp==109)){ if (speed>1) { speed--; rate = speed;}} else if (game=="stop" and (temp==107 or temp==187)) { if (speed"start"){enter(); }else if(temp==Key.ENTER){ enter(); }else if (temp == Key.DOWN and y1>=0) { x1=0; y1 = 1; walk(); timestart() }else if (temp == Key.UP and y1<=0) { x1=0; y1 = -1; walk(); timestart() }else if (temp == Key.LEFT and x1<=0) {

Java五子棋游戏源代码(人机对战)

//Java编程:五子棋游戏源代码 import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import java.io.PrintStream; import javax.swing.JComponent; import javax.swing.JPanel; /* *main方法创建了ChessFrame类的一个实例对象(cf), *并启动屏幕显示显示该实例对象。 **/ public class FiveChessAppletDemo { public static void main(String args[]){ ChessFrame cf = new ChessFrame(); cf.show(); } } /* *类ChessFrame主要功能是创建五子棋游戏主窗体和菜单**/ class ChessFrame extends JFrame implements ActionListener { private String[] strsize={"20x15","30x20","40x30"}; private String[] strmode={"人机对弈","人人对弈"}; public static boolean iscomputer=true,checkcomputer=true; private int width,height; private ChessModel cm; private MainPanel mp; //构造五子棋游戏的主窗体 public ChessFrame() { this.setTitle("五子棋游戏"); cm=new ChessModel(1); mp=new MainPanel(cm); Container con=this.getContentPane(); con.add(mp,"Center"); this.setResizable(false); this.addWindowListener(new ChessWindowEvent()); MapSize(20,15); JMenuBar mbar = new JMenuBar(); this.setJMenuBar(mbar); JMenu gameMenu = new JMenu("游戏");

扫雷的课程设计报告

西安文理学院信息工程学院课程设计报告 设计名称:数据结构课程设计 设计题目:实现一个N*M的扫雷游戏 学生学号:1402130407 专业班级:软件13级四班 学生姓名:樊秀琳 学生成绩: 指导教师(职称):谢巧玲(讲师) 课题工作时间:2015.6.22 至2015.7.3

说明: 1、报告中的任务书、进度表由指导教师在课程设计开始前填写并发给每个 学生。 2、学生成绩由指导教师根据学生的设计情况给出各项分值及总评成绩。 3、所有学生必须参加课程设计的答辩环节,凡不参加答辩者,其成绩一律 按不及格处理。答辩由指导教师实施。 4、报告正文字数一般应不少于3000字,也可由指导教师根据本门综合设 计的情况另行规定。 5、平时表现成绩低于6分的学生,取消答辩资格,其本项综合设计成绩按 不及格处理。

信息工程学院课程设计任务书 指导教师:院长: 日期:2015年6月22日

信息工程学院课程设计进度安排表 学生姓名:樊秀琳学号:1402130407 专业:软件工程班级:13级四班 指导教师签名: 2014年6月22日

成绩评定表 学生姓名:樊秀琳学号:1402130407 专业:软件工程班级:13级四班

摘要 摘要: 扫雷游戏是Windows操作系统自带的一款小游戏,在过去的几年里,Windows操作系统历经数次换代更新,变得越来越庞大、复杂,功能也越来越强大,但是这款小游戏依然保持原来的容貌,可见这款小游戏受到越来越多人的喜爱。扫雷游戏是比较经典的一款小游戏,实现它的方法很多,可以用很多不同算法设计和语言实现,如C,C++,VB,JAVA等。我利用eclipse编写了与它功能相似的扫雷游戏,寓学于乐。 程序的功能是随机生成地雷数,通过鼠标操作玩游戏,不接受键盘,按任意键结束程序。单击屏幕上的笑脸可以重新开始游戏。所有地雷标出后胜利,当鼠标左键单击到地雷时提示游戏失败。其功能类似于Windows操作系统自带的扫雷游戏。论文首先介绍了进行该游戏课程设计的目的,然后是任务描述和设计的相关要求,最后是最重要的需求分析和设计方案。重点介绍了在游戏过程中各事件的处理,其中又以鼠标事件和清除未靠近地雷区方块这两方面最为最要,鼠标事件是利用鼠标所发出的信息了解用户的意图,进而做出相对应的动作。清除未靠近地雷区的方块较为复杂。 关键词:算法设计;事件;Eclipse

Java语言 扫雷游戏完整源代码

import javax.swing.ImageIcon; public class Block { String name; //名字,比如"雷"或数字int aroundMineNumber; //周围雷的数目 ImageIcon mineIcon; //雷的图标 boolean isMine=false; //是否是雷 boolean isMark=false; //是否被标记 boolean isOpen=false; //是否被挖开 public void setName(String name) { https://www.sodocs.net/doc/2c14360818.html,=name; } public void setAroundMineNumber(int n) { aroundMineNumber=n; } public int getAroundMineNumber() { return aroundMineNumber; } public String getName() { return name; } public boolean isMine() { return isMine; } public void setIsMine(boolean b) { isMine=b; } public void setMineIcon(ImageIcon icon){ mineIcon=icon; } public ImageIcon getMineicon(){ return mineIcon; }

public boolean getIsOpen() { return isOpen; } public void setIsOpen(boolean p) { isOpen=p; } public boolean getIsMark() { return isMark; } public void setIsMark(boolean m) { isMark=m; } } import java.util.*; import javax.swing.*; public class LayMines{ ImageIcon mineIcon; LayMines() { mineIcon=new ImageIcon("mine.gif"); } public void layMinesForBlock(Block block[][],int mineCount){ int row=block.length; int column=block[0].length; LinkedList list=new LinkedList(); for(int i=0;i0){ int size=list.size(); // list返回节点的个数 int randomIndex=(int)(Math.random()*size);

汇编语言写的贪吃蛇小游戏源代码

DATA SEGMENT dw 0,0 snk db 1 blk db 32 food db 3 tal1 db 4 tal2 db 2 adrs db 5 len db ? pst db ? addrs dw ? frow db ? fcol db ? hwrt db ? gmov db 'game over press r to restart press q to quit $' score1 db 'score :$' score2 db ? score0 db 1 zero db 48 writer db 'Developer: Geniusdot $' email db ': geniusdotgmail.$' msg1 db 'The way to play the game:$' way db ' press w to up ,press s to down,press a to left,press d to right$' msg db 'Press any key(except a,s,d,w) to start$' DATA ENDS STACK SEGMENT stack db 200 dup(0) STACK ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK start: mov ax,data mov ds,ax mov ax,0 mov es,ax mov frow,10 mov fcol,6 mov dh,10 mov dl,26 mov ah,2

int 10h mov ah,9 lea dx,msg1 int 21h mov dh,11 mov dl,7 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,way int 21h mov dh,12 mov dl,20 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,msg int 21h mov ah,0 int 16h mov ah,6 mov al,0 mov ch,0 mov cl,0 mov dh,24 mov dl,79 mov bh,10 int 10h mov dh,0 mov dl,0 mov ah,2 mov bh,0 int 10h mov ah,9 lea dx,score1 int 21h mov dl,15 mov ah,2 mov bh,0 int 10h

基于Java五子棋游戏的设计源代码及全套资料

分类号: U D C:D10621-408-(2007)5738-0 密级:公开编号:21 成都信息工程学院 学位论文 基于Java的五子棋游戏的设计 论文作者姓名:赵小龙 申请学位类别:计算机科学与技术 申请学位类别:工学学士 指导教师姓名(职称):吴春旺 论文提交日期:2007年06月10日

基于Java的五子棋游戏的设计 摘要 五子棋作为一个棋类竞技运动,在民间十分流行,为了熟悉五子棋规则及技巧,以及研究简单的人工智能,决定用Java开发五子棋游戏。主要完成了人机对战和玩家之间联网对战2个功能。网络连接部分为Socket编程应用,客户端和服务器端的交互用Class Message定义,有很好的可扩展性,客户端负责界面维护和收集用户输入的信息,及错误处理。服务器维护在线用户的基本信息和任意两个对战用户的棋盘信息,动态维护用户列表。在人机对弈中通过深度搜索和估值模块,来提高电脑棋手的智能。分析估值模块中的影响精准性的几个要素,以及提出若干提高精准性的办法,以及对它们搜索的节点数进行比较,在这些算法的基础上分析一些提高电脑AI方案,如递归算法、电脑学习等。算法的研究有助于理解程序结构,增强逻辑思维能力,在其他人工智能方面也有很大的参考作用。 关键词:深度搜索;估值;电脑AI;五子棋;算法

Gobang Java-based games design Abstract As a sport, gobang is very popular in civil, in order to become familiar with gobang rules and techniques, and the study of simple artificial intelligence, I decide to use the Java to develope gobang games and complete the two functions including man-machine war and man-man war. Network Connection is Socket Programming for some applications, client and server interaction is definited by Class Message, which is a very good scalability, Client interface is responsible for the collection and maintenance of user input information, and error handling. Server users maintain online basic information and arbitrary two-time users of the chessboard of information, dynamic maintenance user list. During the man-machine players, it improves intelligence of the computer players through depth search and valuation module. Analyzes Module valuation of the precise elements, as well as a number of increased precision, and compares their search for nodes, which raises some computer AI programs on the basis of analysis, such as recursive algorithm, computer learning. Algorithm of procedures contribute to the understanding of the structure, logical thinking ability, In other areas of artificial intelligence has great references. . Key words:Search depth; Valuation; Computer AI; Gobang ; Algorithm

五子棋游戏代码(Java语言)

五子棋游戏代码(Java语言) import java.awt.*; import java.awt.event.*; import javax.swing.*; class mypanel extends Panel implements MouseListener { int chess[][] = new int[11][11]; boolean Is_Black_True; mypanel() { Is_Black_True=true; for(int i=0;i<11;i++) { for(int j=0;j<11;j++) { chess[i][j] = 0; } } addMouseListener(this); setBackground(Color.RED); setBounds(0, 0, 360, 360); setVisible(true); } public void mousePressed(MouseEvent e) { int x = e.getX(); int y = e.getY(); if(x < 25 || x > 330 + 25 ||y < 25 || y > 330+25) {return;} if(chess[x/30-1][y/30-1] != 0) {return;} if(Is_Black_True==true) { chess[x/30-1][y/30-1] = 1; Is_Black_True=false; repaint(); Justisewiner(); return; }

if(Is_Black_True==false) { chess[x/30-1][y/30-1]=2; Is_Black_True=true; repaint(); Justisewiner(); return; } } void Drawline(Graphics g) { for(int i=30;i<=330;i+=30) { for(int j = 30;j <= 330; j+= 30) { g.setColor(Color.GREEN); g.drawLine(i, j, i, 330); } } for(int j = 30;j <= 330;j+=30) { g.setColor(Color.GREEN); g.drawLine(30, j, 330, j); } } void Drawchess(Graphics g) { for(int i=0;i < 11;i++) { for(int j = 0;j < 11;j++) { if(chess[i][j] == 1) { g.setColor(Color.BLACK); g.fillOval((i+1)*30-8, (j+1)*30-8, 16, 16); } if(chess[i][j]==2) { g.setColor(Color.WHITE); g.fillOval((i+1)*30-8, (j + 1) * 30-8, 16, 16); }

Java扫雷游戏源代码

import java.awt.BorderLayout; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.Timer; public class ScanLei1 extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private Container contentPane; private JButton btn; private JButton[] btns; private JLabel b1; private JLabel b2; private JLabel b3; private Timer timer; private int row=9; private int col=9; private int bon=10; private int[][] a; private int b; private int[] a1; private JPanel p,p1,p2,p3; public ScanLei1(String title){ super(title); contentPane=getContentPane(); setSize(297,377); this.setBounds(400, 100, 400, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); timer =new Timer(1000,(ActionListener) this); a = new int[row+2][col+2]; initGUI(); } public void initGUI(){ p3=new JPanel();

贪吃蛇游戏实现思路及源代码

HTML5 贪吃蛇游戏实现思路及源代码 点评:游戏难点是怎么模拟贪吃蛇的移动。如果只是一个方块的话显然很简单。但是当蛇的长度变长之后要怎么样控制,下面为大家简要介绍下具体的实现,感兴趣的朋友可以参考下,希望对大家有所帮助 游戏操作说明 通过方向键控制贪吃蛇上下左右移动。贪吃蛇吃到食物之后会变长一个长度。 游戏具体实现 游戏难点是怎么模拟贪吃蛇的移动。如果只是一个方块的话显然很简单。但是当蛇的长度变长之后要怎么样控制 每个方块的移动呢? 如果观察蛇的移动,可以发现,从蛇的头部到尾部,每个方块在下一时刻的位置就是它的前一个方块在当前时刻 的位置。因此我们需要做的只是控制贪吃蛇的头部的运动。其他部分的位置都可以依次类推。 另外一个值得注意的问题是 贪吃蛇吃下食物之后,新增加的方块应该放在哪个位置。 答案就是在下一时刻,新增加的方块应该出现在当前时刻的尾部位置。 因此,在吃下食物之后应该在更新蛇的每个位置之前,增加一个方块,并且将其位置设定在当前时刻的尾部位置。 然后在当前时刻更新出了新增方块之外的所有方块的位置 index.html snake.js 复制代码代码如下: var canvas; var ctx; var timer; //measures var x_cnt = 15; var y_cnt = 15;

var unit = 48; var box_x = 0; var box_y = 0; var box_width = 15 * unit; var box_height = 15 * unit; var bound_left = box_x; var bound_right = box_x + box_width; var bound_up = box_y; var bound_down = box_y + box_height; //images var image_sprite; //objects var snake; var food; var food_x; var food_y; //functions function Role(sx, sy, sw, sh, direction, status, speed, image, flag) { this.x = sx; this.y = sy; this.w = sw; this.h = sh; this.direction = direction; this.status = status; this.speed = speed; this.image = image; this.flag = flag; } function transfer(keyCode) { switch (keyCode) { case 37: return 1; case 38: return 3; case 39: return 2; case 40: return 0; } } function addFood()

C程序课程设计报告(扫雷游戏)

C程序设计 扫雷游戏 一、设计题目:扫雷游戏 二、设计目的 1.使学生更深入地理解和掌握该课程中的有关基本概念,程序设计思想和方法。 2.培养学生综合运用所学知识独立完成课题的能力。 3.培养学生勇于探索、严谨推理、实事求是、有错必改,用实践来检验理论,全方位考虑问题等科学技术人员应具有的素质。 4.提高学生对工作认真负责、一丝不苟,对同学团结友爱,协作攻关的基

本素质。 5.培养学生从资料文献、科学实验中获得知识的能力,提高学生从别人经验中找到解决问题的新途径的悟性,初步培养工程意识和创新能力。 6.对学生掌握知识的深度、运用理论去处理问题的能力、实验能力、课程设计能力、书面及口头表达能力进行考核。 三、设计要求 1.汪洋和孔维亮组成设计小组。小组成员分工协作完成。要求每个成员有自己相对独立的模块,同时要了解其他组员完成的内容。 2.查阅相关资料,自学具体课题中涉及到的新知识。 3.采用结构化、模块化程序设计方法,功能要完善,界面要美观。 4.按要求写出课程设计报告,并于设计结束后1周内提交。 一概述 1)掌握数组指针的概念及其应用 2)培养团结合作精神 2. 课程设计的要求 要求我们有扎实的C语言知识,以及良好的编程习惯,能够熟练的应用循环,有毅力,还要求我们有较强的合作精神,善于总结。同时还要求我们自学C语言作图部分知识。在必要时还要上网查相关资料。 3.课程设计的主要设计思想 扫雷游戏主要用了一个10行10列的二维数组,刚开始利用random随机布雷。 每一个程序最主要的是算法。扫雷游戏算法的重点是一开始统计好每个格子周围有多少雷,当鼠标左键点在格子上时做出判断,如果周围8个格子有雷则显示出雷数,如果没有雷则显示空白格(在四个角的格子显示周围3个格子,其它边缘的格子显示周围5个的状态),我们在主函数中用两个for语句来判断周围雷数。我们还加了鼠标处理函数。 如果格子上有雷则调用函FailExitGame(),显示“Fail!”,游戏结束。若所有的雷都标出,且所有的格子都处理过,则调用函数ExitGame(),显示“OK,Good!”,游戏结束。游戏结束后,按任意键出去。

C语言扫雷源代码

C语言扫雷源代码.txt如果背叛是一种勇气,那么接受背叛则需要更大的勇气。爱情是块砖, 婚姻是座山。砖不在多,有一块就灵;山不在高,守一生就行。 #include #include #include #include /*鼠标信息宏定义*/ #define WAITING 0xff00 #define LEFTPRESS 0xff01 #define LEFTCLICK 0xff10 #define LEFTDRAG 0xff19 #define RIGHTPRESS 0xff02 #define RIGHTCLICK 0xff20 #define RIGHTDRAG 0xff2a #define MIDDLEPRESS 0xff04 #define MIDDLECLICK 0xff40 #define MIDDLEDRAG 0xff4c #define MOUSEMOVE 0xff08 struct { int num;/*格子当前处于什么状态,1有雷,0已经显示过数字或者空白格子*/ int roundnum;/*统计格子周围有多少雷*/ int flag;/*右键按下显示红旗的标志,0没有红旗标志,1有红旗标志*/ }Mine[10][10]; int gameAGAIN=0;/*是否重来的变量*/ int gamePLAY=0;/*是否是第一次玩游戏的标志*/ int mineNUM;/*统计处理过的格子数*/ char randmineNUM[3];/*显示数字的字符串*/ int Keystate; int MouseExist; int MouseButton; int MouseX; int MouseY; int up[16][16],down[16][16],mouse_draw[16][16],pixel_save[16][16]; void MouseMath()/*计算鼠标的样子*/ {int i,j,jj,k; long UpNum[16]={ 0x3fff,0x1fff,0x0fff,0x07ff, 0x03ff,0x01ff,0x00ff,0x007f, 0x003f,0x00ff,0x01ff,0x10ff,

贪吃蛇小游戏源代码

#include #include #include #include int head=3 ,tail=0; int main() { int i,j,k=0; int zuobiao[2][80]; long start; int direction=77; int gamespeed; int timeover; int change(char qipan[20][80],int zuobiao[2][80],char direction); zuobiao[0][tail]=1;zuobiao[1][tail]=1;zuobiao[0][1]=1;zuobiao[1][1]=2;zuobiao[0][2]=1;zuobiao[ 1][2]=3;zuobiao[0][head]=1;zuobiao[1][head]=4; /*处理棋盘*/ char qipan[20][80];//定义棋盘 for(i=0;i<20;i++) for(j=0;j<80;j++) qipan[i][j]=' ';//初始化棋盘 for(i=0;i<80;i++) qipan[0][i]='_'; for(i=0;i<20;i++) qipan[i][0]='|'; for(i=0;i<20;i++) qipan[i][79]='|'; for(i=0;i<80;i++) qipan[19][i]='_'; qipan[1][1]=qipan[1][2]=qipan[1][3]='*';//初始化蛇的位置 qipan[1][4]='#'; printf("This is a game of a SNAKE.\nGOOD LUCK TO YOU !\n"); printf("Input your game speed,please.(e.g.300)\n"); scanf("%d",&gamespeed); while(direction!='q') { system("cls"); for(i=0;i<20;i++)//打印出棋盘 for(j=0;j<80;j++) printf("%c",qipan[i][j]); timeover=1;

游戏开发课程设计报告模版-扫雷游戏报告(定稿)

中原工学院信息商务学院 课程设计报告 2016~2017学年第一学期 课程游戏开发课程设计 课程设计名称扫雷游戏 学生姓名*** 学号***** 专业班级数媒141 指导教师郑全录 2016年12月

目录 第一章设计内容及要求 (1) 1.1 扫雷游戏的基本要求 (1) 1.2 游戏需要实现的主要功能 (1) 第二章需求分析 (2) 2.1扫雷游戏界面设计 (2) 2.2 雷区的设计 (2) 2.3 音效的设计 (3) 2.4 扫雷英雄榜的设计 (3) 第三章总体设计 (5) 3.1 总体功能图 (5) 3.2 总体流程图 (5) 第四章主要功能设计流程 (6) 4.1 雷区设计流程图 (6) 4.2 音效设计流程图 (6) 4.3 英雄榜设计流程图 (7) 第五章主要功能设计流程 (8) 5.1 类之间关系图 (8) 5.2程序运行效果图 (8) 5.2.1 游戏登录界面 (8) 5.2.2游戏菜单界面 (9) 5.2.3游戏运行界面 (10) 5.2.4游戏英雄榜界面 (12) 第六章总结 (13) 参考文献 (14) 附录 (15)

第一章设计内容及要求 1.1扫雷游戏的基本要求 当前各种游戏层出不穷,因为游戏的开发成本非常大,所以游戏的开发具有一定的风险性,但是一些小游戏的开发成本具有成本小,编写简单的优势,所以这些小游戏在游戏开发中也占有一席之地。在这类小游戏中包括益智类游戏,它以画面精美、游戏方法简单等特点得到大家的认可。成为人们在工作之余不可或缺的好伙伴。针对这种情况我选择了扫雷游戏该课题作为我的课程题目。 Windows XP和Windows 7系统提供的扫雷游戏是一个很有趣的游戏。本次课程设计的主要任务是使用JA V A语言编写一个与其类似的扫雷游戏。具体要求如下: 1、扫雷游戏分为初级、中级和高级三个级别,同时扫雷英雄榜存储每个级别的最好成绩,即挖出全部的地雷且用时最少者。单击游戏菜单可以选择“初级”、“中级”和“高级”或“查看英雄版”。 2、选择级别后将出现相应级别的扫雷区域,这时用户使用鼠标左键单击雷区中任何一个方块便启动了计时器。 3、用户要揭开某个方块,可单击它。若所揭方块下有雷,用户便输了这一局,若所揭方块下没有雷,则显示一个数字,该数字代表此方块周围的8个方块中共有多少颗雷。 4、如果用户认为某个方块下埋着雷,单击右键可以在方块上标识一个用户认为是雷的图标,即给出一个扫雷标记。用户每标记出一个扫雷标记(无论用户的标记是否正确),窗口左上角的雷数计数器将会减少一个。 5、扫雷胜利后(用时最少者),程序弹出保存成绩的对话框。 6、用户如果遇到疑问的方块,可以勾选游戏菜单下的标记选项卡(或者用快捷键Alt+G然后点击M)即可标记该可疑方块,此时双击右键并可出现“?”标记。另有颜色选项,当用户选中该项时,游戏将以最低图像像素来显示。 7、如果用户需要使用提示声,可选中声音选项,此时将听到计时的咔嗒声。当用户点中雷时,将有爆炸声产生;胜利时,将有凯旋的旋律播放,此时企鹅出现欢悦表情。 1.2游戏需要实现的主要功能 1、用户可以自定义级别并且可以任意输入雷数; 2、具有计时功能,既显示用户完成所有扫雷任务所需要的时间; 3、自动保存扫雷英雄榜。

扫雷游戏Java源代码详解

扫雷游戏Java源代码 import java.awt.BorderLayout; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.Timer; public class ScanLei1 extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private Container contentPane; private JButton btn; private JButton[] btns; private JLabel b1; private JLabel b2; private JLabel b3; private Timer timer; private int row=9; private int col=9; private int bon=10; private int[][] a; private int b; private int[] a1; private JPanel p,p1,p2,p3; public ScanLei1(String title){ super(title); contentPane=getContentPane();

贪吃蛇游戏安卓源代码

附录1.SnakeView类 package com.example.android_snake.view; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.Timer; import java.util.TimerTask; import com.example.android_snake.R; import com.example.android_snake.food.Food; import com.example.android_snake.snake.Body; import com.example.android_snake.snake.Head; import com.example.android_snake.snake.Snake; import com.example.android_snake.snake.SnakeDirection; import com.example.android_snake.stone.Stone; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.os.Handler; import android.util.DisplayMetrics; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.ViewManager; import android.view.WindowManager; import android.widget.Toast; public class SnakeView extends View { private Context context; private Bitmap headBitmap; private Bitmap bodyBitmap; private Bitmap foodBitmap; private Bitmap stoneBitmap; // 屏幕的高度和宽度 private int screenHeight; private int screenWidth; // 每个小格子的高度和宽度 private int eachHeight;

java五子棋小游戏实验报告(附源代码)

手机五子棋游戏的设计与实 现 专业: 姓名: 班级: 学号: 指导教师:

J2ME(Java 2 Micro Edition)是近年来随着各种不同设备,尤其是移动通信设备的飞速发展而诞生的一项开发技术。它因其“write once,run anywhere”的Java特性而提高了开发的效率。随着手机性能的不断提高,手机休闲娱乐应用将成为PC休闲娱乐应用之后又一重要业务增长点。棋类游戏规则单一,比较适合在手机等便携终端推广。 由于具有跨平台、易于移植、占用空间小的优势,J2ME成为移动应用开发平台的主流,并提供了很多用以支持移动应用软件的开发的API。现将该技术用于这次的手机游戏开发,可以实现游戏的快速开发,不但便于查看游戏运行过程中内存的占用量和程序的每一部分代码消耗了多少处理器时间,而且可以不断地优化代码,使代码具有高度的复用性、可扩展性、可维护性。 游戏的开发以J2ME为平台,利用Java技术,结合J2ME的MIDP技术,并对于程序设计思想,重要类、方法等展开讨论。在对弈部分,分析设计走棋算法,选择合适的方式组织成代码,实现基本的人工智能。过程中使用了J2ME中的CLDC/MIDP软件体系,主要运用了MID Profile的特定类的支持,来完成游戏的开发。 关键词:J2ME;CLDC;MIDP

J2ME is a kind of fast developing technology implemented on various devices especially mobile communication equipments. It improves the efficiency of the development process because of its "write once, run anywhere" nature. The development trend of the entertainment market based on the cell phone is very obvious because the handset performance enhances unceasingly. The entertainment market based on the cell phone will to be the new important business growth point follow the PC entertainment market. As the rules of a single chess game, it is more suitable for mobile phones and other portable terminal extension. J2ME has been the preferred platform for development because of its platform independent and compatibility, and provides a lot of APIs to support the development of mobile application software. The technology for mobile game development, can achieve the rapid development of the game. It is not only easy to observe the memory consumption and processor consumed time during the operation of the game, but also can optimize the code, so that the code has a high degree of reusability, scalability, maintainability. The game has designed by J2ME, the Java technology and the MIDP technology. I studied the procedure thought, the important class and the method. In the playing chess part, I have analyzed the algorithm, choosed the appropriate way to organize the code and realized the basic artificial intelligence. On the other hand,I learned software system of CLDC/MIDP and the specific class of the MID Profile to complete the game development. Key words: J2ME;CLDC;MIDP

相关主题