@Test
  public void testSubmitAllCorrectAnswers() {
    Player playerWith5Friends = TestUtils.getPlayer(1005);

    // Take note of the player's points before they submit the correct
    // answers
    long playerPointsOriginal = playerWith5Friends.getPoints();

    // Submit 3 correct answers to our WebService as a POST request
    String targetURL =
        "http://localhost:8080/FBTutorialDemo/rest/webService/GameAnswers/"
            + "1005/67890/76543/89012";
    String JSONInput =
        "[\"" + "One Friend" + "\",\"" + "Two Friend" + "\",\"" + "Three Friend" + "\"]";
    String response = TestUtils.doPOST(targetURL, JSONInput);

    // Test that we get the correct String back from the incorrect answers
    // and our points were deducted
    String expectedResponse =
        "First entry was correct "
            + "Second entry was correct "
            + "Thrid entry was correct "
            + "You will have a total of ["
            + 30
            + "] points added!";

    // Re-GET the player now that the score should be updated
    playerWith5Friends = TestUtils.getPlayer(1005);
    Assert.assertTrue(response.equals(expectedResponse));
    Assert.assertTrue(playerWith5Friends.getPoints() == (playerPointsOriginal + 30));
  }
  @Test
  public void testSubmitAllBlankAnswers() {
    String appName = "FBTutorialDemo";
    Player playerWith5Friends = TestUtils.getPlayer(1005);

    // Take note of the player's points before they submit the blank answers
    long playerPointsOriginal = playerWith5Friends.getPoints();

    // Submit 3 blank answers to our WebService as a POST request
    String targetURL =
        "http://localhost:8080/FBTutorialDemo/rest/webService/GameAnswers/"
            + "1005/67890/76543/89012";
    String JSONInput = "[\"" + "\",\"" + "\",\"" + "\"]";
    String response = TestUtils.doPOST(targetURL, JSONInput);

    // Test that we get the correct String back from the blank answers and
    // our points were deducted
    String expectedResponse =
        "First entry was INCORRECT "
            + "Second entry was INCORRECT "
            + "Third entry was INCORRECT "
            + "You will have a total of ["
            + 30
            + "] points deducted.";

    System.out.println("\n\n\n\n\n\n response: " + response);
    System.out.println("\n\n\n\n\n\n");

    // Re-GET the player now that the score should be updated
    playerWith5Friends = TestUtils.getPlayer(1005);
    Assert.assertTrue(response.equals(expectedResponse));
    Assert.assertTrue(playerWith5Friends.getPoints() == (playerPointsOriginal - 30));
  }
Beispiel #3
0
  @Test
  public void restart_both_scores_and_advantages_when_a_setpoint_is_scored() {
    add(3).pointsTo(playerA);
    add(3).pointsTo(playerB);
    add(2).pointsTo(playerA);

    int ZERO = 0;
    assertThat(playerA.getPoints(), is(ZERO));
    assertThat(playerA.getAdvantages(), is(ZERO));
    assertThat(playerB.getPoints(), is(ZERO));
    assertThat(playerB.getAdvantages(), is(ZERO));
  }
  @Override
  public void paint(Graphics g) {
    super.paint(g);

    for (int i = 0; i < p.getKeys(); i++) {
      g.drawImage(keyIcon.getImage(), (i * 32) + 5, (int) (m.MAZE_SIZE + .2) * 32, null);
    }

    g.drawString("Score: " + p.getPoints(), 5, (int) ((m.MAZE_SIZE + 1.5) * 32));
    for (int i = 0; i < m.MAZE_SIZE; i++) {
      for (int j = 0; j < m.MAZE_SIZE; j++) {
        if (m.getMapTileType(j, i).equals(MazeRoomLogic.MazeEnums.RoomType.PATH)) {
          g.drawImage(m.getRoomImage(), j * 32, i * 32, null);
        }

        if (m.getMapTileType(j, i).equals(MazeRoomLogic.MazeEnums.RoomType.WALL)) {
          g.drawImage(m.getWallImage(), j * 32, i * 32, null);
        }

        if (m.getMapTileType(j, i).equals(MazeRoomLogic.MazeEnums.RoomType.DOOR)) {
          g.drawImage(m.getDoorImage(), j * 32, i * 32, null);
        }

        if (m.getMapTileType(j, i).equals(MazeRoomLogic.MazeEnums.RoomType.EXIT)) {
          g.drawImage(m.getExitImage(), j * 32, i * 32, null);
        }

        if (m.getMapTileType(j, i).equals(MazeRoomLogic.MazeEnums.RoomType.START)) {
          g.drawImage(m.getStartImage(), j * 32, i * 32, null);
        }
      }
    }

    g.drawImage(p.getPlayerImage(), p.getTileX() * 32, p.getTileY() * 32, null);
  }
Beispiel #5
0
 @Override
 public void update(Observable o, Object arg) {
   if (arg instanceof Player) {
     Player player = (Player) arg;
     int points = player.getPoints();
     System.out.println("Spieler" + player.getNum() + "an der Reihe");
     if (player.getNum() == 1) {
       System.out.println("Spieler1 punkte++");
       points1Num.setText("" + points);
     } else if (player.getNum() == 2) {
       System.out.println("Spieler2 punkte++");
       points2Num.setText("" + points);
     }
   } else {
     GameController controller = (GameController) arg;
     if (controller.getPlayer().getNum() == 1) {
       ImageIcon image = new ImageIcon("../gfx/spieler1_play.png");
       l1.setIcon(image);
       ImageIcon imageOld = new ImageIcon("../gfx/spieler2.png");
       l2.setIcon(imageOld);
       System.out.println("spieler gewechselt");
     } else {
       ImageIcon imageI = new ImageIcon("../gfx/spieler2_play.png");
       l2.setIcon(imageI);
       ImageIcon imageOldI = new ImageIcon("../gfx/spieler1.png");
       l1.setIcon(imageOldI);
     }
   }
 }
  @Test
  public void testGameLinkForValidNumOfFriends() {
    Player playerWith5Friends = TestUtils.getPlayer(1005);

    // Test that the Player has 5 friends and has the correct link.
    String expectedHrefBeginning =
        "playGame.html?playerID="
            + playerWith5Friends.getPlayerInfo().getFacebookID()
            + "&playerName="
            + playerWith5Friends.getPlayerInfo().getName()
            + "&playerPoints="
            + playerWith5Friends.getPoints()
            + "&friendIDList=";
    Assert.assertTrue(playerWith5Friends.getFriendList().size() == 5);
    Assert.assertTrue(playerWith5Friends.getGameLink().getOnClickMethod().equals(""));
    Assert.assertTrue(playerWith5Friends.getGameLink().getHref().startsWith(expectedHrefBeginning));

    // Since the friendIDList and friendNameList passed in the GameLink.Href
    // are random,
    // we can't validate them in any simple manner. However, we can verify
    // that our
    // requirements are still in working order. We need to make sure that
    // the names
    // that go with all 3 friendIDList entries are among the 5
    // friendNameList entries
    Assert.assertTrue(isValidGameLinkLists(expectedHrefBeginning, playerWith5Friends));

    Player playerWith10Friends = TestUtils.getPlayer(1010);
    expectedHrefBeginning =
        "playGame.html?playerID="
            + playerWith10Friends.getPlayerInfo().getFacebookID()
            + "&playerName="
            + playerWith10Friends.getPlayerInfo().getName()
            + "&playerPoints="
            + playerWith10Friends.getPoints()
            + "&friendIDList=";

    // Test that the Player with 10 friends also has a correct link.
    Assert.assertTrue(playerWith10Friends.getFriendList().size() == 10);
    Assert.assertTrue(playerWith10Friends.getGameLink().getOnClickMethod().equals(""));
    Assert.assertTrue(
        playerWith10Friends.getGameLink().getHref().startsWith(expectedHrefBeginning));
    Assert.assertTrue(isValidGameLinkLists(expectedHrefBeginning, playerWith10Friends));
  }
Beispiel #7
0
 /** Test of getPoints method, of class Player. */
 @Test
 public void testGetPoints() {
   System.out.println("getPoints");
   Player instance = null;
   int expResult = 0;
   int result = instance.getPoints();
   assertEquals(expResult, result);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
 @Test
 public void testPlayer() {
     try {
         new Player(null, 345, 2345);
         fail();
     } catch (IllegalArgumentException e) {
         assertEquals("illegal userName", e.getMessage());
     }
     try {
         new Player("", 345, 2345);
         fail();
     } catch (IllegalArgumentException e) {
         assertEquals("illegal userName", e.getMessage());
     }
     try {
         new Player("Namegültig", -3, 2345);
         fail();
     } catch (IllegalArgumentException e) {
         assertEquals("illegal villageCount", e.getMessage());
     }
     try {
         new Player("Namegültig", 0, 2345);
         fail();
     } catch (IllegalArgumentException e) {
         assertEquals("illegal villageCount", e.getMessage());
     }
     try {
         new Player("Namegültig", 435, -2);
         fail();
     } catch (IllegalArgumentException e) {
         assertEquals("illegal points", e.getMessage());
     }
     Player p1 = new Player("Namegültig", 435, 0);
     assertEquals(p1.getPoints(), 0);
     assertEquals(p1.getUserName(), "Namegültig");
     assertEquals(p1.getVillageCount(), 435);
     
     Player p2 = new Player("Namegültig", 435, 243536);
     assertEquals(p2.getPoints(), 243536);
 }
  @Override
  public View getView(final int pos, final View convertView, final ViewGroup parent) {
    final _ViewHolder holder;
    final Player p;
    View v = convertView;

    if (v == null) {
      final LayoutInflater vi =
          (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      v = vi.inflate(R.layout.standings_row, parent, false);

      holder = new _ViewHolder();
      holder.row = (LinearLayout) v.findViewById(R.id.player_row);
      holder.rank = (TextView) v.findViewById(R.id.player_rank);
      holder.name = (TextView) v.findViewById(R.id.player_name);
      holder.points = (TextView) v.findViewById(R.id.player_points);
      holder.races = (TextView) v.findViewById(R.id.player_races);
      holder.wins = (TextView) v.findViewById(R.id.player_wins);
      v.setTag(holder);
    } else {
      holder = (_ViewHolder) v.getTag();
    }

    p = getItem(pos);

    if (isSelf(p)) holder.name.setBackgroundResource(R.drawable.standings_self);
    else
      holder.name.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));

    if (p.isInChase()) holder.row.setBackgroundResource(R.drawable.standings_chase);
    else holder.row.setBackgroundResource(R.drawable.standings_other);

    holder.rank.setText(p.getRank());
    holder.points.setText(p.getPoints());

    if (p.getName() != null) holder.name.setText(p.getName());
    else holder.name.setText(mContext.getString(R.string.private_name));

    final int star = p.isFriend() ? R.drawable.friend_star : 0;
    holder.name.setCompoundDrawablesWithIntrinsicBounds(star, 0, 0, 0);
    holder.name.setCompoundDrawablePadding(5);

    if (holder.races != null) holder.races.setText(p.getRaces());

    if (holder.wins != null) holder.wins.setText(p.getWins());

    return v;
  }
 public void exit() {
   points = happiness * happiness;
   p.getPoints(points);
   // remove customer
 }