diff --git a/src/com/sheep/model/Brand.java b/src/com/sheep/model/Brand.java index 4431117..c9ee859 100644 --- a/src/com/sheep/model/Brand.java +++ b/src/com/sheep/model/Brand.java @@ -2,6 +2,9 @@ package com.sheep.model; /* Brand代表游戏中一个牌 +每一个单独的牌都有属于自己的属性:坐标位置、图片、长宽 +为方便进行操作,每个牌都会记录单元格、消除框和地图 +Brand类实现牌类的初始化、图标转为彩色和点击监听事件 */ import com.sheep.util.MapUtil; @@ -20,21 +23,21 @@ public class Brand extends Component{ private Integer y;//坐标y private Integer width;//宽 private Integer height;//高 - private Map map; + private Map map;//当前存储所在的map - EliminateBox eliminateBox = new EliminateBox(); + EliminateBox eliminateBox = new EliminateBox();//将要绘制到的消除框 private Cell cell;//当前牌放置的单元格位置 - //有参构造器 + //有参构造器,传入名字实现属性的赋值 public Brand(String name){ - this.name = name; + this.name = name;//牌的名字 //指定图片 this.image = Toolkit.getDefaultToolkit().getImage("imgs\\"+name+".png"); this.garyImage = Toolkit.getDefaultToolkit().getImage("imgs\\"+name+"_gray.png"); - this.isGray = false;//默认为彩色图片 + this.isGray = false;//默认为彩色图片,方便第一层的图标不用判断是否置灰 //设置宽高(图片大小为50*50) this.width = 50; @@ -44,7 +47,7 @@ public class Brand extends Component{ this.x = 0; this.y = 0; - //添加鼠标点击的监听事件 + //添加鼠标点击的监听事件,灰色不可点击,否则,放到消除框 this.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { diff --git a/src/com/sheep/model/Cell.java b/src/com/sheep/model/Cell.java index 9c7c6da..9231c06 100644 --- a/src/com/sheep/model/Cell.java +++ b/src/com/sheep/model/Cell.java @@ -3,6 +3,7 @@ package com.sheep.model; /* 单元格类 两种状态 0 无牌 1 有牌 +存储map用于向Brand赋值 */ public class Cell { diff --git a/src/com/sheep/model/EliminateBox.java b/src/com/sheep/model/EliminateBox.java index 415dee6..8e94f04 100644 --- a/src/com/sheep/model/EliminateBox.java +++ b/src/com/sheep/model/EliminateBox.java @@ -2,6 +2,8 @@ package com.sheep.model; /* 消除区域 +点击的牌放入消除区域 +此类主要负责点击牌的排序、消除、判断游戏是否失败 */ import javax.swing.*; @@ -44,7 +46,7 @@ public class EliminateBox { } } - paint(); + paint();//图标绘制到消除框 over(brand); } @@ -57,6 +59,7 @@ public class EliminateBox { } } + //当图标达到最大,游戏失败 void over(Brand brand){ if(slot.size() >= 7){ JOptionPane.showMessageDialog(brand,"游戏失败"); diff --git a/src/com/sheep/model/Layer.java b/src/com/sheep/model/Layer.java index 7ae6b99..f149dae 100644 --- a/src/com/sheep/model/Layer.java +++ b/src/com/sheep/model/Layer.java @@ -3,6 +3,8 @@ package com.sheep.model; /* 图层类 二维表格 +记录当前地图的坐标偏移量、行、列、最大存储量、当前牌数量 +存储map向Brand赋值,上一层Layer,方便置灰函数操作 */ public class Layer { @@ -17,11 +19,11 @@ public class Layer { private Layer parent;//上一层图层对象 - private Cell[][] cells = null; + private Cell[][] cells = null;//存储的二维表格 - private Map map; + private Map map;//当前所在的map - //有参构造 + //有参构造,根据传入的行列实现表格初始化 public Layer(Integer rowNum,Integer colNum) { this.rowNum = rowNum; this.colNum = colNum; @@ -35,6 +37,7 @@ public class Layer { offsety = 0; } + //打印表格,用于开发阶段测试使用 public void showCells(){ for(int row = 0;row < cells.length;row++){ for(int col = 0;col