@Override
    protected void onPostExecute(Integer result) {
      if (list == null) {
        return;
      } else if (result == -1) {

        System.out.print("result = " + result);
        // 从服务器获取关注列表
        list.clear();
        FocusModel f = new FocusModel();
        f.setuName("哈哈哈");
        f.setuFlag(true);
        f.setuPic(R.drawable.user_pic1);
        list.add(f);
        f = new FocusModel();
        f.setuName("呵呵");
        f.setuFlag(true);
        f.setuPic(R.drawable.user_pic2);
        list.add(f);
        f = new FocusModel();
        f.setuName("拉拉");
        f.setuFlag(true);
        f.setuPic(R.drawable.user_pic3);
        list.add(f);
      } else {

        System.out.print("result1 = " + result);
        list.remove(list.get(result));
      }
      System.out.println("list.size() =" + list.size());
      adapter.notifyDataSetChanged();
    }
 @Override
 protected Integer doInBackground(Integer... params) {
   // TODO Auto-generated method stub
   if (params[0] == -1) {
     // 获取关注列表
     System.out.println("get focus");
   } else {
     // 从关注列表删除
     FocusModel f = list.get(params[0]);
     System.out.println("delete from focus " + f.getuName());
   }
   return params[0];
 }
Example #3
0
 /**
  * Draws the state of the model, including instructions.
  *
  * @param source If non-null, drawing highlights all legal moves from source.
  */
 public void draw(String instructions, Location source) {
   StdDraw.clear();
   for (int r = 0; r < FocusModel.BOARD_WIDTH; r++) {
     for (int c = 0; c < FocusModel.BOARD_WIDTH; c++) {
       Location destination = new Location(r, c);
       drawSquare(
           model.getPile(destination),
           1.5 + c,
           9.5 - r,
           source != null && model.isLegalMove(source, destination));
     }
   }
   StdDraw.setPenColor(LIGHT_BLUE);
   StdDraw.filledRectangle(2, 0.5, 2, 0.45);
   StdDraw.filledRectangle(8, 0.5, 2, 0.45);
   StdDraw.setPenColor();
   StdDraw.text(2, 0.5, "Black reserves: " + model.getReserves(FocusModel.BLACK));
   StdDraw.text(8, 0.5, "White reserves: " + model.getReserves(FocusModel.WHITE));
   StdDraw.text(5, 1.5, instructions);
   StdDraw.show(0);
 }
Example #4
0
 /** Plays the game. */
 public void run() {
   StdDraw.setXscale(0, 10);
   StdDraw.setYscale(0, 10);
   StdDraw.text(5.0, 8.0, "Focus");
   StdDraw.text(5.0, 6.0, "Get your pieces on top of the piles.");
   StdDraw.text(5.0, 4.0, "The first player unable to move loses.");
   StdDraw.text(5.0, 2.0, "Click to continue.");
   StdDraw.show(0);
   waitForClick();
   while (!model.isGameOver()) {
     draw(getCurrentPlayerName() + ", click on one of your piles or your reserves.", null);
     Location source;
     do {
       source = waitForClick();
     } while (source == null || !model.isLegalSource(source));
     draw(getCurrentPlayerName() + ", click on destination square.", source);
     Location destination;
     do {
       destination = waitForClick();
     } while (destination == null || !model.isLegalMove(source, destination));
     model.move(source, destination);
     model.toggleColorToPlay();
   }
   model.toggleColorToPlay();
   draw(getCurrentPlayerName() + " wins.", null);
 }
Example #5
0
 /**
  * Waits for the user to click and returns the location where they clicked (which might be one of
  * Game.RESERVES_LOCATIONS). For invalid locations, may return null.
  */
 public Location waitForClick() {
   while (!StdDraw.mousePressed()) {
     // Wait for mouse press
   }
   double x = StdDraw.mouseX();
   double y = StdDraw.mouseY();
   while (StdDraw.mousePressed()) {
     // Wait for mouse release
   }
   // This catches some clicks on the background as if they were on one of
   // the reserve buttons, but handles valid clicks correctly
   if (y <= 2.0) {
     if (x < 5) {
       return FocusModel.RESERVES_LOCATIONS[FocusModel.BLACK];
     }
     return FocusModel.RESERVES_LOCATIONS[FocusModel.WHITE];
   }
   Location result = new Location((int) (10.0 - y), (int) (x - 1.0));
   if (model.isOnBoard(result)) {
     return result;
   }
   return null;
 }
Example #6
0
 /** Returns "Black" or "White" as appropriate. */
 public String getCurrentPlayerName() {
   return model.getCurrentPlayer() == FocusModel.BLACK ? "Black" : "White";
 }