Package test.gamerunner

Source Code of test.gamerunner.CardGameReconnectProcTest$MyUI

package test.gamerunner;
import junit.framework.*;
import net.sf.nebulacards.comm.*;
import net.sf.nebulacards.game.*;
import net.sf.nebulacards.gamerunner.*;
import net.sf.nebulacards.main.*;
import net.sf.nebulacards.util.*;
import OneProcGame;

/**
* Test that players receive the correct information when reconnecting to a
* card game.
* @author James Ranson
*/
public class CardGameReconnectProcTest extends TestCase
{
  class MyUI extends UIAdapter
  {
    PileOfCards hand;
    public Player[] players;
    public int hcount = 0, pcount = 0;
    public void dealHand(PileOfCards p) { hand = p; hcount++; }
    public void setPlayers(Player[] p) { players = p; pcount++; }
  }

  // member variables
  final int NUMPLAYERS = 2;
  MyUI[] clients = new MyUI[NUMPLAYERS];
  OneProcGame opg;
 
  public CardGameReconnectProcTest(String s) { super(s); }


  public void setUp()
  {
    opg = new OneProcGame("CardGameReconnectProcTest", NUMPLAYERS);
    // add the players to the game
    for (int i = 0; i < NUMPLAYERS; i++)
    {
      ComManager.AddResult cmar = opg.add(clients[i] = new MyUI());
      cmar.publicize();
      opg.getPlayers()[cmar.getPosition()].setName("Player " + i);
    }
    // give each player a card
    for (int i = 0; i < NUMPLAYERS; i++)
      opg.getHands()[i].add(new PlayingCard(i, i));
  }

  /**
   * Reset all the clients.
   */
  public void reset()
  {
    for (int i = 0; i < clients.length; i++)
    {
      clients[i].hand = null;
      clients[i].players = null;
      clients[i].hcount = clients[i].pcount = 0;
    }
  }

  /**
   * Test the reconnect() method.
   */
  public void testReconnect()
  {
    reset();
    CardGameReconnectProc cgrp = new CardGameReconnectProc(opg);
    cgrp.reconnect(0, opg.getCom(0));
    assertEquals(clients[0].hcount, 1);
    assertEquals(clients[0].pcount, 1);
    // check that he received the player info.
    assertEquals(clients[0].players[0].getName(),
            opg.getPlayers()[0].getName());
    // check that he received his own hand.
    assertEquals(clients[0].hand,
            opg.getHands()[clients[0].getPosition()]);
 
}
TOP

Related Classes of test.gamerunner.CardGameReconnectProcTest$MyUI

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.