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
Matthias Schiffer b2d21a7f2d Don't use deprecated Stone constructor
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@72 72836036-5685-4462-b002-a69064685172
2011-05-03 14:29:57 +02:00

175 lines
5.4 KiB
Java

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.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.getTable().setLeftPlayerName("Player 2");
view.getTable().setTopPlayerName("Player 3");
view.getTable().setRightPlayerName("Player 4");
view.getPlayerPanel().getSortByNumberEvent().add(new IListener() {
@Override
public void fire() {
System.out.println("'Sort by number' fired");
}
});
view.getPlayerPanel().getSortByColorEvent().add(new IListener() {
@Override
public void fire() {
System.out.println("'Sort by color' fired");
}
});
view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
@Override
public void fire() {
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().getBoard().setStones(stones);
view.getPlayerPanel().getBoard().getClickEvent()
.add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Board clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getPlayerPanel().getBoard().getRangeClickEvent()
.add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Board range-clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getPlayerPanel().getBoard().getSetClickEvent()
.add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Board set-clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getTable().getClickEvent().add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Table clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getTable().getRangeClickEvent()
.add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Table range-clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getTable().getSetClickEvent().add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Table set-clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getTable().getStoneCollection().getClickEvent()
.add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Collection clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getTable().getStoneCollection().getRangeClickEvent()
.add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Collection range-clicked at " + p
+ (collect ? ", collect" : ""));
}
});
view.getTable().getStoneCollection().getSetClickEvent()
.add(new IListener2<Position, Boolean>() {
@Override
public void fire(Position p, Boolean collect) {
System.out.println("Collection set-clicked at " + p
+ (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.getTable().setStoneSets(stoneSets);
view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
}
}