package Controller;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JPanel;
import Bean.*;
import Bean.Poker;
import Bean.PokerSize;
public class Controller {
ArrayList<Poker> list = new ArrayList();
private ButtomList buttomList[];// 0位置的元素,处在最上面
private ReadyList readyList;
private OutList outList;
private MouseList mouseList;
private ResultList resultList[];
// private int
public Controller(ButtomList buttomList[], ReadyList readyList,
OutList outList, MouseList mou, ResultList[] result) {
this.buttomList = buttomList;
this.readyList = readyList;
this.outList = outList;
this.mouseList = mou;
this.resultList = result;
// this.InitialPoker();
}
public void InitialPoker() {
for (int i = 0; i < buttomList.length; i++)
buttomList[i] = new ButtomList(i);
Poker poker;
for (int color = 1; color <= 4; color++)
for (int num = 13; num >= 1; num--) {
poker = new Poker(color, num);
list.add(poker);
}
Random ran = new Random();
// 分配到每个list里面
while (!list.isEmpty()) {
int n = ran.nextInt(PokerSize.number + 1);
if (n == PokerSize.number) {
if (readyList.Size() < 31) {
Poker temp = list.remove(0);
readyList.add(temp);
}
} else {
if ((n + 1) > buttomList[n].Size()) {// 可以加入这个list
Poker temp = list.remove(0);
buttomList[n].add(temp);
} else
continue;
}
}
// 把每一列的最后一张牌设置为向上
for (int i = 0; i < PokerSize.number; i++)
buttomList[i].getLast().setUp();
}
public void printSize() {
for (int i = 0; i < PokerSize.number; i++)
System.out.println(i + " = " + buttomList[i].Size());
System.out.println("Left = " + this.readyList.Size());
}
public boolean OutListToMouse(Point mouse) {
if(!outList.isEmpty()){
Poker poker = outList.removeLast();
mouseList.setMouse(mouse);
mouseList.setFrom(7);
mouseList.add(poker);
return true;
}
return false;
}
public boolean ButtomToMouse(Point mouse) {
if (this.onButtomList(mouse)) {
int col = this.onWhichColumn(mouse);
int row = this.onWhichRow(mouse);
if (row < 0)
return false;
Poker poker = this.PokerOnButtom(col, row);
if (!poker.isSelected())
return false;
int size = buttomList[col].Size();
int nums = size - row;
mouseList.setMouse(mouse);
mouseList.setFrom(col);
for (int i = 0; i < nums; i++) {
Poker temp = buttomList[col].remove(row);
mouseList.add(temp);
}
return true;
}
return false;
}
public void ReadyListToOutList() {
if (!readyList.isEmpty()) {
Poker temp = readyList.remove(0);
outList.add(temp);
} else {
if (!outList.isEmpty()) {
while (outList.Size() > 0) {
Poker temp = outList.remove(0);
this.readyList.add(temp);
}
System.out.println("OutList To ReadyList");
}
}
}
public void ButtomToUp(Point x) {
int col = this.onWhichColumn(x);
if (!buttomList[col].isEmpty()
&& !buttomList[col].getLast().isSelected()) {
buttomList[col].getLast().setUp();
}
}
public void ToResult(int select,Point point){
//select =1 从buttom去result,,2从Outlist去buttom
if(select == 1){
if(this.onButtomList(point)){
int row = this.onWhichRow(point);
int col = this.onWhichColumn(point);
Poker temp = this.PokerOnButtom(col, row);
if(temp==null)return;
int color = temp.getColor();
if(resultList[color -1 ].CanBeHere(temp)){
resultList[color -1].add(temp);
buttomList[col].remove(row);
}else System.out.println("can not up");
}
}else if(select == 2){
Poker temp = outList.getLast();
int color = temp.getColor();
if(resultList[color - 1].CanBeHere(temp)){
resultList[color - 1].add(temp);
outList.removeLast();
}
}
}
public boolean ResultToMouse(Point mousepoint){
int x = mousepoint.x;
int y = mousepoint.y;
int n = x / (PokerSize.xWidth + PokerSize.Width);
int yu= x % (PokerSize.xWidth + PokerSize.Width);
if(yu<PokerSize.xWidth)return false;
int row = n -3;
System.out.println(row);
if(resultList[row].isEmpty())return false;
mouseList.setMouse(mousepoint);
mouseList.setFrom(row + 8);
Poker poker = resultList[row].removeLast();
if(poker==null)return false;
mouseList.add(poker);
return true ;
}
public int onWhichRow(Point point) {// 返回行数,也是在确定在column里面的时候,才可以做的
int col = this.onWhichColumn(point);// 得到列坐标,然后
int size = buttomList[col].Size();
if (size == 0)
return -1;// 为空的话,返回-1
Poker last = buttomList[col].getLast();
int y = point.y;
if (y > last.getPoint().y && y < last.getPoint().y + PokerSize.Height)
return size - 1;
else if (y < last.getPoint().y) {
int temp = (y - (PokerSize.Height + PokerSize.upy * 2))
/ PokerSize.xx;
return temp;
}
return -1;
}
public int onWhichColumn(Point point) {// 返回列数坐标,这是在已经确定是在buttomList
int x = point.x;
int y = point.y;
int index = x / (PokerSize.Width + PokerSize.xWidth);
return index;
}
public void updateMouseList(Point mousepoint) {
mouseList.updatePoint(mousepoint);
}
public boolean isLast(int col, int row) {
return ((row + 1) == buttomList[col].Size());
}
public Poker PokerOnButtom(int col, int row) {
return buttomList[col].get(row);
}
public int onReadyList(Point point) {
int result = 0;// 不在返回-1,为空返回0,否则返回有多少张牌
int x = point.x;
int y = point.y;
if (y < PokerSize.upy + PokerSize.Height && y > PokerSize.upy
&& x > PokerSize.xWidth
&& x < PokerSize.xWidth + PokerSize.Width)
return this.readyList.Size();
else
return -1;
}
public int onOutList(Point point) {
int result = 0; // -1为不在这个区域,正数在这个区域,0在这个区域,但是为空
int x = point.x;
int y = point.y;
if (y < PokerSize.upy + PokerSize.Height && y > PokerSize.upy
&& x > PokerSize.xWidth * 2 + PokerSize.Width
&& x < (PokerSize.xWidth + PokerSize.Width) * 2)
return outList.Size();
return -1;
}
public boolean onButtomList(Point point) {// 只是看看是否在这个区域里,不管是否空
int x = point.x;
int y = point.y;
int index = x / (PokerSize.Width + PokerSize.xWidth);// index实际就是列数
int yushu = x % (PokerSize.Width + PokerSize.xWidth);
if (y < PokerSize.Height + PokerSize.upy * 2)
return false;
if (index >= PokerSize.number || yushu < PokerSize.xWidth)// 横向判断
return false;
int size = buttomList[index].Size();
if (size == 0)// 纵向
return true;
else //
if (((size - 1) * PokerSize.xx + PokerSize.Height + PokerSize.Height + PokerSize.upy * 2) > y
&& y > PokerSize.upy * 2 + PokerSize.Height)
return true;
return false;
}
public boolean onResultList(Point mousepoint){
int x = mousepoint.x;
int y = mousepoint.y;
int n = x / (PokerSize.xWidth + PokerSize.Width);
int yu= x % (PokerSize.xWidth + PokerSize.Width);
if(yu<PokerSize.xWidth)return false;
if((y<PokerSize.upy+PokerSize.Height&&y>PokerSize.upy)&&(n>2&&n<=6)){
System.out.println("on resultlist");
return true;
}
System.out.println("not on ResultList");
return false;
}
public void MouseToButtom(Point mousepoint) {
if (this.onButtomList(mousepoint)) {
int col = this.onWhichColumn(mousepoint);
if (this.CanBeHere(mouseList.getFirst(), col)) {
int size = mouseList.Size();
for (int i = 0; i < size; i++) {
Poker poker = mouseList.remove(0);
buttomList[col].add(poker);
}
for(int i=0;i<4;i++)
System.out.println("daxiao=="+resultList[i].Size());
return;
}
}
this.mouseBack();
}
private void mouseBack() {// 因为不符合要求,所以被退回到原来的位置
int fr
没有合适的资源?快使用搜索试试~ 我知道了~
Java实现纸牌游戏
共92个文件
jpg:53个
class:16个
java:15个
4星 · 超过85%的资源 需积分: 50 49 下载量 131 浏览量
2011-11-21
21:29:02
上传
评论 1
收藏 4.23MB RAR 举报
温馨提示
Java实现纸牌游戏,使用了面向对象的思想。
资源推荐
资源详情
资源评论
收起资源包目录
Poker.rar (92个子文件)
Poker
picture
38.jpg 50KB
21.JPG 31KB
14.JPG 40KB
12.JPG 27KB
44.JPG 36KB
10.JPG 84KB
2a.JPG 180KB
3b.JPG 169KB
39.JPG 89KB
42.JPG 37KB
37.jpg 52KB
27.JPG 64KB
b.JPG 126KB
1b.JPG 149KB
25.JPG 48KB
43.JPG 38KB
16.JPG 48KB
28.JPG 81KB
48.JPG 54KB
4a.jpg 139KB
30.JPG 76KB
11.JPG 66KB
15.JPG 52KB
24.JPG 48KB
18.JPG 73KB
29.JPG 82KB
35.JPG 52KB
13.jpg 30KB
19.png 17KB
26.JPG 45KB
34.JPG 41KB
31.JPG 25KB
17.JPG 64KB
22.JPG 30KB
47.JPG 56KB
1a.JPG 150KB
46.JPG 41KB
33.JPG 43KB
4b.JPG 177KB
2b.jpg 135KB
36.JPG 63KB
32.JPG 37KB
2c.JPG 172KB
49.JPG 76KB
1c.JPG 150KB
45.JPG 41KB
3a.JPG 196KB
3c.JPG 145KB
4c.JPG 171KB
a.JPG 146KB
23.JPG 44KB
40.JPG 77KB
41.JPG 21KB
20.JPG 72KB
back.png 8KB
Thumbs.db 184KB
src
Bean
ButtomList.java 755B
MyPokerList.java 992B
MouseList.java 1KB
OutList.java 469B
ResultList.java 1KB
ReadyList.java 456B
PokerSize.java 370B
Poker.java 2KB
log 58B
Controller
FrameListener.java 254B
Controller.java 9KB
PanelTest.java 72B
Listener.java 3KB
Windows
MyPanel.java 7KB
MainFrame.java 1KB
MainPanel.java 3KB
bin
Bean
ReadyList.class 919B
MouseList.class 2KB
MyPokerList.class 2KB
Poker.class 3KB
ButtomList.class 1KB
PokerSize.class 568B
OutList.class 917B
ResultList.class 2KB
log 58B
Controller
FrameListener.class 477B
PanelTest.class 274B
Listener.class 3KB
Controller.class 8KB
Windows
MainFrame.class 2KB
MyPanel$ImageObject.class 2KB
MyPanel.class 6KB
MainPanel.class 3KB
.classpath 301B
.settings
org.eclipse.jdt.core.prefs 629B
.project 381B
共 92 条
- 1
zl0096
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页