国情备忘录观后感-艺术论文.doc_第1页
国情备忘录观后感-艺术论文.doc_第2页
国情备忘录观后感-艺术论文.doc_第3页
国情备忘录观后感-艺术论文.doc_第4页
国情备忘录观后感-艺术论文.doc_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

java蜘蛛纸牌游戏设计-论文java蜘蛛纸牌游戏源程序AboutDialog.javaimport javax.swing.*;import java.awt.*;/*“关于”窗口*/public class AboutDialog extends JDialogJPanel 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);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 Threadprivate 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 30 & 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)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(); = 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; elsecard.setCanMove(can); else if (this.value + 1 = card.getCardValue() & this.type = card.getCardType()card.setCanMove(can);elsecard.setCanMove(false);141java蜘蛛纸牌游戏源代码 /* *返回值:boolean *方法:判断card是否是正面 */public boolean isCardFront() return this.isFront; /* *返回值:boolean *方法:返回是否能够移动 */ public boolean isCardCanMove() return this.canMove; /* *返回值:int *方法:获得card的内容值 */public int getCardValue() return value; /* *返回值:int *方法:获得card的类型 */public int getCardType() return type; import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;public class Spider extends JFrame/整型变量,表示难度等级为:简单public static final int EASY = 1; /整型变量,表示难度等级为:普通public static final int NATURAL = 2; /整型变量,表示难度等级为:难public static final int HARD = 3; /设定初始难度等级为简单private int grade = Spider.EASY; private Container pane = null; /生成纸牌数组private PKCard cards = new PKCard104; private JLabel clickLabel = null; private int c = 0; private int n = 0; private int a = 0; private int finish = 0; Hashtable table = null; private JLabel groundLabel = null; public static void main(String args) Spider spider = new Spider();spider.setVisible(true); /* *构造函数 */ public Spider()setTitle(蜘蛛牌); setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); /设置框架的大小setSize(1024, 742); /生成SpiderMenuBar对象,并放置在框架之上setJMenuBar(new SpiderMenuBar(this); pane = this.getContentPane(); /设置背景颜色pane.setBackground(new Color(0, 112, 26); /将布局管理器设置成为nullpane.setLayout(null); clickLabel = new JLabel(); clickLabel.setBounds(883, 606, 121, 96); pane.add(clickLabel); clickLabel.addMouseListener(new MouseAdapter() public void mouseReleased(MouseEvent me) if (c 60)Spider.this.deal(); ); this.initCards(); this.randomCards(); this.setCardsLocation(); groundLabel = new JLabel10;java蜘蛛纸牌游戏源代码int x = 20; for (int i = 0; i 10; i+) groundLabeli = new JLabel(); groundLabeli .setBorder(javax.swing.BorderFactory .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED); groundLabeli.setBounds(x, 25, 71, 96); x += 101; this.pane.add(groundLabeli); this.setVisible(true); this.deal(); this.addKeyListener(new KeyAdapter() class Show extends Thread public void run() Spider.this.showEnableOperator(); public void keyPressed(KeyEvent e) if (finish != 8) if (e.getKeyCode() = KeyEvent.VK_D & c 60) Spider.this.deal(); else if (e.getKeyCode() = KeyEvent.VK_M) new Show().start(); ); /* *开始新游戏 */public void newGame() this.randomCards(); this.setCardsLocation(); this.setGroundLabelZOrder(); this.deal(); /* *返回值:int *返回牌的数量 */public int getC() return c; /* *设置等级 */public void setGrade(int grade) this.grade = grade; /* *纸牌初始化 */public void initCards() /如果纸牌已被赋值,即将其从框架的面板中移去if (cards0 != null) for (int i = 0; i 104; i+) pane.remove(cardsi); int n = 0; /通过难度等级,为n赋值if (this.grade = Spider.EASY) n = 1; else if (this.grade = Spider.NATURAL) n = 2; else n = 4; /为card赋值 for (int i = 1; i = 8; i+) for (int j = 1; j = 13; j+) cards(i - 1) * 13 + j - 1 = new PKCard(i % n + 1) + - + j, this); /随机纸牌初始化this.randomCards(); /* *纸牌随机分配 */public void randomCards() PKCard temp = null; /随机生成牌号for (int i = 0; i 52; i+) int a = (int) (Math.random() * 104); int b = (int) (Math.random() * 104); temp = cardsa; cardsa = cardsb; cardsb = temp; /* *设置还原 */public void setNA() a = 0; n = 0; /* *设置纸牌的位置 */public void setCardsLocation() table = new Hashtable(); c = 0; finish = 0; n = 0; a = 0; int x = 883; int y = 580;/初始化待展开的纸牌 for (int i = 0; i 6; i+) for (int j = 0; j 5; i-) for (int j = 0; j = 104) continue; pane.add(cardsn); cardsn.turnRear(); cardsn.moveto(new Point(x, y); table.put(new Point(x, y), cardsn); x += 101; x = 20;java蜘蛛纸牌游戏源代码 y -= 5; /* *返回值:void *方法:显示可移动的操作 */public void showEnableOperator() int x = 0; out: while (true) Point point = null; PKCard card = null; do if (point != null)n+; point = this.getLastCardLocation(n); while (point = null) point = this.getLastCardLocation(+n); if (n = 10) n = 0; x+; if (x = 10) break out; card = (PKCard) this.table.get(point); while (!card.isCardCanMove(); while (this.getPreviousCard(card) != null & this.getPreviousCard(card).isCardCanMove() card = this.getPreviousCard(card); if (a = 10)a = 0; for (; a 10; a+) if (a != n) Point p = null; PKCard c = null; do if (p != null)a+;p = this.getLastCardLocation(a); int z = 0; while (p = null) p = this.getLastCardLocation(+a); if (a = 10) a = 0; if (a = n) a+; z+; if (z = 10) break out; c = (PKCard) this.table.get(p); while (!c.isCardCanMove(); if (c.getCardValue() = card.getCardValue() + 1) card.flashCard(card); try Thread.sleep(800); catch (InterruptedException e) e.printStackTrace(); c.flashCard(c); a+; if (a = 10)n+; break out; n+; if (n = 10)n = 0; x+; if (x = 10)break out; /* *返回值:void *方法:游戏运行 */public void deal() this.setNA(); /判断10列中是否空列for (int i = 0; i 10; i+) if (this.getLastCardLocation(i) = null) JOptionPane.showMessageDialog(this, 有空位不能发牌!, 提示, JOptionPane.WARNING_MESSAGE); return; int x = 20; for (int i = 0; i 10; i+) Point lastPoint = this.getLastCardLocation(i); /这张牌应“背面向上”if (c = 0) lastPoint.y += 5; /这张牌应“正面向上”else lastPoint.y += 20; table.remove(cardsc + i.getLocation(); cardsc + i.moveto(lastPoint); table.put(new Point(lastPoint), cardsc + i); cardsc + i.turnFront(); cardsc + i.setCanMove(true); /将组件card移动到容器中指定的顺序索引。 this.pane.setComponentZOrder(cardsc + i, 1); Point point = new Point(lastPoint); if (cardsc + i.getCardValue() = 1) int n = cardsc + i.whichColumnAvailable(point); point.y -= 240; PKCard card = (PKCard) this.table.get(point); if (card != null & card.isCardCanMove() this.haveFinish(n); x += 101; c += 10; /* *返回值:PKCard对象 *方法:获得card上面的那张牌 */public PKCard getPreviousCard(PKCard card) Point point = new Point(card.getLocation(); point.y -= 5; card = (PKCard) table.get(point); if (card != null)return card; point.y -= 15; card = (PKCard) table.get(point); return card; /* *返回值:PKCard对象 *方法:取得card下面的一张牌 */public PKCard getNextCard(PKCard card) Point point = new Point(card.getLocation(); point.y += 5; card = (PKCard) table.get(point); if (card != null)return card; point.y += 15; card = (PKCard) table.get(point); return card; /* *返回值:Point对象 *方法:取得第column列最后一张牌的位置

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论