summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/JRummikub.java
blob: 9571446e2af77b355062f13e72e4e80e21b087db (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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, false), new Position(0, 0));
    stones.put(new Stone(10, StoneColor.BLUE, false), new Position(1, 0));
    stones.put(new Stone(9, StoneColor.RED, false), new Position(0.5f, 1));
    stones.put(new Stone(7, StoneColor.BLACK, false), new Position(1.75f, 1));

    Stone stoneJoker = new Stone(0, StoneColor.RED, true);
    stones.put(stoneJoker, new Position(2.5f, 0));
    stones.put(new Stone(0, StoneColor.BLACK, true), 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" : ""));

      }
    });

    // stoneSets on the table
    Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();

    stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE, false)),
        new Position(0.5f, 1));

    List<Stone> stoneList = new ArrayList<Stone>();

    stoneList.add(new Stone(7, StoneColor.BLACK, false));
    Stone stone8 = new Stone(8, StoneColor.BLACK, false);
    stoneList.add(stone8);
    stoneList.add(new Stone(9, StoneColor.BLACK, false));
    stoneList.add(new Stone(10, StoneColor.BLACK, false));

    stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));

    view.getTable().setStoneSets(stoneSets);

    view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
  }

}