Skip to content
This repository
Browse code

Rudimentary player(s) drawn

  • Loading branch information...
commit e6fe2b57d3a22bc6922352c78c60d9602462ca32 1 parent 0737b89
Mark Feltner authored
131 src/gui/GUIBoard.java
@@ -33,7 +33,6 @@
33 33 // GUI Elements
34 34 private GUISpace guiSpace;
35 35 private GamePanel deedPanel;
36   - private LinkedList<Player> players;
37 36 private LinkedList<GUIPlayer> guiPlayers;
38 37
39 38 private int num_spaces;
@@ -51,13 +50,7 @@
51 50 // Animation variables
52 51 private Thread animationThread;
53 52
54   - private int highlighted_space;
55   -
56   - // Token-moving animation
57   - // private Thread move_player_thread;
58   - // private int final_token_space;
59   - // private int current_token_space;
60   - // private Player current_animation_player;
  53 + private int highlighted_space;
61 54
62 55 /*private void drawSpaces() {
63 56 // Length, in GUISpaces, of a side of the board;
@@ -77,7 +70,7 @@
77 70 * Testing constructor. Generates a standard board where each Space is
78 71 * individually numbered.
79 72 */
80   - public GUIBoard(Board board) // {{{
  73 + public GUIBoard(Board board, LinkedList<Player> players) // {{{
81 74 {
82 75 // super(GUISpace.WIDTH * board.getNumSpaces(), GUISpace.HEIGHT *
83 76 // board.getNumSpaces(), DEFAULT_COLOR);
@@ -91,6 +84,13 @@ public GUIBoard(Board board) // {{{
91 84
92 85 this.board = board;
93 86
  87 + this.guiPlayers = new LinkedList();
  88 + for (Player p : players)
  89 + {
  90 + GUIPlayer gp = new GUIPlayer(p);
  91 + this.guiPlayers.add(gp);
  92 + }
  93 +
94 94 this.num_spaces = board.getNumSpaces();
95 95 setPreferredSize(new Dimension((num_spaces/4 + 1) * GUISpace.WIDTH, (num_spaces/4 + 1) * GUISpace.HEIGHT));
96 96 //drawSpaces();
@@ -103,12 +103,6 @@ public GUIBoard(Board board) // {{{
103 103 animationThread.start();
104 104 }// }}}
105 105
106   - public void update(Board b, LinkedList<Player> p)
107   - {
108   - this.board = b;
109   - this.players = p;
110   - }
111   -
112 106 /**
113 107 * run() is from the Runnable interface. animation_thread calls this
114 108 * constantly when it is running.
@@ -177,16 +171,13 @@ public void paintComponent(Graphics g)// {{{
177 171 }
178 172
179 173 // Draw Players
180   - /**
181   - ListIterator<Player> players_iter = this.players.listIterator(0);
182   - while (players_iter.hasNext()) {
183   - GUIPlayer casted_player = new GUIPlayer(players_iter.next());
184   - casted_player.repaint();
185   - if (casted_player != null) {
186   -
187   - }
  174 + ListIterator<GUIPlayer> guiPlayers_iter = this.guiPlayers.listIterator(0);
  175 + while (guiPlayers_iter.hasNext()) {
  176 + GUIPlayer p = guiPlayers_iter.next();
  177 + Point coordinates = getCoordinates(p.getPosition());
  178 + g.drawImage(p.getToken().getBuffer(), (int)coordinates.getX(),
  179 + (int)coordinates.getY(), this);
188 180 }
189   - */
190 181 }// }}}
191 182
192 183 /**
@@ -231,7 +222,7 @@ private int getIndexFromCoordinates( int x, int y )//{{{
231 222 }
232 223
233 224 return -1;
234   - }//}}}
  225 + }
235 226
236 227 /**
237 228 * Maps an point onto the Spaces of the board.
@@ -261,7 +252,7 @@ public void setSelectedSpace(int space) {//{{{
261 252 deedPanel.repaint();
262 253 }
263 254 }
264   - }//}}}
  255 + }
265 256
266 257 private void setHighlightedSpace( int hspace )
267 258 {
@@ -277,33 +268,6 @@ public void setDeedPanel(GamePanel panel) {
277 268 }
278 269
279 270 /**
280   - * WARNING! SIDE EFFECT: the player's position is set to the position of the
281   - * space. This means that the position may get rolled over.
282   - */
283   - public void addPlayerToSpace(int space, GUIPlayer player) {//{{{
284   - if (space < 0)
285   - return;
286   - space = returnValidPosition(space);
287   - int current_token_space = player.getPosition();
288   - int final_token_space = space;
289   - player.setPosition(space); // SIDE EFFECT
290   - // spaces[current_token_space].removePlayer( player );
291   - // spaces[final_token_space].addPlayer( player );
292   - /*
293   - * current_animation_player = player; final_token_space = space;
294   - * move_player_thread = new Thread( this ); move_player_thread.start();
295   - */
296   - BoardAnimation b = new BoardAnimation(current_token_space,
297   - final_token_space, player);
298   - }//}}}
299   -
300   - public void removePlayerFromSpace(int space) {
301   - if (space < 0 || space >= board.getNumSpaces())
302   - return;
303   - // board.spaces[space].removePlayer();
304   - }
305   -
306   - /**
307 271 * Basic sanity-checking on position numbers
308 272 */
309 273 public boolean isValidPosition(int position_num) {
@@ -328,50 +292,56 @@ public Space getSpace(int position_num) {
328 292 return board.spaces.get(position_num);
329 293 }
330 294
  295 + /**
331 296 class BoardAnimation implements Runnable //{{{
332 297 {
333   - private Thread move_player_thread;
  298 + private Thread animation_thread;
334 299 private int final_token_space;
335 300 private int current_token_space;
336   - private GUIPlayer current_animation_player;
337 301 private boolean final_is_lesser_than_current; // used for situations
338 302 // when moving past the
339 303 // zeroth space.
340 304
341   - BoardAnimation(int current_token_space, int final_token_space,
342   - GUIPlayer current_animation_player)
343   - {
344   - this.current_token_space = current_token_space;
345   - this.final_token_space = final_token_space;
346   - this.current_animation_player = current_animation_player;
347   - final_is_lesser_than_current = (final_token_space < current_token_space);
348   -
349   - current_animation_player.setIsMoving(true);
  305 + private GUIPlayer current_animation_player;
  306 + private GUISpace current_space;
  307 + private GUISpace fromSpace;
  308 + private GUISpace toSpace;
350 309
351   - // System.out.println("Animate: " + current_token_space + " " +
352   - // final_token_space);
  310 + BoardAnimation()
  311 + {
  312 + }
353 313
354   - move_player_thread = new Thread(this);
355   - move_player_thread.start();
356   - }
  314 + void movePlayer(GUIPlayer p, GUISpace fromSpace, GUISpace toSpace)
  315 + {
  316 + this.fromSpace = fromSpace;
  317 + this.toSpace = toSpace;
  318 + this.currentSpace = p.;
  319 + this.current_animation_player.setIsMoving(true);
  320 + this.animation_thread = new Thread(this);
  321 + this.animation_thread.start();
  322 + }
357 323
358 324 @Override
359 325 public void run()// {{{
360 326 {
361   - while (move_player_thread != null) {
  327 + while (animation_thread != null) {
362 328 if (current_animation_player == null)
363   - move_player_thread = null;
  329 + animation_thread = null;
364 330
365   - // System.out.println("current: " + current_token_space +
  331 + int start_position = this.fromSpace.getPosition();
  332 + int current_position = this.currentSpace.getPosition();
  333 + int final_position = this.toSpace.getPosition();
  334 +
  335 + // System.out.println("current: " + start_position +
366 336 // " final: " + final_token_space );
367   - if (current_token_space < final_token_space
  337 + if (current_position < final_token_space
368 338 || final_is_lesser_than_current) {
369 339
370   - board.spaces.get(current_token_space).removePlayer(
  340 + board.spaces.get(start_position).removePlayer(
371 341 current_animation_player.getPlayer());
372 342
373   - current_token_space++;
374   - current_token_space = returnValidPosition(current_token_space);
  343 + start_position++;
  344 + start_position = returnValidPosition(current_token_space);
375 345 if (current_token_space == 0)
376 346 final_is_lesser_than_current = false;
377 347
@@ -385,17 +355,18 @@ public void run()// {{{
385 355 current_animation_player.getPlayer());
386 356 // current_animation_player = null;
387 357 current_animation_player.setIsMoving(false);
388   - move_player_thread = null;
  358 + animation_thread = null;
389 359 }
390 360
391 361 try {
392 362 Thread.sleep(ANIMATION_DELAY_MS);
393   - } catch (InterruptedException e) { /* do nothing */
  363 + } catch (InterruptedException e) { // do nothing
394 364 }
395 365 }
396   - }// }}}
  366 + }
397 367
398   - }//}}}
  368 + }
  369 + */
399 370
400 371 @Override
401 372 protected boolean handleMousePressed(MouseEvent e)
4 src/gui/GUIGame.java
@@ -87,7 +87,7 @@ private void createWindow() {
87 87 }
88 88
89 89 private void createBoard() {
90   - this.guiBoard = new GUIBoard(new Board(this.DEBUG));
  90 + this.guiBoard = new GUIBoard(new Board(this.DEBUG), this.game.getPlayers());
91 91
92 92 }
93 93
@@ -142,8 +142,8 @@ public void run() {
142 142 lastLoopTime = System.currentTimeMillis();
143 143
144 144 // do stuff...
145   - this.guiBoard.update(this.game.getBoard(), this.game.getPlayers());
146 145 String cmd = "";
  146 + System.out.println("Updategame");
147 147 this.game.updateGame(cmd);
148 148 //game.updateGame(cmd)
149 149
4 src/gui/GUISpace.java
@@ -397,6 +397,10 @@ public int getYCoor() {
397 397 return y_coor;
398 398 }
399 399
  400 + public int getPosition() {
  401 + return this.space.getPosition();
  402 + }
  403 +
400 404 public boolean isSelected()
401 405 {
402 406 return space.isSelected();

0 comments on commit e6fe2b5

Please sign in to comment.
Something went wrong with that request. Please try again.