java斗地主程序源代码

  • Y4_457669
    了解作者
  • 1.9MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-21 11:42
    上传日期
用java写的斗地主程序的源代码(包括客户端和服务器端的源代码)
源代码.rar
内容介绍
//界面类*********************************************************************************************** import ds.GameMsg; import ds.Poke; import ds.Protocol; import ds.UserMsg; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; import java.net.Socket; import java.util.ArrayList; import java.util.Iterator; import javax.imageio.ImageIO; import javax.swing.JPanel; //用户头像男,女各三张,每张桌子每个座位对应的图片时确定的 public class DdzArea extends JPanel { BufferedImage backgroundImage; BufferedImage backPokeImage; BufferedImage pokeImage[][]; BufferedImage clockImage; BufferedImage dzImage; BufferedImage bjzImage; BufferedImage bczImage; BufferedImage pointImage[]; BufferedImage readyImage; BufferedImage startImage[]; BufferedImage bjImage[]; BufferedImage bcImage[]; BufferedImage cpImage[]; BufferedImage oneImage[]; BufferedImage twoImage[]; BufferedImage threeImage[]; BufferedImage boyImage[]; BufferedImage girlImage[]; BufferedImage playerBackImage; private int xPos;//鼠标指针所在x坐标 private int yPos; public DdzArea() { readImage(); setSize(810, 738); repaint(); } public void setPos(int i, int j) { xPos = i; yPos = j; } public void readImage() { String as[] = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "g" }; try { backgroundImage = ImageIO.read(new File("ico/ddz/background.png")); playerBackImage = ImageIO.read(new File("ico/ddz/playerBack.png")); boyImage = new BufferedImage[3]; for (int i = 0; i < 3; i++) boyImage[i] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/player/").append(i + 1).append("_b.gif").toString())); girlImage = new BufferedImage[3]; for (int j = 0; j < 3; j++) girlImage[j] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/player/").append(j + 1).append("_g.gif").toString())); backPokeImage = ImageIO.read(new File("ico/ddz/poke/back.gif")); pokeImage = new BufferedImage[14][4]; for (int k = 0; k < 14; k++) { for (int l2 = 0; l2 < 4 && (k != 13 || l2 <= 1); l2++) pokeImage[k][l2] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/poke/").append(as[k]).append(l2).append(".gif").toString())); } clockImage = ImageIO.read(new File("ico/ddz/clock.png")); dzImage = ImageIO.read(new File("ico/ddz/dz.png")); bczImage = ImageIO.read(new File("ico/ddz/bcz.png")); readyImage = ImageIO.read(new File("ico/ddz/ready.png")); startImage = new BufferedImage[2]; for (int l = 0; l < 2; l++) startImage[l] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/start").append(l).append(".png").toString())); bjImage = new BufferedImage[2]; for (int i1 = 0; i1 < 2; i1++) bjImage[i1] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/bj").append(i1).append(".png").toString())); bcImage = new BufferedImage[2]; for (int j1 = 0; j1 < 2; j1++) bcImage[j1] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/bc").append(j1).append(".png").toString())); cpImage = new BufferedImage[2]; for (int k1 = 0; k1 < 2; k1++) cpImage[k1] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/cp").append(k1).append(".png").toString())); oneImage = new BufferedImage[3]; for (int l1 = 0; l1 < 3; l1++) oneImage[l1] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/one").append(l1).append(".png").toString())); twoImage = new BufferedImage[3]; for (int i2 = 0; i2 < 3; i2++) twoImage[i2] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/two").append(i2).append(".png").toString())); threeImage = new BufferedImage[2]; for (int j2 = 0; j2 < 2; j2++) threeImage[j2] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/three").append(j2).append(".png").toString())); pointImage = new BufferedImage[4]; for (int k2 = 0; k2 < 4; k2++) pointImage[k2] = ImageIO.read(new File((new StringBuilder()).append("ico/ddz/point").append(k2).append(".png").toString())); } catch (Exception exception) { System.out.println("读取文件失败"); exception.printStackTrace(); } } public void paint(Graphics g) { try { if (!Client.gameMsg.isStart())//画玩家的背景 g.drawImage(getBackgroundImage(Client.gameMsg.isStart()), 0, 0, null);//一次性画三个玩家的背景 else g.drawImage(backgroundImage, 0, 0, null); if (!Client.gameMsg.isStart()) { for (Iterator iterator = Client.partner.iterator(); iterator.hasNext();) { UserMsg usermsg = (UserMsg)iterator.next(); Point point5 = getSite(usermsg.getSite()); int k3 = (int)point5.getX(); int k5 = (int)point5.getY(); g.setColor(Color.white); g.setFont(new Font("宋体", 0, 12)); g.drawString((new StringBuilder()).append("昵称 : ").append(usermsg.getUserName()).toString(), k3, k5 + 180); g.drawString((new StringBuilder()).append("级别 : ").append(UserPanel.getCaste(usermsg.getScore())).toString(), k3, k5 + 195); if (usermsg.getSex().equals("女"))//画玩家 g.drawImage(girlImage[usermsg.getSite() - 1], k3, k5, null); else g.drawImage(boyImage[usermsg.getSite() - 1], k3, k5, null); } if (!Client.gameMsg.isReady())//还未准备 if (xPos == (int)Ddz.START_BN.getX() && yPos == (int)Ddz.START_BN.getY())//鼠标位于开始键上 g.drawImage(startImage[1], (int)Ddz.START_BN.getX(), (int)Ddz.START_BN.getY(), null); else g.drawImage(startImage[0], (int)Ddz.START_BN.getX(), (int)Ddz.START_BN.getY(), null); for (int i = 0; i < 3; i++) { Point point2 = getSite(i + 1); if (Ddz.ready[i]) g.drawImage(readyImage, (int)point2.getX() + 70, (int)point2.getY() + 110, null); } } else {//游戏开始了 for (Iterator iterator1 = Client.partner.iterator(); iterator1.hasNext();) { UserMsg usermsg1 = (UserMsg)iterator1.next(); int j2 = usermsg1.getSite(); Point point7 = getSite(j2); int l5 = (int)point7.getX(); int l7 = (int)point7.getY(); if (l5 == 510)//获取文字描述的起始坐标 { l5 = 690; l7 = 200; } else if (l5 == 210) { l5 = 0; l7 = 200; } else { l5 = 80; l7 = 530; } g.setColor(Color.white); g.setFont(new Font("宋体", 0, 12)); if (l5 == 80) {//玩家图片下方的文字描述 g.drawString((new StringBuilder()).append("昵称 : ").append(usermsg1.getUserName()).toString(), 310, 665); g.drawString((new StringBuilder()).append("级别 : ").append(UserPanel.getCaste(usermsg1.getScore())).toString(), 310 + 12 * (usermsg1.getUserName().length() + 5), 665); if (Client.gameMsg.getBottomScore() == 0) g.drawString("底分 : -- ", 330, 685); else g.drawString((new StringBuilder()).append("底分 : ").append(Client.gameMsg.getBottomScore()).append(" ").toString(), 340, 685); g.drawString((new StringBuilder()).append("倍数 : ").append(Client.gameMsg.getMul()).append(" ").toString(), 410, 685); } else { g.drawString((new StringBuilder()).append("昵称 : ").append(usermsg1.getUserName()).toString(), l5 + 25, l7 + 180); g.drawString((new StringBuilder()).append("级别 : ").append(UserPanel.getCaste(usermsg1.getScore())).toString(), l5 + 25, l7 + 195); } if (usermsg1.getSex().equals("女")) g.drawImage(girlImage[usermsg1.getSite() - 1], l5, l7, null); else g.drawImage(boyImage[usermsg1.getSite() - 1], l5, l7, null); } if (Client.gameMsg.getOrder() != 0) if
评论
    相关推荐