package c20110812.model; import java.util.Random; public class MyModel { private int statue; private int type; private Cell[] cells = new Cell[4]; public MyModel() { this(new Random().nextInt(7)+1,new Random().nextInt(4)); } public MyModel(int statue,int type) { this.statue = statue; this.type = type; this.createModel(new Cell(-1,10)); } /**旋转模板*/ public void rotate() { type = (type+1)%4; this.createModel(cells[0]); } public void rotate(int i) { type = (type+i)%4; this.createModel(cells[0]); } /**移动模块*/ public void move(int x,int y) { for(int i=0;i<cells.length;i++){ cells[i]=new Cell(cells[i].getX()+x,cells[i].getY()+y); } } /**产生模块*/ public Cell[] createModel(Cell point) { int x = point.getX(); int y = point.getY(); cells = new Cell[4]; // l: if(this.statue == 1) { switch (this.type){ case 0: cells[0] = new Cell(x,y); cells[1] = new Cell(x-1,y); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x+2,y); break; case 1: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y-1); cells[2] = new Cell(x,y+1); cells[3] = new Cell(x,y+2); break; case 2: cells[0] = new Cell(x,y); cells[1] = new Cell(x-1,y); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x+2,y); break; case 3: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y-1); cells[2] = new Cell(x,y+2); cells[3] = new Cell(x,y+1); break; } } // 倒7: else if(this.statue == 2) { switch (this.type){ case 0: cells[0] = new Cell(x,y); cells[1] = new Cell(x-1,y); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x-1,y+1); break; case 1: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y-1); cells[2] = new Cell(x,y+1); cells[3] = new Cell(x-1,y-1); break; case 2: cells[0] = new Cell(x,y); cells[1] = new Cell(x+1,y); cells[2] = new Cell(x-1,y); cells[3] = new Cell(x+1,y-1); break; case 3: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y-1); cells[2] = new Cell(x,y+1); cells[3] = new Cell(x+1,y+1); break; } } // 7: else if(this.statue == 3) { switch (this.type){ case 0: cells[0] = new Cell(x,y); cells[1] = new Cell(x-1,y); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x-1,y-1); break; case 1: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y-1); cells[2] = new Cell(x,y+1); cells[3] = new Cell(x+1,y-1); break; case 2: cells[0] = new Cell(x,y); cells[1] = new Cell(x+1,y+1); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x-1,y); break; case 3: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x,y-1); cells[3] = new Cell(x-1,y+1); break; } } else if(this.statue == 4) { switch (this.type){ case 0: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x-1,y); cells[3] = new Cell(x+1,y+1); break; case 1: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x-1,y+2); cells[3] = new Cell(x-1,y+1); break; case 2: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x-1,y); cells[3] = new Cell(x+1,y+1); break; case 3: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x-1,y+2); cells[3] = new Cell(x-1,y+1); break; } } else if(this.statue == 5) { switch (this.type){ case 0: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x-1,y+1); break; case 1: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x+1,y+2); cells[3] = new Cell(x+1,y+1); break; case 2: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x-1,y+1); break; case 3: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x+1,y+2); cells[3] = new Cell(x+1,y+1); break; } } else if(this.statue == 6) { cells[0] = new Cell(x,y); cells[1] = new Cell(x,y+1); cells[2] = new Cell(x+1,y); cells[3] = new Cell(x+1,y+1); } else if(this.statue == 7) { switch (this.type){ case 0: cells[0] = new Cell(x,y); cells[1] = new Cell(x-1,y); cells[2] = new Cell(x-1,y-1); cells[3] = new Cell(x-1,y+1); break; case 1: cells[0] = new Cell(x,y); cells[1] = new Cell(x,y-1); cells[2] = new Cell(x-1,y-1); cells[3] = new Cell(x+1,y-1); break; case 2: cells[0] = new Cell(x,y); cells[1] = new Cell(x+1,y); cells[2] = new Cell(x+1,y-1); cells[3] = new Cell(x+1,y+1); break; case 3: cells[0] = new Cell(x,y); cells[1] = new Cell(x+1,y+1); cells[2] = new Cell(x,y+1); cells[3] = new Cell(x-1,y+1); break; } } return cells; } public int getStatue() { return statue; } public void setStatue(int statue) { this.statue = statue; } public int getType() { return type; } public void setType(int type) { this.type = type; } public Cell[] getCells() { return cells; } public void setCells(Cell[] cells) { this.cells = cells; } }
最近下载更多
cy1234567890 LV2
10月31日
ClydeSon LV5
2023年12月27日
微信网友_6699076084797440 LV7
2023年10月30日
tx1121 LV14
2023年4月9日
liangge2115 LV27
2022年12月24日
smyinger LV1
2022年7月12日
wddd1121 LV3
2022年4月8日
闫小玥 LV8
2021年12月22日
396261 LV1
2021年12月7日
luoshun LV3
2021年11月23日
最近浏览更多
cy1234567890 LV2
10月31日
juiceoa LV2
6月14日
cmossomc LV1
5月29日
ClydeSon LV5
2023年12月27日
1112WHQ LV7
2023年11月3日
微信网友_6699076084797440 LV7
2023年10月30日
wangjialiang1 LV17
2023年8月20日
17683946472 LV9
2023年6月8日
小安同学 LV7
2023年5月11日
tx1121 LV14
2023年4月9日