Class Game

java.lang.Object
  extended by Game

public class Game
extends java.lang.Object

This Game class represents all the server side game functionalites of this 304 cards game. When every new game is created, a class instent object of this class will be crated in server. Basically all the server side game functionalites are handled by this game class.


Field Summary
private  int bestbet
           
private  int bestbetby
           
(package private)  boolean[] betfinished
           
(package private)  int[] bets
           
private  java.util.ArrayList<Card>[] cards4player
           
private  int gameId
           
private  int lastRoundWinner
           
private  int noOfRounds
           
private  int[] playerPoints
           
private  int roundStartsWith
           
private  Cards304Server srv
           
private  Card[] table
           
private  int thisTurnPlayer
           
private  Card trump
           
private  boolean trumpOpen
           
private  int[] wins
           
 
Constructor Summary
Game(Cards304Server srv, int gameId)
          Constructor of this class, get the server object and gameId.
 
Method Summary
private  void checkBestBet()
          this methos is to check the best bet and to sent a message to the clients.
static java.util.ArrayList<Card> deal(java.util.List<Card> deck, int n)
          This method is to divide the shuffeled cards into 4 players.
private  int enemyOf(int player)
          This method is to find an openent of a player.
 void finalize()
          This method finializes the game functionalities.
private  void finishPlay()
          This method is to finish the current player and set the winner.
private  boolean isRoundFinished()
          This method is to check whether a round finished or not.
private  void newPlay()
          This method restores the default values to all those variables in this class and starts a new play
private  int partnerOf(int player)
          This method is to find the partner of a player.
private  void resetTable()
          This method is to reset the Table array and this method check whether 8 rounds finished or not, if 8 rounds finished, finishes the game and sets the winning results.
 void selectTurn()
          This method is to select a turn according to the game logics.
 void setBet(int playerId, int bet)
          This method is to set a bet to its player and this function will be called from the server.
private  void setPoints()
          This method is to sent the point to playerPoints array.
 void setSelectedCard(int playerId, java.lang.String card)
          This method is to set the selected card in client to a table card array.
 void setTrump(java.lang.String trump)
          This method sets the trump card and this method will be called from server.
 void shuffleAndServe()
          This method is to get a new deack of cards from cards class and suffle it and then to server it to the clients.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gameId

private int gameId

bestbet

private int bestbet

bestbetby

private int bestbetby

lastRoundWinner

private int lastRoundWinner

thisTurnPlayer

private int thisTurnPlayer

roundStartsWith

private int roundStartsWith

noOfRounds

private int noOfRounds

wins

private int[] wins

playerPoints

private int[] playerPoints

trump

private Card trump

srv

private Cards304Server srv

cards4player

private java.util.ArrayList<Card>[] cards4player

table

private Card[] table

trumpOpen

private boolean trumpOpen

bets

int[] bets

betfinished

boolean[] betfinished
Constructor Detail

Game

public Game(Cards304Server srv,
            int gameId)
Constructor of this class, get the server object and gameId.

Parameters:
srv - Cards304Server class object to access server and send messages to the clients.
gameId - int index no of a game.
Method Detail

shuffleAndServe

public void shuffleAndServe()
This method is to get a new deack of cards from cards class and suffle it and then to server it to the clients.


deal

public static java.util.ArrayList<Card> deal(java.util.List<Card> deck,
                                             int n)
This method is to divide the shuffeled cards into 4 players.


setBet

public void setBet(int playerId,
                   int bet)
This method is to set a bet to its player and this function will be called from the server.

Parameters:
playerId - int index numer of a player or id of a player
bet - int the amount of a bet.

checkBestBet

private void checkBestBet()
this methos is to check the best bet and to sent a message to the clients.


setTrump

public void setTrump(java.lang.String trump)
This method sets the trump card and this method will be called from server. param trump String trump card name.


setSelectedCard

public void setSelectedCard(int playerId,
                            java.lang.String card)
This method is to set the selected card in client to a table card array.

Parameters:
playerId - int this player's index number.
card - String name of a gard.

isRoundFinished

private boolean isRoundFinished()
This method is to check whether a round finished or not.


setPoints

private void setPoints()
This method is to sent the point to playerPoints array.


selectTurn

public void selectTurn()
This method is to select a turn according to the game logics.


resetTable

private void resetTable()
This method is to reset the Table array and this method check whether 8 rounds finished or not, if 8 rounds finished, finishes the game and sets the winning results.


finishPlay

private void finishPlay()
This method is to finish the current player and set the winner. Then it sents the message to the client.


newPlay

private void newPlay()
This method restores the default values to all those variables in this class and starts a new play


partnerOf

private int partnerOf(int player)
This method is to find the partner of a player.

Parameters:
player - int player id.
Returns:
int partner player's id.

enemyOf

private int enemyOf(int player)
This method is to find an openent of a player. Even though there are two openents, this method will return you the next oponent's player id.

Parameters:
player - int player id.
Returns:
int oponent player's id.

finalize

public void finalize()
This method finializes the game functionalities.

Overrides:
finalize in class java.lang.Object