Java小游戏吃豆豆源代码

Java小游戏吃豆豆源代码
Java小游戏吃豆豆源代码

1.4源程序

1.4.1 BigMouthFish.java

package cn.ycit.xinxi.eatbean.fish;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.Timer;

public class BigMouseFish implements ActionListener {

public static int up = 0;

public static int right = 1;

public static int down = 2;

public static int left = 3;

public int size = 50;

public int direction = right;

public Color color = Color.CYAN;

public int posx = 80;

public int posy = 80;

public int speed = 4;

public int eyesize = size / 5;

public int eyeposx = posx + size / 2;

public int eyeposy = posy + size / 5;

private Color eyecolor = Color.BLACK;

private int maxMouse = 30;

private int mousesize = 30;

private boolean isOpen = true;

private Timer time = null;

/**

* 创建一个位置为(200,200)大小为50,方向右,颜色蓝色,速度为10* */

public BigMouseFish() {

this(200,200,50,right,Color.CYAN,10);

}

public BigMouseFish(int posx, int posy, int size, int direction,Color color, int speed) { this.posx = posx;

this.posy = posy;

this.size = size;

this.speed = speed;

if (direction == 0 || direction == 1 || direction == 2 || direction == 3) {

this.direction = direction;

}

eyesize = size / 7;

initEye();

time = new Timer(Fishpool.reTime, this);

time.start();

}

public void move() {

switch (direction) {

case 0:

posy--;

break;

case 1:

posx++;

break;

case 2:

posy++;

break;

case 3:

posx--;

break;

default:

break;

}

}

public void changeColor(Color color) {

this.color=color;

}

public void changeDir(int direction) {

this.direction = direction;

}

public void paint(Graphics g){

//保存画笔的颜色

Color c = g.getColor();

//绘制鱼脸

g.setColor(color);

//从(posx,posy)点开始,绘制宽为size,高为size,开始角度为(direction%2==0?(direction+1):(direction-1))*90+monthsize,弧度为360-2*maxMonth的弧形

g.fillArc(posx, posy, size, size, (direction%2==0?(direction+1):(direction-1))*90+mousesize, 360-2*mousesize);

//绘制鱼眼

initEye();

g.setColor(eyecolor);

g.fillOval(eyeposx, eyeposy, eyesize, eyesize);

//恢复画笔颜色

g.setColor(c);

}

private void initEye() {

switch (direction) {

case 0:

eyeposx = posx + size / 7;

eyeposy = posy + size / 2;

break;

case 1:

eyeposx = posx + size / 2;

eyeposy = posy + size / 7;

break;

case 2:

eyeposx = posx + size * 5 / 7;

eyeposy = posy + size / 2;

break;

case 3:

eyeposx = posx + size / 2 - eyesize;

eyeposy = posy + size / 7;

break;

default:

break;

}

}

public void actionPerformed(ActionEvent e) {

if(isOpen){

mousesize -= 2;

if(mousesize<=0)

isOpen = false;

}else{

mousesize += 2;

if(mousesize>=maxMouse)

isOpen = true;

}

}

}

1.4.2 FishBean.java

ackage cn.ycit.xinxi.eatbean.fish;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.Timer;

public class FishBean implements ActionListener {

public int posx = 190;

public int posy = 190;

public int size = 10;

private Color color = Color.MAGENTA;

private Color newcolor = Color.MAGENTA;

private Color oldcolor = Color.GRAY;

public static int flickerTime = 350;

public static int flickerNum = 8;

private int hasFileckedNum = 0;

private Timer timer = null;

public FishBean() {

this(40, 15, 10, Color.MAGENTA, Color.gray);

}

public FishBean(int posx, int posy, int size, Color newcolor, Color oldcolor) { this.posx = posx;

this.posy = posy;

this.size = size;

this.newcolor = newcolor;

this.oldcolor = newcolor;

timer = new Timer(flickerTime, this);

}

public void paint(Graphics g) {

Color c = g.getColor();

g.setColor(color);

g.fillOval(posx, posy, size, size);

g.setColor(c);

}

public void newPos(int posx, int posy) {

this.posx = posx;

this.posy = posy;

}

public void stopTimer() {

color = newcolor;

timer.stop();

hasFileckedNum = 0;

}

public void runTimer() {

timer.start();

}

public void actionPerformed(ActionEvent e) {

hasFileckedNum++;

if (color.equals(newcolor) || color == newcolor) {

color = oldcolor;

} else {

color = newcolor;

}

if (hasFileckedNum == flickerNum && timer.isRunning()) { stopTimer();

}

}

public boolean timerIsRunning(){

return timer.isRunning();

}

}

1.4.3 Fishpool.java

package cn.ycit.xinxi.eatbean.fish;

import cn.ycit.xinxi.eatbean.main.BigMouseFishFrame;

import cn.ycit.xinxi.eatbean.tools.FishUtilities;

import cn.ycit.xinxi.eatbean.tools.RandomUtil;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyEvent;

import java.awt.image.ImageObserver;

import javax.swing.AbstractAction;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.KeyStroke;

import javax.swing.Timer;

public class Fishpool extends JLabel{

private static final long serialVersionUID = 1L;

private BigMouseFish fish = null;

private FishBean bean = null;

private int timeLength = 15 * 1000;

public static int reTime = 100;

private Timer timer = null;

private Timer time = null;

private int sizeAdd = 1;

private int speedAdd =2;

private int scoreAdd = 1;

private int score = 0;

private int upgradeNum = 10;

private int eatNum = 0;

private int min_x = 0;

private int max_x = 0;

private int min_y = 0;

private int max_y = 0;

public Fishpool() {

setSize(BigMouseFishFrame.width, BigMouseFishFrame.height);

setLocation(10, 10);

fish = new BigMouseFish();

initFishBean();

max_x = BigMouseFishFrame.width - fish.size - 3;

min_y = 3;

max_y = BigMouseFishFrame.height - fish.size - 3;

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "UPPRESS");

getActionMap().put("UPPRESS", new UpListenerImpl());

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "RIGHTPRESS");

getActionMap().put("RIGHTPRESS", new RightListenerImpl());

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "DOWNPRESS");

getActionMap().put("DOWNPRESS", new DownListenerImpl());

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "LEFTPRESS");

getActionMap().put("LEFTPRESS", new LeftListenerImpl());

timer = new Timer(reTime, new TimerListenerImpl());

timer.start();

time = new Timer(timeLength - FishBean.flickerTime * FishBean.flickerNum, new TimerListenerImpl());

ActionListener actionListener = new ActionListener() {

public void actionPerformed(ActionEvent e) {

time.stop();

bean.runTimer();

new Thread() {

public void run() {

while(true){

if ( !bean.timerIsRunning() ) {

beanNewPos();

time.restart();

break;

}

}

}

}.start() ;

}

};

timer.start();

}

private void initFishBean() {

int posx = 0;

int posy = 0;

do {

posx = RandomUtil.randomInt(BigMouseFishFrame.width - size-50);

posy = RandomUtil.randomInt(BigMouseFishFrame.height - size-100);

bean = new FishBean(posx, posy, size, getBackground(), Color.BLUE);

} while (posx >= fish.posx && posx <= fish.posx + fish.size

&& posy >= fish.posy && posy <= fish.posy + fish.size

&&posx+size>=fish.posx &&posx+size<=fish.posx+fish.size

&&posy+size>=fish.posy &&posy+size<=fish.posy+fish.size);

bean = new FishBean(posx, posy, size, Color.MAGENTA, getBackground());

}

private void beanNewPos() {

int size = 15;

int posx =0;

int posy= 0;

do {

posx = RandomUtil.randomInt(2 * size, BigMouseFishFrame.width - 2 * size);

posy = RandomUtil.randomInt(2 * size, BigMouseFishFrame.height - 2 * size);

} while (posx >= fish.posx && posx <= fish.posx + fish.size && posx >= fish.posy

&& posy <= fish.posy + fish.size && posx + size >= fish.posx && posy + size < +fish.posy

&& posx + size <= fish.posx + fish.size

&& posy + size <= fish.posy + fish.size);

bean.newPos(posx, posy);

}

public void paint(Graphics g) {

super.paint(g);

fish.paint(g);

bean.paint(g);

}

private void bigFishmove(int direction) {

MOVE:

for (int i = 0; i < fish.speed; i++) {

fish.changeDir(direction);

switch (direction) {

case 0:

if (fish.posy >= min_y + 1) {

if (isTouched()) {

break MOVE;

}

}

case 1:

if (fish.posx >= max_x - 1) {

if (isTouched()) {

break MOVE;

}

}

case 2:

if (fish.posy >= max_y - 1) {

if (isTouched()) {

break MOVE;

}

}

case 3:

if (fish.posx >= min_x + 1) {

if (isTouched()) {

break MOVE;

}

break;

}

}

}

}

private boolean isTouched() {

fish.move();

boolean b = FishUtilities.isInteraction(fish, bean);

if (b) {

initFishBean();

eatNum++;

score += scoreAdd;

BigMouseFishFrame.IblScore.setText(score + "");

fish.speed =4;

if (eatNum == upgradeNum) {

eatNum = 0;

fish.size += sizeAdd;

fish.speed += speedAdd;

BigMouseFishFrame.IblSize.setText(fish.size + "");

BigMouseFishFrame.IblSpeed.setText(fish.speed + "");

}

}

return b;

}

class UpListenerImpl extends AbstractAction {

private static final long serialVersionUID = 1L;

public void actionPerformed(ActionEvent e) {

bigFishmove(0); //To change body of generated methods, choose Tools | Templates.

}

}

class RightListenerImpl extends AbstractAction {

private static final long serialVersionUID = 1L;

public void actionPerformed(ActionEvent e) {

bigFishmove(1); //To change body of generated methods, choose Tools | Templates.

}

}

class DownListenerImpl extends AbstractAction {

private static final long serialVersionUID = 1L;

public void actionPerformed(ActionEvent e) {

bigFishmove(2); //To change body of generated methods, choose Tools | Templates.

}

}

class LeftListenerImpl extends AbstractAction {

private static final long serialVersionUID = 1L;

public void actionPerformed(ActionEvent e) {

bigFishmove(3); //To change body of generated methods, choose Tools | Templates.

}

}

class TimerListenerImpl implements ActionListener {

public void actionPerformed(ActionEvent e) {

repaint(); //To change body of generated methods, choose Tools | Templates.

}

}

}

1.4.4 FishUtilities.java

package cn.ycit.xinxi.eatbean.tools;

import cn.ycit.xinxi.eatbean.fish.BigMouseFish;

import cn.ycit.xinxi.eatbean.fish.FishBean;

public class FishUtilities {

public static boolean isInteraction(BigMouseFish fish,FishBean bean){

return Math.pow(fish.posx+fish.size /2-bean.posx-bean.size /2,2)

+Math.pow(fish.posy+fish.size/2-bean.posy -bean.size/2,2)<=Math.pow(fish.size/2,2);

}

1.4.5 RandomUtil.java

package cn.ycit.xinxi.eatbean.tools;

import java.util.Random;

public class RandomUtil {

public static int randomInt(int a,int b){

int t,n=0;

if(a>b){t=a;a=b;b=t;}

t=(int)(Math.ceil(Math.log10(b)));

while(true){

n=(int)(Math.random()*Math.pow(10, t));

if(n>=a&&n<=b){break;}

}

return n;

}

public static int randomInt(int a){

return new Random().nextInt(a);

}

}

1.4.6 BigMouthFishFrame.java

package cn.ycit.xinxi.eatbean.main;

import cn.ycit.xinxi.eatbean.fish.BigMouseFish; import cn.ycit.xinxi.eatbean.fish.Fishpool;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.Toolkit;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextArea;

import javax.swing.border.EtchedBorder;

import javax.swing.border.LineBorder;

import javax.swing.border.TitledBorder;

public class BigMouseFishFrame extends JFrame { private static final long serialVersion = 1L;

public static int width = 800;

public static int height = 800;

private JLabel IblInfo = new JLabel("欢迎进入大嘴鱼游戏");

private JLabel IblFishSize = new JLabel(" 鱼的大小:");

private JLabel IblFishSpeed = new JLabel(" 鱼的速度:");

private JLabel IblFishScore = new JLabel(" 现在得分:");

public static JLabel IblSize = new JLabel("50");

public static JLabel IblSpeed = new JLabel("4");

public static JLabel IblScore = new JLabel("0");

private JTextArea txtInfo = new JTextArea();

public BigMouseFishFrame() {

Fishpool pool = new Fishpool();

pool.setBorder(new EtchedBorder());

setTitle("大嘴鱼游戏");

setSize(width + 180, height + 50);

setResizable(true);

Toolkit tk = Toolkit.getDefaultToolkit();

setLocation((tk.getScreenSize().width - getSize().width) / 2, (tk.getScreenSize().height - getSize().height));

IblInfo.setSize(150, 20);

IblInfo.setLocation(width + 25, 240);

String str = "大嘴鱼游戏的简单使用说明;使用键盘上的" + "上下左右键控制大嘴鱼的移动方向,得分加1" + "每吃10条鱼,大嘴鱼将升级,大小加1,速度加2\n\n";

txtInfo.append(str);

txtInfo.setBackground(getBackground());

txtInfo.setEditable(false);

txtInfo.setLineWrap(true);

txtInfo.setSize(150, 240);

txtInfo.setLocation(width + 15, 370);

txtInfo.setBorder(new TitledBorder(new LineBorder(Color.GRAY), "游戏说明"));

JPanel pan = new JPanel();

pan.setSize(150, 100);

pan.setLocation(width + 15, 265);

pan.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

pan.setBorder(new TitledBorder(new LineBorder(Color.GRAY), "游戏积分"));

pan.add(IblFishSize);

pan.add(IblSize);

pan.add (IblFishSpeed);

pan.add(IblSpeed);

pan.add(IblFishScore);

pan.add(IblScore);

setLayout(null);

add(pool);

add(IblInfo);

add(pan);

add(txtInfo);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

}

public static void main(String[] args) {

new BigMouseFishFrame();

}

}

java课设走迷宫含代码

目录1.设计目的 1.1课程设计的目的 2.总体设计 2.1设计思路 2.2设计方法 3.关键技术 4.程序流程 5.主要源代码 6. 运行结果及结论 7.参考文献

1.设计目的 1.1课程设计的目的 随着科技进步,时代发展,计算机走进了大家的生活。计算机程序强大的功能为使用者提供服务,编程语言也变得越来越流行。Java语言是当今流行的网络编程语言,它具有面向对象、跨平台、分布应用等特点。面向对象的开发方法是当今世界最流行的开发方法,它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。 为了进一步巩固课堂上所学到的知识,深刻把握Java语言的重要概念及其面向对象的特性,熟练应用面向对象的思想和设计方法解决实际问题的能力,也是为了增加同学们娱乐游戏选择而开发了一个适合学生的,能提升思考力的迷宫冒险游戏,这既锻炼了动手能力,还能进行消遣娱乐,可谓一举两得。 2.总体设计 2.1设计思路 根据对游戏系统进行的需求分析,本系统将分为6个模块:分别是迷宫主界面模块、记时设计模块、迷宫设计模块、道路和障碍设计模块、动漫冒险者设计模块、出入口设计模块。实现的功能有: (1)迷宫的选择 玩家可以根据自身需求来进行选择简单迷宫、中等迷宫、难度迷宫三类中选择一类迷宫进行游戏。 (2)选择道路和障碍的图像 玩家可以根据个人喜好对迷宫中的道路和障碍的图片进行选择,但是图片的格式有规定,必须是“jpg”或“gif”格式的。 (3)游戏记时 当玩家控制迷宫中的动漫人物进行游戏时,计时器就开始进行记时,直到动漫人物到达出口时,记时结束,并在屏幕上显示游戏用时。 (4)开始游戏 玩家将鼠标移动至迷宫中的动漫冒险者,即可看到“单击我然后按键盘方向键”,单击后,游戏开始。玩家即可通过键盘上的方向键进行游戏。 (5)游戏结束 玩家控制动漫冒险者移动至迷宫地图的出口处时,游戏的计时器停止计时,并弹出信息框“恭喜您通关了”,游戏结束。

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("游戏");

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.360docs.net/doc/bd1419757.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);

扫雷游戏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();

java小游戏源码

连连看java源代码 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class lianliankan implements ActionListener { JFrame mainFrame; //主面板 Container thisContainer; 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; //游戏按钮的位置坐标int i,j,k,n;//消除方法控制 public void init(){ mainFrame=new JFrame("JKJ连连看"); thisContainer = mainFrame.getContentPane(); thisContainer.setLayout(new BorderLayout()); centerPanel=new JPanel(); southPanel=new JPanel(); northPanel=new JPanel(); 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); southPanel.add(exitButton);

C语的迷宫小游戏_源代码

C语言编写的迷宫游戏源代码 #include #include #include #include #include #define N 20/*迷宫的大小,可改变*/ int oldmap[N][N];/*递归用的数组,用全局变量节约时间*/ int yes=0;/*yes是判断是否找到路的标志,1找到,0没找到*/ int way[100][2],wayn=0;/*way数组是显示路线用的,wayn是统计走了几个格子*/ void Init(void);/*图形初始化*/ void Close(void);/*图形关闭*/ void DrawPeople(int *x,int *y,int n);/*画人工探索物图*/ void PeopleFind(int (*x)[N]);/*人工探索*/ void WayCopy(int (*x)[N],int (*y)[N]);/*为了8个方向的递归,把旧迷宫图拷贝给新数组*/ int FindWay(int (*x)[N],int i,int j);/*自动探索函数*/ void MapRand(int (*x)[N]);/*随机生成迷宫函数*/ void PrMap(int (*x)[N]);/*输出迷宫图函数*/ void Result(void);/*输出结果处理*/ void Find(void);/*成功处理*/ void NotFind(void);/*失败处理*/ void main(void)/*主函数*/ { int map[N][N]; /*迷宫数组*/ char ch; clrscr(); printf("\n Please select hand(1) else auto\n");/*选择探索方式*/ scanf("%c",&ch); Init(); /*初始化*/ MapRand(map);/*生成迷宫*/ PrMap(map);/*显示迷宫图*/ if(ch=='1') PeopleFind(map);/*人工探索*/ else FindWay(map,1,1);/*系统自动从下标1,1的地方开始探索*/ Result();/*输出结果*/ Close(); } void Init(void)/*图形初始化*/ {

java实战之连连看游戏源码(完整版)

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class lianliankan implements ActionListener { JFrame mainFrame; // 主面板 JPanel centerPanel,saidPanel; // 子面板 JButton diamondsButton[][] = new JButton[10][10];// 游戏按钮数组 JButton firstButton, secondButton; // 分别记录两次被选中的按钮 JButton backButton, remarkButton, newlyButton, startButton;// 返回,重列,重新,开始|暂停按钮 JLabel lable1 = new JLabel("分数:"); JLabel lable2 = new JLabel("0"); // 分数标签 int grid[][] = new int[12][12]; static boolean pressInformation = false; // 判断是否有按钮被选中 int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg = 0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标 int i, j, k, n;// 消除方法控制 public void AddGif() { for (int cols = 0; cols < 10; cols++) { for (int rows = 0; rows < 10; rows++) { diamondsButton[cols][rows] = new JButton(new ImageIcon(String.valueOf(grid[cols + 1][rows + 1])+".gif")); diamondsButton[cols][rows].addActionListener(this); centerPanel.add(diamondsButton[cols][rows]); } } } public void create() { mainFrame = new JFrame("连连看"); mainFrame.setLayout(null); centerPanel = new JPanel(); saidPanel = new JPanel(); saidPanel.setLayout(null); saidPanel.setBackground(Color.yellow); centerPanel.setLayout(new GridLayout(10,10)); //10*10的网格布局

java小游戏源代码

j a v a小游戏源代码 Document number:NOCG-YUNOO-BUYTT-UU986-1986UT

Java小游戏 第一个Java文件: import class GameA_B { public static void main(String[] args) { Scanner reader=new Scanner; int area; "Game Start…………Please enter the area:(1-9)" + '\n'+"1,2,3 means easy"+'\n'+"4,5,6 means middle"+'\n'+ "7,8,9 means hard"+'\n'+"Please choose:"); area=(); switch((area-1)/3) { case 0:"You choose easy! ");break; case 1:"You choose middle! ");break; case 2:"You choose hard! ");break; } "Good Luck!"); GameProcess game1=new GameProcess(area); (); } } 第二个Java文件: import class GameProcess { int area,i,arrcount,right,midright,t; int base[]=new int[arrcount],userNum[]=new int[area],sysNum[]=new int[area]; Random random=new Random(); Scanner reader=new Scanner; GameProcess(int a) { area=a; arrcount=10; right=0; midright=0; t=0; base=new int[arrcount]; userNum=new int[area]; sysNum=new int[area]; for(int i=0;i

java课设走迷宫(含代码)

目录1.设计目的 课程设计的目的 2.总体设计 设计思路 设计方法 3.关键技术 4.程序流程 5.主要源代码 6. 运行结果及结论 7. 参考文献

1.设计目的 课程设计的目的 随着科技进步,时代发展,计算机走进了大家的生活。计算机程序强大的功能为使用者提供服务,编程语言也变得越来越流行。 Java 语言是当今流行的网络编程语言,它具有面向对象、跨平台、分布应用等特点。面向对象的开发方法是当今世界最流行的开发方法,它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。 为了进一步巩固课堂上所学到的知识,深刻把握 Java 语言的重要概念及其面向对象的特性,熟练应用面向对象的思想和设计方法解决实际问题的能力,也是为了增加同学们娱乐游戏选择而开发了一个适合学生的,能提升思考力的迷宫冒险游戏,这既锻炼了动手能力,还能进行消遣娱乐,可谓一举两得。 2.总体设计设计思路 根据对游戏系统进行的需求分析,本系统将分为 6 个模块:分别是迷宫 主界面模块、记时设计模块、迷宫设计模块、道路和障碍设计模块、动漫冒险者设计模块、出入口设计模块。实现的功能有:

(1)迷宫的选择 玩家可以根据自身需求来进行选择简单迷宫、中等迷宫、难度迷宫三类中选择一类迷宫进行游戏。 (2)选择道路和障碍的图像 玩家可以根据个人喜好对迷宫中的道路和障碍的图片进行选择,但是图片的格式有规定,必须是“ jpg ”或“ gif ”格式的。 (3)游戏记时 当玩家控制迷宫中的动漫人物进行游戏时,计时器就开始进行记时,直 到动漫人物到达出口时,记时结束,并在屏幕上显示游戏用时。 (4)开始游戏 玩家将鼠标移动至迷宫中的动漫冒险者,即可看到“单击我然后按键盘 方向键”,单击后,游戏开始。玩家即可通过键盘上的方向键进行游戏。 (5)游戏结束 玩家控制动漫冒险者移动至迷宫地图的出口处时,游戏的计时器停止计时,并弹出信息框“恭喜您通关了” ,游戏结束 (6)冒险脚步声 玩家单击动漫冒险者后,便可以用键盘方向键进行控制。动漫冒险者每移动一步便会发出一声“嘟”的响声。

Java贪吃蛇游戏源代码

import java.awt.Color; import java.awt.Graphics; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.KeyStroke; public class 贪吃蛇extends JFrame implements ActionListener, KeyListener,Runnable { /** * */ private static final long serialVersionUID = 1L; private JMenuBar menuBar; private JMenu youXiMenu,nanDuMenu,fenShuMenu,guanYuMenu; private JMenuItem kaiShiYouXi,exitItem,zuoZheItem,fenShuItem; private JCheckBoxMenuItem cJianDan,cPuTong,cKunNan; private int length = 6; private Toolkit toolkit; private int i,x,y,z,objectX,objectY,object=0,growth=0,time;//bojectX,Y private int m[]=new int[50]; private int n[]=new int[50]; private Thread she = null; private int life=0; private int foods = 0; private int fenshu=0;

Java课程设计走迷宫

Java语言与面向对象技术课程设计报告 ( 2014 -- 2015年度第1 学期) 走迷宫

目录 目录 ...................................................................................................... 错误!未定义书签。 1 概述.................................................................................................. 错误!未定义书签。课程设计目的 ........................................................................... 错误!未定义书签。课程设计内容 ........................................................................... 错误!未定义书签。 2 系统需求分析 .......................................................................................... 错误!未定义书签。系统目标 ................................................................................... 错误!未定义书签。主体功能 ................................................................................... 错误!未定义书签。开发环境 ................................................................................... 错误!未定义书签。 3 系统概要设计 .......................................................................................... 错误!未定义书签。系统的功能模块划分 ............................................................... 错误!未定义书签。系统流程图 ............................................................................... 错误!未定义书签。4系统详细设计 ........................................................................................... 错误!未定义书签。系统的主界面设计 ..................................................................... 错误!未定义书签。 MAZE的设计.................................................................... 错误!未定义书签。 PERSONINMAZE的设计................................................... 错误!未定义书签。 WALLORROAD的设计 ..................................................... 错误!未定义书签。 MAZEPOINT的设计 ......................................................... 错误!未定义书签。 SOUND的设计 ................................................................. 错误!未定义书签。 RECORD的设计................................................................ 错误!未定义书签。 5 测试........................................................................................................... 错误!未定义书签。测试方案 ................................................................................... 错误!未定义书签。测试结果 ................................................................................... 错误!未定义书签。 6 小结........................................................................................................... 错误!未定义书签。参考文献....................................................................................................... 错误!未定义书签。

Java小游戏俄罗斯方块附完整源代码_毕业设计

**** 届毕业设计Java小游戏俄罗斯方块

┊┊┊┊┊┊┊┊┊┊┊┊┊装┊┊┊┊┊订┊┊┊┊┊线┊┊┊┊┊┊┊┊┊┊┊┊┊ 摘要 在现今电子信息高速发展的时代,电子游戏已经深入人们的日常生活,成为老少皆宜的娱乐方式。但是游戏设计结合了日新月异的技术,在一个产品中整合了复杂的设计、艺术、声音和软件,所以并不是人人皆知。直到今天,在中国从事游戏设计的人仍然很少,但是游戏行业的发展之快,远超如家电、汽车等传统行业,也正因为如此,游戏人才的教育、培养远落后于产业的发展。 俄罗斯方块是个老幼皆宜的小游戏,它实现由四块正方形的色块组成,然后存储在一个数组的四个元素中,计算机随机产生不同七种类型的方块,根据计算机时钟控制它在一定的时间不停的产生,用户根据键盘的四个方向键控制翻转、向左、向右和向下操作,(控制键的实现是由键盘的方向键的事件处理实现)。然后程序根据这七种方块堆叠成各种不同的模型。 论文描述了游戏的历史,开发此游戏的环境,游戏开发的意义。遵循软件工程的知识,从软件问题定义开始,接着进行可行性研究、需求分析、概要设计、详细设计,最后对软件进行了测试,整个开发过程贯穿软件工程的知识体系。 此次设计在Microsoft Windows 7系统下,以Java为开发语言,在eclipse开发平台上进行游戏的设计与实践。从游戏的基本玩法出发,主要就是俄罗斯方块的形状和旋转,我在设计中在一个图片框中构造了一些的网状小块,由这些小块组合成新的形状,每四个小块连接在一起就可以构造出一种造型,因此我总共设计了7中造型,每种造型又可以通过旋转而变化出2到4种形状,利用随机函数在一个欲览窗体中提前展示形状供用户参考,在游戏窗体中用户就可以使用键盘的方向键来控制方块的运动,然后利用递归语句对每一行进行判断,如果有某行的方块是满的,则消除这行的方块,并且使上面的方块自由下落,最后就可以得出用户的分数。 关键词:游戏设计,算法,数组,事件

小游戏源代码

/************************************ * Desc: 俄罗斯方块游戏 * By: hoodlum1980 :30 ************************************/ #include <> #include <> #include <> #include <> #include <> #include <> #define true 1 #define false 0 #define BoardWidth 12 #define BoardHeight 23 #define _INNER_HELPER /*inner helper method */ /*Scan Codes Define*/ enum KEYCODES { K_ESC =0x011b, K_UP =0x4800, /* upward arrow */ K_LEFT =0x4b00, K_DOWN =0x5000, K_RIGHT =0x4d00, K_SPACE =0x3920, K_P =0x1970 }; /* the data structure of the block */ typedef struct tagBlock { char c[4][4]; /* cell fill info array, 0-empty, 1-filled */ int x; /* block position cx [ 0,BoardWidht -1] */ int y; /* block position cy [-4,BoardHeight-1] */ char color; /* block color */ char size; /* block max size in width or height */ char name; /* block name (the block's shape) */ } Block; /* game's global info */ int FrameTime= 1300; int CellSize= 18; int BoardLeft= 30; int BoardTop= 30; /* next block grid */ int NBBoardLeft= 300;

java小游戏源代码

Java小游戏 第一个Java文件: import public class GameA_B { public static void main(String[] args) { Scanner reader=new Scanner; int area; "Game Start…………Please enter the area:(1-9)" + '\n'+"1,2,3 means easy"+'\n'+"4,5,6 means middle"+'\n'+ "7,8,9 means hard"+'\n'+"Please choose:"); a rea=(); s witch((area-1)/3) { c ase 0:"You choose easy! ");break; c ase 1:"You choose middle! ");break; c ase 2:"You choose hard! ");break; } "Good Luck!"); G ameProcess game1=new GameProcess(area); (); } } 第二个Java文件: import import public class GameProcess { int area,i,arrcount,right,midright,t; int base[]=new int[arrcount],userNum[]=new int[area],sysNum[]=new int[area]; Random random=new Random(); Scanner reader=new Scanner; GameProcess(int a) { area=a; arrcount=10; right=0; midright=0; t=0; base=new int[arrcount]; userNum=new int[area]; sysNum=new int[area]; for(int i=0;i

java迷宫小游戏源代码

帮朋友写的迷宫小游戏程序java //作者:LaoCooon import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.event.*; import javax.swing.*; import java.awt.*; class mMaze extends Frame { Color redColor;

Random Random=new Random(); int mapI=Random.getRandom(); MapArray MapArray=new MapArray(); int[] map = MapArray.getMapArray(mapI); static ImageIcon wall= new ImageIcon("wall.jpg"); final ImageIcon tortoise= new ImageIcon("tortoise.gif"); int xl=0,yl=1,speed=30; int x=0,y=1; public mMaze(){addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ if(e.getKeyCode()== KeyEvent.VK_UP){ System.out.println("\n Go Up"); if(map[(yl-1)*29+xl]!=1) yl-=1; } else if(e.getKeyCode()== KeyEvent.VK_DOWN){ System.out.println("\n Go Down"); if(map[(yl+1)*29+xl]!=1) yl+=1; } else if(e.getKeyCode()== KeyEvent.VK_LEFT){ System.out.println("\n Go Left"); if(map[yl*29+(xl-1)]!=1) xl-=1; } else if(e.getKeyCode()== KeyEvent.VK_RIGHT){ System.out.println("\n Go Right"); if(map[yl*29+(xl+1)]!=1) xl+=1; } else System.out.println(e.getKeyChar()); if(y==27&&x==28) System.out.println("\n You Win~!"); repaint(); } } ); setSize(890,910); setVisible(true); setLocation(400,200); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); System.exit(0); } } ); } public void paint(Graphics g){ g.drawImage(tortoise.getImage(), xl*speed+8, yl*speed+30, null); int i=0,j=0; for ( i = 0; i < 29; i++) for(j=0;j<29;j++) if(map[i*29+j]==1) g.drawImage(wall.getImage(), j*30+8, i*30+30, null); } } public class Maze{ public static void main(String[] args){ new mMaze(); }} 回复 ?2楼 ?2013-05-16 10:34

java小游戏设计.docx

文档来源为 :从网络收集整理.word 版本可编辑 .欢迎下载支持.华北科技学院计算机学院综合性实验 实验报告 课程名称JAVA程序设计 实验学期2014至2015学年第1学期 学生所在院部计算机学院 年级专业班级 学生姓名学号 任课教师 实验成绩 计算机学院制

《 Java 程序设计》课程综合性实验报告 开课实验室:基础四2016年 11 月 28日 实验题目基于 java 的拼图游戏 一、实验目的 程序使用Eclipse 集成开发环境完成,熟悉并掌握在Eclipse 开发环境下编写Java 程序。 二、设备与环境 硬件:多媒体计算机 软件: Windows 系列操作系统、JDK 开发包、 Eclipse 开发环境 三、实验内容及要求 1.实验要求 使用 Java swing 编程实现拼图游戏。游戏功能是将一幅图片分割成5*5 的规则小图片,游戏开始时将25 个小图片随机摆放,玩家能够参考原图拼接出正确的图片。 游戏规则:在 25 个小图片中有一个为空白图片,玩家可以单击和空白小图片相邻的任一个 小图片(上、下、左、右均可),即可将单击的小图片与空白小图片交换位置。通过有限次的移动,即可将随机分布的小图片恢复成原图的样式。 2.实验内容 ( 1) java 源代码及其功能 及主 员函 序号类名主要功能 功1GreedSnake该类为程序入口,含有main 方法。 ( 2)2SnakeControl 实现控制运行等总体要求,实现方向键控制蛇的方 向,空格键控制游戏暂停或继续,还有分数等。代码 该类实现蛇的结构和具体运动,如判断食物是否和 3SnakeModel 现如 怎样被吃掉及判断后的动作。 ① 程4Node该类实现组成蛇身的单位- 食物。 口主5SnakeView该类实现画板功能,用黑色画蛇身,红色画食物。法: //第一部分 public class GreedSnake {//建立主类GreeSnake 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(); }各类要成数的能:具体及实下:序入方

相关文档
最新文档