大家好,今天给各位分享java游戏交易平台源码的一些知识,其中也会对谁有java游戏源码,给我发过来‘进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!
本文目录
一、求java小游戏源代码
// CheckerDrag.javaimport java.awt.*;import java.awt.event.*;public class CheckerDrag extends java.applet.Applet{// Dimension of checkerboard square.//棋盘上每个小方格的尺寸 final static int SQUAREDIM= 40;// Dimension of checkerboard-- includes black outline.//棋盘的尺寸–包括黑色的轮廓线 final static int BOARDDIM= 8* SQUAREDIM+ 2;// Dimension of checker-- 3/4 the dimension of a square.//棋子的尺寸–方格尺寸的3/4 final static int CHECKERDIM= 3* SQUAREDIM/ 4;// Square colors are dark green or white.//方格的颜色为深绿色或者白色 final static Color darkGreen= new Color(0, 128, 0);// Dragging flag-- set to true when user presses mouse button over checker// and cleared to false when user releases mouse button.//拖动标记--当用户在棋子上按下鼠标按键时设为true,//释放鼠标按键时设为false boolean inDrag= false;// Left coordinate of checkerboard's upper-left corner.//棋盘左上角的左方向坐标 int boardx;// Top coordinate of checkerboard's upper-left corner.//棋盘左上角的上方向坐标 int boardy;// Left coordinate of checker rectangle origin(upper-left corner).//棋子矩形原点(左上角)的左方向坐标 int ox;// Top coordinate of checker rectangle origin(upper-left corner).//棋子矩形原点(左上角)的上方向坐标 int oy;// Left displacement between mouse coordinates at time of press and checker// rectangle origin.//在按键时的鼠标坐标与棋子矩形原点之间的左方向位移 int relx;// Top displacement between mouse coordinates at time of press and checker// rectangle origin.//在按键时的鼠标坐标与棋子矩形原点之间的上方向位移 int rely;// Width of applet drawing area.// applet绘图区域的宽度 int width;// Height of applet drawing area.// applet绘图区域的高度 int height;// Image buffer.//图像缓冲 Image imBuffer;// Graphics context associated with image buffer.//图像缓冲相关联的图形背景 Graphics imG; public void init(){// Obtain the size of the applet's drawing area.//获取applet绘图区域的尺寸 width= getSize().width; height= getSize().height;// Create image buffer.//创建图像缓冲 imBuffer= createImage(width, height);// Retrieve graphics context associated with image buffer.//取出图像缓冲相关联的图形背景 imG= imBuffer.getGraphics();// Initialize checkerboard's origin, so that board is centered.//初始化棋盘的原点,使棋盘在屏幕上居中 boardx=(width- BOARDDIM)/ 2+ 1; boardy=(height- BOARDDIM)/ 2+ 1;// Initialize checker's rectangle's starting origin so that checker is// centered in the square located in the top row and second column from// the left.//初始化棋子矩形的起始原点,使得棋子在第一行左数第二列的方格里居中 ox= boardx+ SQUAREDIM+(SQUAREDIM- CHECKERDIM)/ 2+ 1; oy= boardy+(SQUAREDIM- CHECKERDIM)/ 2+ 1;// Attach a mouse listener to the applet. That listener listens for// mouse-button press and mouse-button release events.//向applet添加一个用来监听鼠标按键的按下和释放事件的鼠标监听器 addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){// Obtain mouse coordinates at time of press.//获取按键时的鼠标坐标 int x= e.getX(); int y= e.getY();// If mouse is over draggable checker at time// of press(i.e., contains(x, y) returns// true), save distance between current mouse// coordinates and draggable checker origin//(which will always be positive) and set drag// flag to true(to indicate drag in progress).//在按键时如果鼠标位于可拖动的棋子上方//(也就是contains(x, y)返回true),则保存当前//鼠标坐标与棋子的原点之间的距离(始终为正值)并且//将拖动标志设为true(用来表明正处在拖动过程中) if(contains(x, y)){ relx= x- ox; rely= y- oy; inDrag= true;}} boolean contains(int x, int y){// Calculate center of draggable checker.//计算棋子的中心位置 int cox= ox+ CHECKERDIM/ 2; int coy= oy+ CHECKERDIM/ 2;// Return true if(x, y) locates with bounds// of draggable checker. CHECKERDIM/ 2 is the// radius.//如果(x, y)仍处于棋子范围内则返回true// CHECKERDIM/ 2为半径 return(cox- x)*(cox- x)+(coy- y)*(coy- y)< CHECKERDIM/ 2* CHECKERDIM/ 2;} public void mouseReleased(MouseEvent e){// When mouse is released, clear inDrag(to// indicate no drag in progress) if inDrag is// already set.//当鼠标按键被释放时,如果inDrag已经为true,//则将其置为false(用来表明不在拖动过程中) if(inDrag) inDrag= false;}});// Attach a mouse motion listener to the applet. That listener listens// for mouse drag events.//向applet添加一个用来监听鼠标拖动事件的鼠标运动监听器 addMouseMotionListener(new MouseMotionAdapter(){ public void mouseDragged(MouseEvent e){ if(inDrag){// Calculate draggable checker's new// origin(the upper-left corner of// the checker rectangle).//计算棋子新的原点(棋子矩形的左上角) int tmpox= e.getX()- relx; int tmpoy= e.getY()- rely;// If the checker is not being moved//(at least partly) off board,// assign the previously calculated// origin(tmpox, tmpoy) as the// permanent origin(ox, oy), and// redraw the display area(with the// draggable checker at the new// coordinates).//如果棋子(至少是棋子的一部分)没有被//移出棋盘,则将之前计算的原点//(tmpox, tmpoy)赋值给永久性的原点(ox, oy),//并且刷新显示区域(此时的棋子已经位于新坐标上) if(tmpox> boardx&& tmpoy> boardy&& tmpox+ CHECKERDIM< boardx+ BOARDDIM&& tmpoy+ CHECKERDIM< boardy+ BOARDDIM){ ox= tmpox; oy= tmpoy; repaint();}}}});} public void paint(Graphics g){// Paint the checkerboard over which the checker will be dragged.//在棋子将要被拖动的位置上绘制棋盘 paintCheckerBoard(imG, boardx, boardy);// Paint the checker that will be dragged.//绘制即将被拖动的棋子 paintChecker(imG, ox, oy);// Draw contents of image buffer.//绘制图像缓冲的内容 g.drawImage(imBuffer, 0, 0, this);} void paintChecker(Graphics g, int x, int y){// Set checker shadow color.//设置棋子阴影的颜色 g.setColor(Color.black);// Paint checker shadow.//绘制棋子的阴影 g.fillOval(x, y, CHECKERDIM, CHECKERDIM);// Set checker color.//设置棋子颜色 g.setColor(Color.red);// Paint checker.//绘制棋子 g.fillOval(x, y, CHECKERDIM- CHECKERDIM/ 13, CHECKERDIM- CHECKERDIM/ 13);} void paintCheckerBoard(Graphics g, int x, int y){// Paint checkerboard outline.//绘制棋盘轮廓线 g.setColor(Color.black); g.drawRect(x, y, 8* SQUAREDIM+ 1, 8* SQUAREDIM+ 1);// Paint checkerboard.//绘制棋盘 for(int row= 0; row< 8; row++){ g.setColor(((row& 1)!= 0)? darkGreen: Color.white); for(int col= 0; col< 8; col++){ g.fillRect(x+ 1+ col* SQUAREDIM, y+ 1+ row* SQUAREDIM, SQUAREDIM, SQUAREDIM); g.setColor((g.getColor()== darkGreen)? Color.white: darkGreen);}}}// The AWT invokes the update() method in response to the repaint() method// calls that are made as a checker is dragged. The default implementation// of this method, which is inherited from the Container class, clears the// applet's drawing area to the background color prior to calling paint().// This clearing followed by drawing causes flicker. CheckerDrag overrides// update() to prevent the background from being cleared, which eliminates// the flicker.// AWT调用了update()方法来响应拖动棋子时所调用的repaint()方法。该方法从// Container类继承的默认实现会在调用paint()之前,将applet的绘图区域清除//为背景色,这种绘制之后的清除就导致了闪烁。CheckerDrag重写了update()来//防止背景被清除,从而消除了闪烁。 public void update(Graphics g){ paint(g);}}
二、求一个Java棋类游戏源码学习用,要求如下
1、 public static void main(String [] args){
2、 Scanner input= new Scanner(System.in);
3、 System.out.println("掷色子开始!");
4、 System.out.println("请下注注:下注金额只能是50的倍数且不能超过1000");
5、 if(zhu%50==0&&zhu<=1000&&zhu<=money){
6、 System.out.println("下注成功");
7、 System.out.println("买大请输入数字1,买小输入数字2");
8、 System.out.println("恭喜您猜对了,骰子点数为"+sum+"结果是大"+"余额为"+money);
9、 System.out.println("很遗憾,骰子点数为"+sum+"结果是小"+"余额为"+money);
10、 System.out.println("恭喜您猜对了,骰子点数为"+sum+"结果是小"+"余额为"+money);
11、 System.out.println("很遗憾,骰子点数为"+sum+"结果是大"+"余额为"+money);
12、 System.out.println("继续请按1,退出请按任意键");
13、 System.out.println("您选择的是继续");
14、 System.out.println("欢迎您下次再来玩");
15、 System.out.println("下注失败"+"余额为"+money);
三、谁有java游戏源码,给我发过来‘
1、注意:源代码仅供个人作学习研究时的参考,不得在程序制作中直接抄录。
2、源代码一共两个文件:Mine.java,MGame.java,另外还有一些图片。
3、在JBuilder下建立一个新的工程,将两个源文件复制到工程目录下的src\mine目录中,将所有图片复制到src\images目录中就可以了。
4、首先要说明一下用来存放地雷信息的数组grid。
5、grid是一个二维数组,第一位对应表格的行,第二位对应表格的列,比如grid[y][x]表示第y行第x列。每个字节的含义分三段:0-9表示已经挖开;10-19表示仍然埋藏;20-29表示做了标记。每段中:0-8表示周围的地雷数量;9表示是地雷。
6、由于每次地雷的埋放地是随机的,应次开始新游戏之前先要生成新的地雷信息。
7、第一步是初始化grid,将所有内容都置成10,因为一开始所有格子都是埋藏的。
8、第二步是随机产生地雷。当然了,已经产生过地雷的地方要避开。
9、x= Math.abs(rand.nextInt())% Width;
10、y= Math.abs(rand.nextInt())% Height;
11、最后就是无雷处计算周围的雷数了。怎么计算?一个一个加就是了。
12、在看一下按键响应函数keyPressed(int kcode),按1键是挖开动作。
13、前半部分表示如果当前焦点在一个埋藏格(值介于10到19之间),那么将其值减10,表示现在挖开。当然如果地下不是雷而且周围没有雷(值等于0)那么需要自动展开,这里调用了Expand(),(selx,sely)是当前焦点的表格坐标。
14、后半部分表示如果当前焦点在一个已经挖开的格子上(值小于10),那么就调用SafeExp()来自动挖开周围未挖的格子。
15、按3键是做标记动作。如果当前格是埋藏格,就做上标记(值加10);如果当前格已经做了标记,那么就去掉标记(值减10)。
16、Expand()是一个嵌套函数,他的作用是将周围不含地雷的格子周围全部挖开,如果挖开的部分中也有周围不含地雷的格子,那么对那些格子也重复前面的操作,直到把相关的格子都挖开。挖的顺序是左上、上、右上、左、右、左下、下、右下,如果遇到一个周围不含地雷的格子(值为0)那么马上嵌套调用Expand()对那个格子进行处理。
17、SafeExp()是一个自动挖开周围未挖格子的函数。当然要实现这个功能是有条件的,就是周围做了标记的格子数量必须等于当前格所标的数字,也就是说玩家把周围所有的地雷都标记了(不管是否标错)。函数中第一个部分就是做以上条件的判断。
18、第二部分是把周围埋藏的格子挖开。但是由于玩家的错误可能标记了没有地雷的格子,而把有地雷的格子漏标了,所以先要检查一下没做标而有地雷的格子和做错标记的格子。如果没有这些错误,那么可以安全的翻开了,同时也要检查是否挖到周围不含雷的格子,有的话就要调用Expand()了。
19、SafeExp()的返回值表示是否引爆了地雷,就是标记错误,true表示是,false表示否。这主要用于判断这次游戏是否要结束。
20、ExtendedImage是Siemens自己扩展的一个专用类,只在Siemens的Java中存在。
21、这个类主要是用做图像的缓存。大家不知道还有没有印象,以前在PC上编程的时候由于显示的速度比较慢,往往会开一片显示缓存,先把要现实的内容画到这片缓存中,全部画好后再一次性显示出来,ExtendedImage类就起到了这个作用。其实Java本身的Image类也可以实现类似的功能,但是显示速度好象不如人意,而且ExtendedImage更好用,所以我基本上都采用这个类。当然这对通用性是不利的。
22、用给定的颜色填充整个图形区域。
23、void blitToScreen(int x, int y);
24、将缓存内容贴到显示屏上,(x,y)是屏幕左上角坐标。
25、返回一个标准的Image类。可以通过ExtendImage.getImage().getGraphics()得到与其相关的Graphics对象,用来往ExtendImage上面画图。
关于java游戏交易平台源码,谁有java游戏源码,给我发过来‘的介绍到此结束,希望对大家有所帮助。
声明:本文内容来自互联网不代表本站观点,转载请注明出处:https://www.41639.com/15_306373.html
