-
Notifications
You must be signed in to change notification settings - Fork 0
/
AceFoundationController.java
85 lines (76 loc) · 2.52 KB
/
AceFoundationController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package nvacheishvili;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import heineman.klondike.MoveCardToFoundationMove;
import heineman.klondike.MoveWasteToFoundationMove;
import ks.common.controller.SolitaireReleasedAdapter;
import ks.common.games.Solitaire;
import ks.common.model.BuildablePile;
import ks.common.model.Card;
import ks.common.model.Column;
import ks.common.model.Move;
import ks.common.model.Pile;
import ks.common.view.BuildablePileView;
import ks.common.view.CardView;
import ks.common.view.ColumnView;
import ks.common.view.Container;
import ks.common.view.PileView;
import ks.common.view.Widget;
public class AceFoundationController extends SolitaireReleasedAdapter{
Archway a;
PileView aceFoundation;
public AceFoundationController(Archway a, PileView aceFoundation) {
super(a);
this.a = a;
this.aceFoundation = aceFoundation;
}
public void mouseReleased(MouseEvent me) {
Container c = theGame.getContainer();
/** Return if there is no card being dragged chosen. */
Widget draggingWidget = c.getActiveDraggingObject();
if (draggingWidget == Container.getNothingBeingDragged()) {
System.err.println ("FoundationController::mouseReleased() unexpectedly found nothing being dragged.");
c.releaseDraggingObject();
return;
}
/** Recover the from BuildablePile OR waste Pile */
Widget fromWidget = c.getDragSource();
if (fromWidget == null) {
System.err.println ("FoundationController::mouseReleased(): somehow no dragSource in container.");
c.releaseDraggingObject();
return;
}
// Determine the To Pile
Pile foundation = (Pile) aceFoundation.getModelElement();
if(fromWidget instanceof PileView){
Pile pile = (Pile) fromWidget.getModelElement();
CardView cardView = (CardView) draggingWidget;
Card theCard = (Card) cardView.getModelElement();
Move move = new MoveCardReserveToAce(pile,foundation, theCard);
if(move.doMove(a)){
a.pushMove(move);
a.refreshWidgets();
}
else{
fromWidget.returnWidget(draggingWidget);
}
c.releaseDraggingObject();
c.repaint();
}
else if(fromWidget instanceof ColumnView){
Column column = (Column) fromWidget.getModelElement();
CardView cardView = (CardView) draggingWidget;
Card theCard = (Card) cardView.getModelElement();
Move move = new MoveCardTableuToAce(column,foundation, theCard);
if(move.doMove(a)){
a.pushMove(move);
a.refreshWidgets();
}
else{
fromWidget.returnWidget(draggingWidget);
}
c.releaseDraggingObject();
c.repaint();
}
}
}