|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.nipax.hippo.pexeso.Playground
public class Playground
Implementation of class - holds inner things about pexeso game state. Working with Playground and AI:
Playground
object
init(int, int)
setPGC(cz.nipax.hippo.pexeso.PlaygroundComponent)
AI
objects
add_AI(cz.nipax.hippo.pexeso.AI, cz.nipax.hippo.pexeso.AI)
start()
About the AI calls:
Playground
calls AI.onturn()
if the AI is supposed to turn. The AI
doesn't have to play right now. Then ai calls wantturn(cz.nipax.hippo.pexeso.AI, int, int)
.
When a card is revealed, Playground calls AI.revealed(int, int, int)
. AI has to
remember revealed cards if it wants to :-) [AI.revealed(int, int, int)
is called even if
the other player revealed card. Note that AI.onturn()
is called once and
it is expected that ai calls wantturn(cz.nipax.hippo.pexeso.AI, int, int)
twice, because
it can react on revealed card and alter the position of second card.
When two same cards are revealed and geting out of game, AI.ivalidate(int, int)
is called to AI.
If AI will no longer be used (new game started and AI are set to null),
AI.kill()
is called.
Note that if AI call wantturn(cz.nipax.hippo.pexeso.AI, int, int)
the Playground
may directly
call back AI.onturn()
withou any delay - so after succesfull wantturn(cz.nipax.hippo.pexeso.AI, int, int)
call you should be carefull what you are changing.
If you call setPGC(cz.nipax.hippo.pexeso.PlaygroundComponent)
, then PlaygroundComponent.repaint_later(boolean)
is
called after every change of game state.
Nested Class Summary | |
---|---|
(package private) class |
Playground.Piece
Info about one piece in game. |
(package private) class |
Playground.Player
Info about one player. |
Field Summary | |
---|---|
private int |
actual
Currently playing player - 0 or 1. |
(package private) static boolean |
DEBUG
The debug mode. |
(package private) boolean |
game_started
false after inicialization before start() called. |
private boolean |
m_beastmode
Random switching cards after turns. |
private int |
m_cards
Number of cards left in game. if == 0, the game ends. |
private Playground.Piece[][] |
m_field
the desk with playground |
(package private) PlaygroundComponent |
m_pgc
For notifying, that a refresh is needed. |
private int |
m_sleep_switch
How long to sleep after switching cards at end of turn in switch mode. |
private int |
m_sleep_turn
How long to sleep after end of turn. |
private boolean |
m_turnswitch
Switches two cards when visible. |
private int |
m_x
width of m_field |
private int |
m_y
height of m_field |
private Playground.Player[] |
player
Players in game - 2 |
Constructor Summary | |
---|---|
Playground()
Allocates objects for playground |
Method Summary | |
---|---|
void |
add_AI(AI a1,
AI a2)
Plugs AIs into game. |
protected void |
beastswitch()
Performs the beast action. |
java.lang.String |
getCPName()
Gets string ID if current player. |
int |
getID(int x,
int y)
Returns ID of card on position x,y. |
private Playground.Piece |
getRandpiece()
Get one valid Playground.Piece from m_field . |
int |
getScore(int playerID)
Gets score of player. |
int |
getWinner()
Gets ID of winner if game has ended. |
int |
getX()
Gets width of m_field |
int |
getY()
Gets height of m_field |
boolean |
checkDirty(int x,
int y)
Checks if piece need redrawing. |
void |
init(int x,
int y)
Inits new game on filed with dimensions x, y. |
boolean |
isEnd()
Checks for end of game. |
private void |
nextturn()
Ends current turn. |
void |
println(java.lang.String s)
Inteligent debug message printinge. |
void |
setBeastmode(boolean beastmode)
Change state of m_beastmode . |
void |
setPGC(PlaygroundComponent pgc)
Set m_pgc variable. |
void |
setSwitchturn(boolean tswitch)
Controls state of m_turnswitch . |
void |
start()
Starts game - check if AI are allready added. |
private void |
switchplayer(boolean swp)
Change current player. |
private void |
updateinvalidAI()
Checks all cards in game and call AI.ivalidate(int, int) for every invalid card. |
private void |
updaterevealedAI()
Checks all cards in game and call AI.revealed(int, int, int) for every visible card. |
boolean |
wantturn(AI ai,
int x,
int y)
This should be called by AI when it wants to make turn. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final boolean DEBUG
println(java.lang.String)
and enables showing
random switch in beast mode.
private Playground.Player[] player
private int actual
player
private boolean m_beastmode
setSwitchturn(boolean)
private boolean m_turnswitch
setSwitchturn(boolean)
private int m_sleep_turn
private int m_sleep_switch
private Playground.Piece[][] m_field
private int m_x
m_field
private int m_y
m_field
private int m_cards
boolean game_started
start()
called.
PlaygroundComponent m_pgc
null
so carefully.
Constructor Detail |
---|
public Playground()
Method Detail |
---|
public void println(java.lang.String s)
public void setPGC(PlaygroundComponent pgc)
public boolean checkDirty(int x, int y)
x
- coordinate of piece to checky
- coordinate of piece to check
public void init(int x, int y)
x
- width of fieldy
- height of the fieldpublic void add_AI(AI a1, AI a2)
a1
- AI of first player - has first turna2
- AI of second playerpublic void start()
game_started
to start game only once. Since
this method is public, some nasty AI may try to cheat by starting game
twice or something :-)
private void switchplayer(boolean swp)
swp
- really switch player or just give another turn to current playerpublic boolean wantturn(AI ai, int x, int y)
ai
- it should be "self" for the ai. This is needed to avoid AI cheating since AI doesn't
have AI
of opponent.x
- x-coordinate of movey
- y-coordinate of move
private void updaterevealedAI()
AI.revealed(int, int, int)
for every visible card.
private void updateinvalidAI()
AI.ivalidate(int, int)
for every invalid card.
private void nextturn()
m_turnswitch
and calls beastswitch()
.
public int getX()
m_field
public int getY()
m_field
public int getScore(int playerID)
playerID
- 0 for first player and 1 for second
public boolean isEnd()
public int getWinner()
public java.lang.String getCPName()
AI.getname()
and actual
public int getID(int x, int y)
public void setBeastmode(boolean beastmode)
m_beastmode
.
beastmode
- wanted modeprotected void beastswitch()
m_beastmode
is true
.
Takes two cards and switches them. Takes two valid pieces and switch the IDs.
It doesn't change dirty or revealed because all cards should be invisible now
and the dirty is relevant to position.
private Playground.Piece getRandpiece()
Playground.Piece
from m_field
. The piece is chosen
randomly.
public void setSwitchturn(boolean tswitch)
m_turnswitch
. Also alters m_sleep_switch
and m_sleep_turn
because of human memory :-).
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |