JAVA21点游戏源代码

JAVA21点游戏源代码
JAVA21点游戏源代码

package com.easyjava.sample;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

import java.util.Stack;

/**

*

* @author

* 21点游戏

*/

public class BlackJack {

private Player player,com;// 玩家和电脑

private Dealer deck;// 一副牌

BufferedReader br;

/**

* 打印菜单

* 完成所有功能调用

*/

public BlackJack() {

// 初始化玩家,牌

player=new Player();

com=new Player();

deck=new Dealer();

String str = null;

br=new BufferedReader(new InputStreamReader(System.in));

// 打印菜单

while(true){

player.playAgain();

com.playAgain();

System.out.println("\t\t\t黑杰克\n");

System.out.println("\t\t 1.开始游戏\n");

System.out.println("\t\t 2.查看比分\n");

System.out.println("\t\t 3.结束游戏\n");

System.out.println("\t请输入:");

try {

str=br.readLine();

} catch (IOException e) {

e.printStackTrace();

}

switch(Integer.parseInt(str)){

case 1:

start();

break;

case 2:

checkScore();

break;

case 3:

System.exit(0);

break;

default:

System.out.println("输入有误,请重新输入");

break;

}

}

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

new BlackJack();

}

// 游戏开始,完成初始金额的投注及发第一张牌

// 然后用户选择是投注加倍金额,发下一张牌,还是PASS,或者开牌

private void start() {

// 初始化金额为20货币单位

int money=20;// 投注金额

int yourChoice;// 用户选择

System.out.println("请选择你要投注的金额(最低20货币单位):");

// 用户输入下注金额

try {

money=Integer.parseInt(br.readLine());

if(money<20){

money=20;

}

} catch (Exception e) {

money=20;

System.out.println("您的输入不正确,计算机自动将您的投注金额定为20货币单位");

}

System.out.println("下面开始发牌...");

player.setHand(deck.getCard());

com.setHand(deck.getCard());

do{

System.out.println("您得到的牌是:"+player.getHandList());

do{

System.out.println("您的选择:1.加倍;2.PASS;3.再要一张;4.开牌;5.退回上级菜单");

try {

yourChoice=Integer.parseInt(br.readLine());

break;

} catch (NumberFormatException ex) {

System.out.println("输入错误,请重新输入");

} catch (IOException ex) {

System.out.println("输入错误,请重新输入");

}

}while(true);

switch(yourChoice){

case 1:// 加倍

yourDouble(money);

break;

case 2:// PASS

yourPass(money);

break;

case 3:// 再要一张

getCardAgain(money);

break;

case 4:// 开牌

winOrLose(money);

yourChoice=5;

break;

case 5:// 退回上一级

break;

default:

System.out.println("您的输入有误,请输入1-5");

}

}while(yourChoice!=5);

}

// 查看玩家成绩

private void checkScore() {

System.out.println("您胜利了"+player.getWin()+"次");

System.out.println("您失败了"+player.getLose()+"次");

System.out.println("您还有"+player.getCash()+"货币单位");

}

// 玩家加倍

private void yourDouble(int money) {

money*=2;// 投注金额加倍

// 判断输赢

this.winOrLose(money);

}

// 点数计算

private int computePoint(Player player){

int playerPoint=0;// 玩家的牌点

int numberOfA=0;// A点拿到的张数

// A点以外的分数累加

for(int i=0;i

Card c=(Card)player.getHand().get(i);

if(c.getFace().charAt(0)>='2'&&c.getFace().charAt(0)<='9'){

playerPoint+=Integer.parseInt(c.getFace());// 牌点在2~9之间直接累加}else if(c.getFace().equals("J") ||

c.getFace().equals("Q")||

c.getFace().equals("K")||c.getFace().equals("10")){

playerPoint+=10;// 牌点是J Q K则累加10

}else if(c.getFace().charAt(0)=='A'){

numberOfA++;

}

}

// A点的分数累加

if(numberOfA==0){

}else{

if(playerPoint+(11*numberOfA)>21){

playerPoint+=numberOfA;

}else{

playerPoint+=11;

}

}

if(playerPoint<=21){

return playerPoint;

}else{

return 0;// 超过21点(爆分)

}

}

private void yourPass(int money) {// PASS

// 判断输赢

this.winOrLose(money);

}

private void getCardAgain(int money) {// 再发一张

player.setHand(deck.getCard());

}

private void winOrLose(int money) {// 判断输赢

int playerPoint=https://www.360docs.net/doc/4e5262890.html,putePoint(player);// 获得玩家点数

int comPoint=comPlayer();// 获得电脑点数

if(comPoint==0){// 点脑爆分

System.out.println("爆分!你赢了。");

player.setCash(player.getCash()+money);

player.youWin();

}else if(playerPoint==0){// 玩家爆分

System.out.println("爆分!你输了。");

player.setCash(player.getCash()-money);

player.youLose();

}else if(comPoint

System.out.println("电脑:"+comPoint+"你:"+playerPoint+"你赢了");

player.setCash(player.getCash()+money);

player.youWin();

}else{

System.out.println("电脑:"+comPoint+"你:"+playerPoint+"你输了");

player.setCash(player.getCash()-money);

player.youLose();

}

}

private int comPlayer() {

int comPoint=https://www.360docs.net/doc/4e5262890.html,putePoint(com);

System.out.println("电脑开始:"+com.getHandList());

while(comPoint!=0&&comPoint<=18 && com.getSize()<5){// 人工智能:如果电脑手上的点数小于18点就发牌

com.setHand(deck.getCard());// 再发一张牌给电脑

System.out.println("再发一张,电脑手中:"+com.getHandList());

comPoint=https://www.360docs.net/doc/4e5262890.html,putePoint(com);// 重新计算分数

}

return comPoint;

}

}// BlackJack

/**

*

* @author

* 扑克

*/

class Card {

// 表示所有纸牌面值的数组

public static final String[] FACES={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};

// 表示所有类型值的数组

public static final String[] SUITS={"黑桃","梅花","方块","红心"};

// 纸牌总数

public static final int MAX_CARDS=FACES.length*SUITS.length;

// 这张牌的点值

protected int value;

// 用0点创建一个默认纸牌

public Card(){

value=0;

}

// 创建第n张牌,非法n值将使程序终止。

public Card(int n){

if(n<0 || n>MAX_CARDS){

System.out.println("错误:非法牌索引,程序退出");

System.exit(0);

}else{

value=n;

}

}

// 返回表示纸牌面值的字符串

public String getFace(){

return FACES[value%FACES.length];

}

// 返回表示纸牌类型的String

public String getSuit(){

return SUITS[value%SUITS.length];

}

public String toString(){

return getSuit()+getFace();

}

}// Card

/**

*

* @author

* 发牌者

*/

class Dealer {

// Card对象的最大值

public static final int MAX_SIZE=52;

// Card对象的栈

protected Stack cards;

// 所有已取出牌的集合

protected List drawnCards;

// 在上面的列表中允许随机获取

protected Random random;

/**创建一个含52张牌的Deck */

public Dealer() {

// 把给定数目的牌压入栈中

cards=new Stack();

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

cards.push(new Card(i));

}

// 为已取出的牌创建一个池,并创建数字产生器

drawnCards=new ArrayList();

random=new Random();

shuffle();

}

/**

* 返回这幅牌剩余的数量

*/

public int getSize(){

return cards.size()+drawnCards.size();

}

// 随机洗牌

private void shuffle() {

// 清空栈

while (!cards.isEmpty()){

drawnCards.add(cards.pop());

}

// 把取出的牌重新随机放回到栈中

Object card=null;

while (!drawnCards.isEmpty()){

card=drawnCards.remove(Math.abs(random.nextInt()%drawnCards.size()));

cards.push(card);

}

}

/**

* 发牌

*/

public Card getCard(){

if(getSize()==0){// 牌已经发完了

// 重新生成一副牌

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

cards.push(new Card(i));

}

// 重新洗牌

shuffle();

}

return (Card)cards.pop();

}

/**

*

* @author

* 玩家持牌

*/

class CardsInHand {

private ArrayList cards;

/** Creates a new instance of Hand */

public CardsInHand() {

cards=new ArrayList();

}

/**

*接受一张发牌

*/

public void setCard(Object c){

cards.add(c);

}

/**

*清空玩家手中的牌

*/

public void clear(){

cards.clear();

}

/**

*返回玩家手中的牌张数

*/

public int getSize(){

return cards.size();

}

// 显示玩家手中的牌列表

public String toString(){

// int i = 0;

String hand = "";

// while (!cards.isEmpty()){

hand=cards.toString();

// i++;

// }

return hand;

public ArrayList getCards(){

return cards;

}

}// Hand

/**

*

* @author

* 玩家类

*/

class Player {

private int winNumber;// 记录胜利次数

private int loseNumber;// 记录失败次数

private int cash;// 玩家手中的现金

private CardsInHand hand;

/**

* 初始化玩家的相关参数

*胜利次数:0

*失败次数:0

*纸牌数:0

*现金数:10000

*/

public Player() {

winNumber=0;

loseNumber=0;

hand=new CardsInHand();

setCash(10000);

}

/**

*获得胜利次数

*/

public int getWin(){

return winNumber;

}

/**

*获得失败次数

*/

public int getLose(){

return loseNumber;

}

/**

*获得玩家手中牌的列表*/

public String getHandList(){ return hand.toString(); }

/**

*获得玩家手中牌的张数*/

public int getSize(){

return hand.getSize(); }

/**

*接受发来的牌

*/

public void setHand(Card c){ hand.setCard(c);

}

/**

*返回玩家手中牌列表

*类型:List

*/

public List getHand(){

return hand.getCards(); }

/**

*赢了一局

*/

public void youWin(){

winNumber++;

}

/**

*清空玩家手中的牌

*/

public void playAgain(){

hand.clear();

}

/**

*输了一局

*/

public void youLose(){

loseNumber++;

}

/**

*得到当前现金

*/

public int getCash() {

return cash;

}

/**

*重新设置当前现金

*/

public void setCash(int cash) {

this.cash = cash;

}

}// Player

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/4e5262890.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);

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贪吃蛇游戏源代码

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小游戏俄罗斯方块

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

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游戏开发项目及游戏源码

J a v a程序设计项目 1.项目背景 为了提高学生动手能力,增加学生实践的机会,某软件公司实习单位要求学生5-6人组成开发团队进行Java程序项目开发,参考自己团队的实力与客户的要求,使用Java语言开发某一项目,此项目可以是应用程序,也可以是游戏开发等,项目名称自拟。 2.硬件资源和软件资源 (1)每组配备联网PC台,智能手机一部(带有手机数据 线)HP打印机一台。 (2)eclipse-SDK-3.6.1-win32软件开发程序(含有eclipseme插件)、SUNWTK 无线开发包或Symbian_3_SDK_v0_9等手机开发包。 3.实验室功能需求 (1)实现学生机和教师机器(服务器)进行通信,相互共享资源。 (2)教师机器(服务器)上安装一台打印机,实现学生机可以共享打印。 (3)实现教师机器(服务器)连接和访问Internet。 (4)实现每一台学生机器访问Internet。 (5)要求为每一项目组学生机和教师机器分配一个标识,即学生机器的机器名为ST1~ST10,教师机器名为Server。 4.项目实施要求 (1)要求各项目小组拿出详细的某某Java程序设计项目报告书(具体项目规划书格式参考附表一),关键步骤要有相应的截图。 (2)要求项目组长向各小组讲解与演示自己小组的项目成果,组长小组成员要熟练的解释与分析自己负责编写的Java代码或项目分工成果。 (3)最后提交用小组命名的文件夹,其中包括开发所用的所有资料与项目成果。 附表一: 雷霆战机项目报告书 一、项目概述 本项目为一个Java游戏,是一个基于J2ME平台的飞机射击类游戏。 二、项目开发团队 三、所用Java相关知识点

Java猜拳小游戏源代码

第一个文件: public class Computer { String name; int score; public int showfist(){ int quan; quan=(int)(Math.random()*10); if(quan<=2){ quan=1; }else if(quan<=5){ quan=2; }else{ quan=3; } switch(quan){ case 1:System.out.println(name+"出拳:剪刀");break; case 2:System.out.println(name+"出拳:石头");break; case 3:System.out.println(name+"出拳:布");break; } return quan; } } 第二个文件: import java.util.Scanner; public class Game { int count=0; int countP=0; Person person=new Person(); Computer computer=new Computer(); Scanner input=new Scanner(System.in); public void initial(){ System.out.print("请选择你的角色(1.刘备 2.孙权 3.曹操):"); int juese=input.nextInt(); switch(juese){ case 1:https://www.360docs.net/doc/4e5262890.html,="刘备"; break; case 2:https://www.360docs.net/doc/4e5262890.html,="孙权"; break; case 3:https://www.360docs.net/doc/4e5262890.html,="曹操"; break; } System.out.print("请选择对手角色(1.关羽 2.张飞 3.赵云):");

连连求java小游戏源代码

求java小游戏源代码 悬赏分:100 - 解决时间:2007-11-30 12:37 要做课程设计,想找几个小游戏的代码做参考,请各位高手帮忙!!!小弟不胜感激!!! 提问者:s2005035 - 二级 最佳答案 连连看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);

游戏2048的JAVA源代码

游戏2048的JAVA源代码 1.文档说明 a) 本代码主要功能为实现2048游戏,GUI界面做到尽量简洁和原游戏相仿。目前版本不包含计分,计时功能。 b) 本代码受计算机系大神指点,经许可后发布如下,向Java_online网致敬 c) 运行时请把.java文件放入Game_one文件夹中方可运行(没有的自己在workplace src中创建)或者直接删去第一个package Game_one;代码即可。2.运行截图 a) 初始状态 b) 进入游戏 c) 游戏进行中

3.JAVA代码 package Game_one; import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class Game2048 extends JPanel { enum State { start, won, running, over } final Color[] colorTable = { new Color(0x701710), new Color(0xFFE4C3), new Color(0xfff4d3), new Color(0xffdac3), new Color(0xe7b08e), new Color(0xe7bf8e), new Color(0xffc4c3), new Color(0xE7948e), new Color(0xbe7e56), new Color(0xbe5e56), new Color(0x9c3931), new Color(0x701710)}; final static int target = 2048; static int highest; static int score; private Color gridColor = new Color(0xBBADA0); private Color emptyColor = new Color(0xCDC1B4); private Color startColor = new Color(0xFFEBCD);

java小游戏连连看源代码

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

java跳棋源代码

〖作者:俞尚〗〖大小:2.7M 〗〖发布日期:2006-09-08 〗〖浏览:206 〗 电脑智能升级难度更大, 采用隔空跳的规则,这样变化更多一些,可玩性更好, 是一个eclipse的工程, 现在是最新版本: 1.修改电脑的智力,难度更高,要战胜电脑?你有10%的机会 2.现在支持多个玩家游戏(将来支持网络游戏) 3.下一步设想移植到手机,PPC上; 4.增加声音效果; “我的跳棋”设计说明书,作者:俞尚 来自:https://www.360docs.net/doc/4e5262890.html,/user17/yushang0824/blog/26621680.html. 一、概述: 跳棋在我国是一项老少皆宜、流传广泛的益智型棋类游戏。由于其规则简单,一玩就懂,一辈子都不会忘,所以几乎每个人从小到大都下过跳棋。如果您不愿陷入激烈的思考和竞争,那么无疑本游戏可以使您回到一种更平和、产生美好回忆的心情之中。 在此我把近十天的成果做一个简要的介绍,尽量把问题说得清楚细致。希望与对跳棋编程有同样兴趣的伙伴们好好讨论一下,也希望下一版本的跳棋做得更好。 这个跳棋游戏主要有下几个特点:界面漂亮,操作简单,功能简洁,老少兼宜。我爸爸都很喜欢下。整个跳棋的源码你可以下载。 二、跳棋整体设计 UML类图:

先给跳棋整个代码做一个整体介绍,说明每个包,每个类具体作用: 1. org.yushang.jumpchess.app AppJumpChess.java实现的漂亮的窗体界面,标题栏和各种按钮,设置玩家个数及类型(人,或是计算机)。 2. org.yushang.jumpchess.audio WavePlayer.java主要用于播放游戏中各种声音效果,比较简单。 3. org.yushang.jumpchess.image ImageLoader.java主要用于从资源文件中导入各种图片背景,比较简单。 4. org.yushang.jumpchess.Interface Animation.java是用于播放动画的超类λ AnimationGO.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];

相关文档
最新文档