java蜘蛛纸牌游戏设计

java蜘蛛纸牌游戏源程序

AboutDialog.java

import javax.swing.*;

import java.awt.*;

/*

**“关于”窗口

*/

public class AboutDialog extends JDialog

{

JPanel jMainPane = new JPanel();

JTabbedPane jTabbedPane = new JTabbedPane();

private JPanel jPanel1 = new JPanel();

private JPanel jPanel2 = new JPanel();

private JTextArea jt1 = new JTextArea("将电脑多次分发给你的牌按照相同的花色由大至小排列起来。直到桌面上的牌全都消失。");

private JTextArea jt2 = new JTextArea("该游戏中,纸牌的图片来自于Windows XP的纸牌游戏,图片权属于原作者所有!");

/*

**构造函数

*/

public AboutDialog()

{

setTitle("蜘蛛牌");

setSize(300,200);

setResizable(false);

setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE);

Container c = this.getContentPane();

jt1.setSize(260,200);

jt2.setSize(260,200);

jt1.setEditable(false);

jt2.setEditable(false);

jt1.setLineWrap(true);

jt2.setLineWrap(true);www.lwfree.cn

jt2.setForeground(Color.black);

jPanel1.add(jt1);

jPanel2.add(jt2);

jTabbedPane.setSize(300,200);

jTabbedPane.addTab("游戏规则", null, jPanel1, null);

jTabbedPane.addTab("声明", null, jPanel2, null);

jMainPane.add(jTabbedPane);

c.add(jMainPane);

pack();

this.setVisible(true);

}

}

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class PKCard extends JLabel implements MouseListener,

MouseMotionListener{

//纸牌的位置

Point point = null;

Point initPoint = null;

int value = 0;

int type = 0;

String name = null;

Container pane = null;

Spider main = null;

boolean canMove = false;

boolean isFront = false;

PKCard previousCard = null;

public void mouseClicked(MouseEvent arg0){

}

public void flashCard(PKCard card){

//启动Flash线程

new Flash(card).start();

//不停的获得下一张牌,直到完成

if(main.getNextCard(card) != null){

card.flashCard(main.getNextCard(card));

}

}

class Flash extends Thread{

private PKCard card = null;

public Flash(PKCard card){

this.card = card;

}

/*

**线程的run()方法

**为纸牌的正面设置白色图片

*/

public void run(){

boolean is = false;

ImageIcon icon = new ImageIcon("images/white.gif");

for (int i = 0; i < 4; i++){

try{

Thread.sleep(200);

}

catch (InterruptedException e){

e.printStackTrace();

}

if (is){

this.card.turnFront();

is = !is;

}

else{

this.card.setIcon(icon);

is = !is;

}

// 根据当前外观将card的UI属性重置

card.updateUI();

}

}

}

/**

**点击鼠标

*/

public void mousePressed(MouseEvent mp){

point = mp.getPoint();

main.setNA();

this.previousCard = main.getPreviousCard(this);

}

/**

**释放鼠标

*/

public void mouseReleased(MouseEvent mr){

Point point = ((JLabel) mr.getSource()).getLocation();

//判断可行列

int n = this.whichColumnAvailable(point);

if (n == -1 || n == this.whichColumnAvailable(this.initPoint)){

this.setNextCardLocation(null);

main.table.remove(this.getLocation());

this.setLocation(this.initPoint);

main.table.put(this.initPoint, this);

return;

}

point = main.getLastCardLocation(n);

boolean isEmpty = false;

PKCard card = null;

if (point == null){

point = main.getGroundLabelLocation(n);

isEmpty = true;

}

else{

card = (PKCard) main.table.get(point);

}

if (isEmpty || (this.value + 1 == card.getCardValue())){

point.y += 40;

if (isEmpty) point.y -= 20;

this.setNextCardLocation(point);

main.table.remove(this.getLocation());

point.y -= 20;

this.setLocation(point);

main.table.put(point, this);

this.initPoint = point;

if (this.previousCard != null){

this.previousCard.turnFront();

this.previousCard.setCanMove(true);

}

this.setCanMove(true);

}

else{

this.setNextCardLocation(null);

main.table.remove(this.getLocation());

this.setLocation(this.initPoint);

main.table.put(this.initPoint, this);

return;

}

point = main.getLastCardLocation(n);

card = (PKCard) main.table.get(point);

if (card.getCardValue() == 1){

point.y -= 240;

card = (PKCard) main.table.get(point);

if (card != null && card.isCardCanMove()){

main.haveFinish(n);

}

}

}

/*

**方法:放置纸牌

*/

public void setNextCardLocation(Point point){

PKCard card = main.getNextCard(this);

if (card != null){

if (point == null){

card.setNextCardLocation(null);

main.table.remove(card.getLocation());

card.setLocation(card.initPoint);

main.table.put(card.initPoint, card);

}

else{

point = new Point(point);

point.y += 20;

card.setNextCardLocation(point);

point.y -= 20;

main.table.remove(card.getLocation());

card.setLocation(point);

main.table.put(card.getLocation(), card);

card.initPoint = card.getLocation();

}

}

}

/**

**返回值:int

**方法:判断可用列

*/

public int whichColumnAvailable(Point point){

int x = point.x;

int y = point.y;

int a = (x - 20) / 101;

int b = (x - 20) % 101;

if (a != 9){

if (b > 30 && b <= 71){

a = -1;

}

else if (b > 71){

a++;

}

}

else if (b > 71){

a = -1;

}

if (a != -1){

Point p = main.getLastCardLocation(a);

if (p == null) p = main.getGroundLabelLocation(a);

b = y - p.y;

if (b <= -96 || b >= 96){

a = -1;

}

}

return a;

}

public void mouseEntered(MouseEvent arg0){

}

public void mouseExited(MouseEvent arg0){

}

/**

**用鼠标拖动纸牌

*/

public void mouseDragged(MouseEvent arg0){

if (canMove){

int x = 0;

int y = 0;

Point p = arg0.getPoint();

x = p.x - point.x;

y = p.y - point.y;

this.moving(x, y);

}

}

/**

**返回值:void

**方法:移动(x,y)个位置

*/

public void moving(int x, int y){

PKCard card = main.getNextCard(this);

Point p = this.getLocation();

//将组件移动到容器中指定的顺序索引。

pane.setComponentZOrder(this, 1);

//在Hashtable中保存新的节点信息

main.table.remove(p);

p.x += x;

p.y += y;

this.setLocation(p);

main.table.put(p, this);

if (card != null) card.moving(x, y);

}

public void mouseMoved(MouseEvent arg0){

}

/**

**构造函数

*/

public PKCard(String name, Spider spider){

super();

this.type = new Integer(name.substring(0, 1)).intValue();

this.value = new Integer(name.substring(2)).intValue();

this.name = name;

this.main = spider;

this.pane = this.main.getContentPane();

this.addMouseListener(this);

this.addMouseMotionListener(this);

this.setIcon(new ImageIcon("images/rear.gif"));

this.setSize(71, 96);

this.setVisible(true);

}

/**

**返回值:void

**方法:令纸牌显示正面

*/

public void turnFront(){

this.setIcon(new ImageIcon("images/" + name + ".gif"));

this.isFront = true;

}

/**

**返回值:void

**方法:令纸牌显示背面

*/

public void turnRear(){

this.setIcon(new ImageIcon("images/rear.gif"));

this.isFront = false;

this.canMove = false;

}

/**

**返回值:void

**方法:将纸牌移动到点point

*/

public void moveto(Point point){

this.setLocation(point);

this.initPoint = point;

}

/**

**返回值:void

**方法:判断牌是否能移动

*/

public void setCanMove(boolean can){

this.canMove = can;

PKCard card = main.getPreviousCard(this);

if (card != null && card.isCardFront()){

if (!can){

if (!card.isCardCanMove()){

return;

}

else{

card.setCanMove(can);

}

}

else{

if (this.value + 1 == card.getCardValue()

&& this.type == card.getCardType()){

card.setCanMove(can);

}

else{

card.setCanMove(false);141

蜘蛛纸牌java课设_java蜘蛛纸牌游戏设计相关推荐

  1. 签到考勤java课设_Java程序设计课程设计学生考勤系统Word版

    <Java程序设计课程设计学生考勤系统Word版>由会员分享,可在线阅读,更多相关<Java程序设计课程设计学生考勤系统Word版(6页珍藏版)>请在人人文库网上搜索. 1.传 ...

  2. 学生宿舍管理系统java课设_JAVA学生宿舍管理系统

    需要的工具 1.SQL Server 2.Eclipse 3.JDBC连接数据库驱动 https://download.microsoft.com/download/A/F/B/AFB381FF-70 ...

  3. 【源码+教程】Java课设项目_12款最热最新Java游戏项目_Java游戏开发_Java小游戏_飞翔的小鸟_王者荣耀_超级玛丽_推箱子_黄金矿工_贪吃蛇

    马上就要期末了,同学们课设做的如何了呢?本篇为大家带来了12款热门Java小游戏项目的源码和教程,助力大家顺利迎接暑假![源码+教程]Java课设项目_12款最热最新Java游戏项目_Java游戏开发 ...

  4. java 课设 商品库存管理系统

    比较辛苦的java课设!写了蛮久的,战斗了好多个通宵. 下载https://download.csdn.net/download/qq_37871063/10297290 入门:JAVAFX+MVC+ ...

  5. 华南农业大学课设——数据结构课设、Java课设、操作系统课设

    文章目录 缘起 大二上-数据结构课设(高校教学管理系统)-C++.Qt 视频演示 感想 大二下-Java课设(流程图绘制程序)-JavaFX 视频演示 感想 大三上-操作系统课设(模拟磁盘文件系统实现 ...

  6. 学生信息管理系统(成绩统计)Java课设

    下载地址:学生信息管理系统(成绩统计)Java课设-Web服务器文档类资源-CSDN下载 ├── StudentInfo │   ├── bin │   │   ├── com │   │   │   ...

  7. JAVA课设单人版五子棋小游戏

    内容介绍:该程序为Java课设的单人版五子棋小游戏,通过eclipse编辑,实现了动作事件的监听与处理,以及JavaSwing的界面编程.  编辑排行榜,包含局数,结果,步数,以及"关于我们 ...

  8. Java课设——ArxivHelper

    项目地址https://github.com/PKUCSS/arxiv-helper How to run运行方式:java -jar arxiv-helper.jar Tips:We use pyi ...

  9. 100套java课设源码参考/毕设源码代码参考

    引言:本人是一个Java 开发者,喜欢分享Java课设源码和代码,用于课程设计或者作业学习参考噢,开发一些有技术含量的Java web源码,主要的技术有JSP+Servlet,SSM/SpringBo ...

最新文章

  1. python操作mysql数据库依赖包_python安装mysql的依赖包mysql-python操作
  2. 微服务架构编码,构建
  3. 【OpenCV学习】brg转换hsv函数
  4. js rem 单位适配(手机、平板、PC)?
  5. 企业实战_23_MyCat SQL防火墙
  6. html记仇表情包源码,写小本本记仇表情包
  7. 6.边缘检测:梯度——边缘检测、导数与边缘、什么是梯度_2
  8. html 3重嵌套选项卡,这对HTML标签嵌套在SEO优化上,其实99%的人都不知道!
  9. jquery教程_jQuery教程
  10. POJ 2828 Buy Tickets(单点更新) 详细题解和思路
  11. 自己攒的正则表达式---判断汉字、字符但不要数字
  12. 商业 GIS 软件:专有地图软件列表
  13. 软考备考-系统构架师-21-系统架构师考纲整理
  14. 终极搞定硬盘“A disk read error occured,Press Ctrl+Alt+Del to restart”报错的彻底解决方法...
  15. 视频存储网站服务器配置,视频存储服务器配置
  16. apache的IO包中的FileUtils方法的使用
  17. js设置元素垂直居中
  18. 百度智能云虚拟主机搭建ThinkPHP5.0项目
  19. STM32微控制器SPI接口NSS管理分析
  20. 电话面试 - 招银网络科技 - 数据研发工程师

热门文章

  1. 这个国外大学生的作弊神器,竟是乔布斯的老朋友做的?
  2. Microsoft Teams会议文件无法下载或在线访问
  3. 将数组排列成左边小,中间相等,右边大的形式 给定链表节点数组和某个值
  4. Ubuntu 13.04 双显卡安装NVIDIA GT630M驱动
  5. dnf加物理攻击的卡片有哪些_dnf物理攻击宝珠有哪些 dnf90版本物理攻击宝珠-下载吧...
  6. Linux下抓包工具tcpdump使用
  7. 应对恶意网站 IE常见的故障解决办法
  8. 计算机丢失tool dll,catchtools.dll怎么删除,在任务管理器里面找不到
  9. TX2调试之远程桌面控制
  10. 10道题搞懂色彩搭配的6大准则,让你的图表开口说话!