eclipse小游戏源代码(小游戏java源代码)
admin 发布:2022-12-19 08:32 91
今天给各位分享eclipse小游戏源代码的知识,其中也会对小游戏java源代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、急需基于eclipse的JAVA小游戏源代码!!!
- 2、如何获得玩老版的小游戏的代码
- 3、用eclipse开发一个五子棋的小游戏,现在在layout里添加了一个重新开始的按钮,求按钮的代码
- 4、大神们 急求基于eclipse的java小游戏程序的源码,程序不要多复杂啊。像坦克大战,五子棋,扫雷之类的谢谢
急需基于eclipse的JAVA小游戏源代码!!!
单人版五子棋,不用导入,直接新建一个mywindow类就行,然后把一下代码粘贴就Ok了。或者,直接用dos就可以了。。
---------------------
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.BLUE);
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.WHITE);
g.drawLine(i, j, i, 330);
}
}
for(int j = 30;j = 330;j += 30)
{
g.setColor(Color.WHITE);
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);
}
}
}
}
void Justisewiner()
{
int black_count = 0;
int white_count = 0;
int i = 0;
for(i = 0;i 11;i++)//横向判断
{
for(int j = 0;j 11;j++)
{
if(chess[i][j] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i][j] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i 11;i++)//竖向判断
{
for(int j = 0;j 11;j++)
{
if(chess[j][i] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[j][i] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i 7;i++)//左向右斜判断
{
for(int j = 0;j 7;j++)
{
for(int k = 0;k 5;k++)
{
if(chess[i + k][j + k] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i + k][j + k] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}
for(i = 4;i 11;i++)//右向左斜判断
{
for(int j = 6;j = 0;j--)
{
for(int k = 0;k 5;k++)
{
if(chess[i - k][j + k] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i - k][j + k] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}
}
void Clear_Chess()
{
for(int i=0;i11;i++)
{
for(int j=0;j11;j++)
{
chess[i][j]=0;
}
}
repaint();
}
public void paint(Graphics g)
{
Drawline(g);
Drawchess(g);
}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
}
class myframe extends Frame implements WindowListener
{
mypanel panel;
myframe()
{
setLayout(null);
panel = new mypanel();
add(panel);
panel.setBounds(0,23, 360, 360);
setTitle("单人版五子棋");
setBounds(200, 200, 360, 383);
setVisible(true);
addWindowListener(this);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}
public class mywindow
{
public static void main(String argc [])
{
myframe f = new myframe();
}
}
如何获得玩老版的小游戏的代码
1、获得玩老版的小游戏的代码先安装了eclipse那你就可以配置sdk环境,然后建立代码源。
2、将源代码放进去,选择在你自己的手机上运行就会自动安装到你手机上即可。游戏代码通过正确的步骤进行即可。
用eclipse开发一个五子棋的小游戏,现在在layout里添加了一个重新开始的按钮,求按钮的代码
//运行代码很简单:在eclipse的项目中新建一个类Five.java把下面的代码放入该类即可//游戏运行:上下左右键控制方向,enter键确定棋子落定之处,黑白交替执行importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;/** *借鉴别人的。。。 */publicclassFiveextendsKeyAdapter{ booleanstart=false; JFrameframe; ThreadtimerThread; inth,l;//定义变量 intpans[][]=newint[11][11];//变量初始值 intgbx=5; intgby=5; intziShu=0; intshui=0; Five(){ frame=newJFrame("五子棋"); frame.getContentPane().add(newScreen()); frame.addKeyListener(this); frame.setSize(12*40+5*2,12*40+22+5*2+100);//窗口大小 frame.setVisible(true); frame.repaint(); frame.addWindowListener(newWindowAdapter(){ publicvoidwindowClosing(WindowEvente){ System.exit(0); } });//关闭窗体 } publicvoidkeyPressed(KeyEventevt){ switch(evt.getKeyCode()){ caseKeyEvent.VK_ENTER: if(ziShu%2==0)//子数来判断谁赢 { heiXia(); }else{ baiXia(); } shui=shuiYing(); break; caseKeyEvent.VK_ESCAPE: System.exit(1); break; caseKeyEvent.VK_LEFT: guangBiaoDong(-1,0);//光标动的坐标 break; caseKeyEvent.VK_RIGHT: guangBiaoDong(1,0);//光标动的坐标 break; caseKeyEvent.VK_DOWN: guangBiaoDong(0,1);//光标动的坐标 break; caseKeyEvent.VK_UP: guangBiaoDong(0,-1);//光标动的坐标 break; } frame.repaint();}@SuppressWarnings("serial")classScreenextendsJComponent{ publicvoidpaint(Graphicsg){ Graphics2Dg2d=(Graphics2D)g; xianShi(g2d);//画图 }}publicstaticvoidmain(String[]args){ newFive();} voidxianShi(Graphics2Dg2d)//显示 { xianShiQiPan(g2d);//显示棋盘 xianShiQiZis(g2d);//显示旗子 xianShiGuangBiao(g2d);//显示光标 g2d.setFont(newFont("STXingkai",1,30));//0708第二小组 g2d.setColor(Color.black); g2d.drawString("欢乐五子棋Java版",280,580); g2d.setFont(newFont("stCaiyun",1,40)); if(shui==0)//判断 { g2d.setColor(Color.black); xianShiTiShiXia(g2d);//显示谁下棋 }else{ g2d.setColor(Color.black); xianShiTiShiYing(g2d);//显示谁赢棋 } } voidguangBiaoDong(intfangX,intfangY)////光标动 { if(gbx+fangX10||gbx+fangX10||gby+fangY=0kanx+fx=0kany+fy=0kanx-fx=0kany-fy=5?pans[gby][gbx]:0); }};运行结果:
大神们 急求基于eclipse的java小游戏程序的源码,程序不要多复杂啊。像坦克大战,五子棋,扫雷之类的谢谢
import java.util.Scanner;
public class Wuziqi {
/**
* 棋盘
*/
private final int[][] qipan;
/**
* 步数
*/
private int bushu;
/**
* 构造方法,设置棋盘规格
* @param x
* @param y
*/
public Wuziqi(int x, int y) {
if (x 1 || y 1) {
System.out.println("棋盘规格应不小于1,使用默认规格");
qipan = new int[9][9];
} else {
qipan = new int[y][x];
}
}
/**
* 游戏开始
*/
public void play() {
int[] zuobiao = null;
//如果游戏没有结束
while (!end(zuobiao)) {
//落子,并取得坐标
zuobiao = luozi();
//输出棋盘
out();
}
}
/**
* 输出棋盘和棋子
*/
private void out() {
for (int i = 0; i qipan.length; i++) {
for (int j = 0; j qipan[i].length; j++) {
if (qipan[i][j] == 0) {
System.out.print(" +");
}else if (qipan[i][j] == -1) {
System.out.print(" 白");
}else if (qipan[i][j] == 1) {
System.out.print(" 黑");
}
}
System.out.println(" ");
}
}
/**
* 落子
*/
private int[] luozi() {
int[] zuobiao;
bushu++;
if (bushu % 2 == 1) {
System.out.println("请黑方落子");
zuobiao = input();
qipan[zuobiao[1]][zuobiao[0]] = 1;
}else {
System.out.println("请白方落子");
zuobiao = input();
qipan[zuobiao[1]][zuobiao[0]] = -1;
}
return zuobiao;
}
/**
* 输入坐标
* @return
*/
private int[] input() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入x轴坐标");
String x = sc.next();
System.out.println("请输入y轴坐标");
String y = sc.next();
//如果没有通过验证,则再次执行input(),递归算法
if (!validate(x, y)) {
return input();
}
int int_x = Integer.valueOf(x);
int int_y = Integer.valueOf(y);
return new int[] {int_x, int_y};
}
/**
* 校验数据
* @param x
* @param y
* @return
*/
private boolean validate(String x, String y) {
Integer int_x = null;
Integer int_y = null;
//异常处理的方式判断字符串是否是一个整数
try {
int_x = Integer.valueOf(x);
int_y = Integer.valueOf(y);
} catch (NumberFormatException e) {
System.out.println("坐标格式错误,坐标应为整数");
return false;
}
if (int_x 0 || int_y 0 || int_x = qipan[0].length || int_y = qipan.length) {
System.out.println("坐标越界");
return false;
}
if (qipan[int_y][int_x] == 0) {
return true;
} else {
System.out.println("坐标上已有棋子");
}
return false;
};
/**
* 结束条件
* @return
*/
private boolean end(int[] zuobiao) {
if (zuobiao == null) {
return false;
}
//计数器
//表示棋盘上经过最近落子坐标的4条线上的连续(和最近落子颜色相同的)棋子的个数
//如果某条线上连续的棋子大于等于4(加上最近落子本身,大于等于5),则游戏结束,符合五子棋规则
int[] jieguo = new int[4];
int x = zuobiao[0];
int y = zuobiao[1];
//定义八个方向
final int[][] fangxiang = {{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
//最近落子的坐标上的棋子颜色
int number = qipan[y][x];
//搜索最近落子坐标为中心最远4的距离
for (int i = 1; i = 4; i++) {
//每次搜索不同的距离都搜索八个方向
for (int j = 0; j fangxiang.length; j++) {
//约定如果某个方向为null时,不再搜索这个方向。关键字continue是跳过本次(一次)循环的意思
if (fangxiang[j] == null) {
continue;
}
int mubiao_x = x + i * fangxiang[j][0];
int mubiao_y = y + i * fangxiang[j][1];
//如果搜索坐标相对于棋盘越界,则不再搜索这个方向
if (mubiao_y = qipan.length || mubiao_y 0 || mubiao_x = qipan[0].length || mubiao_x 0) {
fangxiang[j] = null;
continue;
}
//如果最近落子坐标上的值等于目标坐标上的值(颜色相同),则计数器上某条线加1
//否则认为这个方向没有棋子或有别的颜色的棋子,不再搜索这个方向
if (number == qipan[mubiao_y][mubiao_x]) {
jieguo[j % 4]++;
}else {
fangxiang[j] = null;
}
}
}
//查看计数器上是否有比3更大的数(查看是否有一方胜出)
for (int i : jieguo) {
if (i 3) {
System.out.println("游戏结束");
if (bushu % 2 == 1) {
System.out.println("黑方胜");
} else {
System.out.println("白方胜");
}
return true;
}
}
//没有胜出者的情况下,查看棋盘上是否还有空位置,如果有,则游戏可以继续
for (int[] arr : qipan) {
for (int i : arr) {
if (i == 0) {
return false;
}
}
}
//如果没有空位置,则平局
System.out.println("游戏结束,平局");
return true;
}
}
eclipse小游戏源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于小游戏java源代码、eclipse小游戏源代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-07pb超级报表源代码(pb报表工具)[20240507更新]
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-07广告切换源代码免费下载(广告切换源代码免费下载安装)[20240507更新]
- 05-06阁楼网源代码(阁楼是什么网站)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06人脸识别源代码pdf的简单介绍[20240506更新]
- 05-06包含超市管理系统java源代码的词条[20240506更新]
- 05-06商城app源代码免费(商城App源码)[20240506更新]
- 05-06包含游戏源代码不同的模式的词条[20240506更新]
- 05-06matlab写的图象灰度切分源代码(matlab灰度图像分段线性变换)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接