Skip to content

Commit

Permalink
Player names depend on skin
Browse files Browse the repository at this point in the history
  • Loading branch information
loony-bean committed Sep 12, 2011
1 parent 5a1a7b0 commit df3ac4e
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/com/example/kindle/boardgame/GameEvent.java
Expand Up @@ -4,6 +4,5 @@ public class GameEvent
{
public static final int CONTINUE = 0;
public static final int WIN = 1;
public static final int LOOSE = 2;
public static final int DRAW = 3;
}
7 changes: 0 additions & 7 deletions src/com/example/kindle/boardgame/IPlayer.java
Expand Up @@ -18,13 +18,6 @@ public interface IPlayer
*/
public Color getColor();

/**
* Returns name of the player.
*
* @return Player name.
*/
public String getName();

/**
* This method should be called when it is time for player
* to think on game and make it's move. Player is provided
Expand Down
Expand Up @@ -17,9 +17,9 @@ public class ComputerPlayer extends Player
public final static int MAXVAL = 100;
public final static int DEPTH = 6;

public ComputerPlayer(final Color color, final String name)
public ComputerPlayer(final Color color)
{
super(color, name);
super(color);

App.log("ComputerPlayer::create");

Expand Down
Expand Up @@ -265,9 +265,9 @@ public GameView getView()
return this.gameView;
}

public void setStatusText(final String status)
public void setStatus(int currentPlayerId, int status)
{
this.gameView.setStatusText(status);
this.gameView.setStatus(currentPlayerId, status);
}

public void repaint()
Expand Down
10 changes: 5 additions & 5 deletions src/com/example/kindle/winningfour/boardgame/GameState.java
Expand Up @@ -15,7 +15,7 @@ public class GameState extends State
public GameState(final GameController game, int player, final String name)
{
super(name);
this.player = player;
this.playerId = player;
this.game = game;

this.endGameKeyAdapter = new KeyAdapter()
Expand All @@ -39,7 +39,7 @@ public void enter()
this.game.getView().addKeyListener(this.keyAdapter);
}

this.game.setStatusText(this.status);
this.game.setStatus(this.playerId, this.status);
this.game.repaint();
}

Expand All @@ -53,7 +53,7 @@ public void leave()

public IPlayer getPlayer()
{
return this.game.getContext().getPlayers()[this.player];
return this.game.getContext().getPlayers()[this.playerId];
}

public void pulse(final SignalEvent signal)
Expand All @@ -74,10 +74,10 @@ public void destroy()
App.log("GameState::destroy done");
}

protected String status;
protected int status;
protected GameState state;
protected KeyAdapter keyAdapter;
protected KeyAdapter endGameKeyAdapter;
protected int player;
protected int playerId;
private GameController game;
}
@@ -1,10 +1,10 @@
package com.example.kindle.winningfour.boardgame;

import com.example.kindle.boardgame.GameEvent;
import com.example.kindle.sm.SignalEvent;
import com.example.kindle.sm.State;
import com.example.kindle.sm.StateMachine;
import com.example.kindle.winningfour.App;
import com.example.kindle.winningfour.AppResources;

public class GameStateMachine extends StateMachine
{
Expand Down Expand Up @@ -85,7 +85,7 @@ public TurnState(final GameController game, int player, final String name)

public void enter()
{
this.status = "" + this.getPlayer().getName() + App.bundle.getString(AppResources.KEY_GAME_TURN);
this.status = GameEvent.CONTINUE;
this.keyAdapter = this.getPlayer().getKeyAdapter();

super.enter();
Expand Down Expand Up @@ -130,7 +130,7 @@ public WinState(final GameController game, int player, final String name)

public void enter()
{
this.status = "" + this.getPlayer().getName() + App.bundle.getString(AppResources.KEY_GAME_WIN);
this.status = GameEvent.WIN;
super.enter();
App.gamer.stop();
}
Expand All @@ -157,7 +157,8 @@ private class DrawState extends GameState
public DrawState(final GameController game)
{
super(game, 0, "DrawState");
this.status = App.bundle.getString(AppResources.KEY_GAME_DRAW);
//this.status = App.bundle.getString(AppResources.KEY_GAME_DRAW);
this.status = GameEvent.DRAW;
this.keyAdapter = this.endGameKeyAdapter;
}

Expand Down
32 changes: 30 additions & 2 deletions src/com/example/kindle/winningfour/boardgame/GameView.java
Expand Up @@ -9,11 +9,13 @@
import org.kwt.ui.KWTProgressBar;

import com.amazon.kindle.kindlet.ui.KLabel;
import com.example.kindle.boardgame.GameEvent;
import com.example.kindle.utils.GameClock;
import com.example.kindle.winningfour.App;
import com.example.kindle.winningfour.AppResources;
import com.example.kindle.winningfour.boardgame.BoardItem;
import com.example.kindle.winningfour.gui.GameImage;
import com.example.kindle.winningfour.options.OptionsFactory;
import com.example.kindle.winningfour.skins.BoardLayout;

public class GameView extends Container
Expand Down Expand Up @@ -90,6 +92,8 @@ public void paint(Graphics g)
this.selectedRow*(this.layout.pieceSizeX + this.layout.pieceGapX),
this.layout.selectorY);

this.statusLabel.setText(this.getStatusString());

super.paint(g);
AppResources.getSkin().paintBoard(g, this);
this.paintItems(this.items, g);
Expand Down Expand Up @@ -125,9 +129,30 @@ public void setSelectedRow(int row)
this.gameSelector.repaint();
}

public void setStatusText(final String text)
public void setStatus(final int currentPlayerId, int status)
{
this.statusLabel.setText(text);
this.status = status;
this.currentPlayerId = currentPlayerId;
this.statusLabel.repaint();
}

private String getStatusString()
{
String result = "";
String actor = (new OptionsFactory()).createSkin().getPlayerNames()[this.currentPlayerId];
if (this.status == GameEvent.WIN)
{
result = actor + App.bundle.getString(AppResources.KEY_GAME_WIN);
}
else if (this.status == GameEvent.DRAW)
{
result = App.bundle.getString(AppResources.KEY_GAME_DRAW);
}
else if (this.status == GameEvent.CONTINUE)
{
result = actor + App.bundle.getString(AppResources.KEY_GAME_TURN);
}
return result;
}

public void setProgressTicks(int percents)
Expand Down Expand Up @@ -167,6 +192,9 @@ public void destroy()
private ArrayList items;
private int selectedRow;
private KWTProgressBar progressBar;

private int status;
private int currentPlayerId;

private BoardLayout layout;
}
4 changes: 2 additions & 2 deletions src/com/example/kindle/winningfour/boardgame/HumanPlayer.java
Expand Up @@ -11,9 +11,9 @@

public class HumanPlayer extends Player
{
public HumanPlayer(final Color color, final String name)
public HumanPlayer(final Color color)
{
super(color, name);
super(color);
}

protected void onKeyboard(final KeyEvent event)
Expand Down
11 changes: 2 additions & 9 deletions src/com/example/kindle/winningfour/boardgame/Player.java
Expand Up @@ -10,10 +10,9 @@

public class Player implements IPlayer
{
public Player(final Color color, final String name)
public Player(final Color color)
{
this.color = color;
this.name = name;

this.keyAdapter = new KeyAdapter()
{
Expand All @@ -29,11 +28,6 @@ public Color getColor()
return this.color;
}

public String getName()
{
return this.name;
}

public KeyAdapter getKeyAdapter()
{
return this.keyAdapter;
Expand Down Expand Up @@ -61,7 +55,7 @@ public boolean equals(Object other)
{
IPlayer lhs = (IPlayer) this;
IPlayer rhs = (IPlayer) other;
return rhs.getName().equals(lhs.getName());
return rhs.getColor().equals(lhs.getColor());
}

return false;
Expand All @@ -78,5 +72,4 @@ public void destroy()

private KeyAdapter keyAdapter;
private final Color color;
private final String name;
}
Expand Up @@ -61,18 +61,16 @@ public IPlayer[] createPlayers()
String firstTurn = (String) App.opts.get(AppOptions.OP_T_FIRST_TURN);
String opponent = (String) App.opts.get(AppOptions.OP_T_OPPONENT);

String[] playerNames = this.createSkin().getPlayerNames();

IPlayer you = new HumanPlayer(Color.white, playerNames[0]);
IPlayer you = new HumanPlayer(Color.white);
IPlayer opp = null;

if (opponent.equals(AppOptions.OP_V_COMPUTER))
{
opp = new ComputerPlayer(Color.black, playerNames[1]);
opp = new ComputerPlayer(Color.black);
}
else if (opponent.equals(AppOptions.OP_V_HUMAN))
{
opp = new HumanPlayer(Color.black, playerNames[1]);
opp = new HumanPlayer(Color.black);
}

if (firstTurn.equals(AppOptions.OP_V_YOU))
Expand Down

0 comments on commit df3ac4e

Please sign in to comment.