This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
JRummikub/src/jrummikub/JRummikub.java

210 lines
6.5 KiB
Java
Raw Normal View History

package jrummikub;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.UIManager;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.IListener2;
import jrummikub.view.IView;
public class JRummikub {
/**
* @param args
*/
public static void main(String[] args) {
String nativeLF = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(nativeLF);
} catch (Exception e) {
}
IView view = new jrummikub.view.impl.View();
view.getPlayerPanel().setCurrentPlayerName("Player 1");
view.getPlayerPanel().setTimeLeft(42);
view.getTablePanel().setLeftPlayerName("Player 2");
view.getTablePanel().setTopPlayerName("Player 3");
view.getTablePanel().setRightPlayerName("Player 4");
view.getPlayerPanel().getSortByGroupsEvent().add(new IListener() {
@Override
public void handle() {
System.out.println("'Sort by groups' fired");
}
});
view.getPlayerPanel().getSortByRunsEvent().add(new IListener() {
@Override
public void handle() {
System.out.println("'Sort by runs' fired");
}
});
view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
@Override
public void handle() {
System.out.println("'End turn' fired");
}
});
// stones on the board
Map<Stone, Position> stones = new HashMap<Stone, Position>();
stones.put(new Stone(1, StoneColor.ORANGE), new Position(0, 0));
stones.put(new Stone(10, StoneColor.BLUE), new Position(1, 0));
stones.put(new Stone(9, StoneColor.RED), new Position(0.5f, 1));
stones.put(new Stone(7, StoneColor.BLACK), new Position(1.75f, 1));
Stone stoneJoker = new Stone(StoneColor.RED);
stones.put(stoneJoker, new Position(2.5f, 0));
stones.put(new Stone(StoneColor.BLACK), new Position(3.5f, 0));
view.getPlayerPanel().getHandPanel().setStones(stones);
view.getPlayerPanel().getHandPanel().getClickEvent()
.add(new IListener1<Position>() {
@Override
public void handle(Position p) {
System.out.println("Hand clicked at " + p);
}
});
view.getPlayerPanel().getHandPanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Hand clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getPlayerPanel().getHandPanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Hand range-clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getPlayerPanel().getHandPanel().getSetClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Hand set-clicked at " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getClickEvent()
.add(new IListener1<Position>() {
@Override
public void handle(Position p) {
System.out.println("Table clicked at " + p);
}
});
view.getTablePanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Table clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Table range-clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getSetClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Table set-clicked at " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getLeftConnectorClickEvent()
.add(new IListener1<StoneSet>() {
@Override
public void handle(StoneSet s) {
System.out.println("Left connector clicked on " + s);
}
});
view.getTablePanel().getRightConnectorClickEvent()
.add(new IListener1<StoneSet>() {
@Override
public void handle(StoneSet s) {
System.out.println("Right connector clicked on " + s);
}
});
view.getTablePanel().getStoneCollectionPanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Collection clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getStoneCollectionPanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Collection range-clicked on " + s
+ (collect ? ", collect" : ""));
}
});
view.getTablePanel().getStoneCollectionPanel().getSetClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
public void handle(Stone s, Boolean collect) {
System.out.println("Collection set-clicked at " + s
+ (collect ? ", collect" : ""));
}
});
// stoneSets on the table
Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE)), new Position(
0.5f, 1));
List<Stone> stoneList = new ArrayList<Stone>();
stoneList.add(new Stone(7, StoneColor.BLACK));
Stone stone8 = new Stone(8, StoneColor.BLACK);
stoneList.add(stone8);
stoneList.add(new Stone(9, StoneColor.BLACK));
stoneList.add(new Stone(10, StoneColor.BLACK));
stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
view.getTablePanel().setStoneSets(stoneSets);
view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
}
}