示例#1
0
  public void updateMainContent(Card cc) {
    TextView cash = (TextView) findViewById(R.id.menu_text);
    if (game.getAddedCash() > 0)
      cash.setText("Cash: $" + game.getCash() + "  (+$" + game.getAddedCash() + ")");
    else if (game.getAddedCash() < 0)
      cash.setText("Cash: $" + game.getCash() + "  ($" + game.getAddedCash() + ")");
    else cash.setText("Cash: $" + game.getCash());

    LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout3);
    new Color();
    ll.setBackgroundColor(
        Color.rgb(
            game.getCurrentCard().getColor()[0],
            game.getCurrentCard().getColor()[1],
            game.getCurrentCard().getColor()[2]));

    TextView h1 = (TextView) findViewById(R.id.textView1);
    h1.setText(cc.getStreet().toUpperCase());

    TextView h2 = (TextView) findViewById(R.id.textView2);
    h2.setText(cc.getArea());

    TextView own = (TextView) findViewById(R.id.textView3);
    own.setText("" + cc.getOwner());

    TextView val = (TextView) findViewById(R.id.textView4);
    val.setText("$" + Integer.toString(cc.getValue()));

    TextView tax = (TextView) findViewById(R.id.textView5);
    tax.setText("$" + Integer.toString(cc.getTax()));

    TextView hou = (TextView) findViewById(R.id.textView6);
    String pri = new String();
    if (cc.getHousePrise() <= 0) pri = " --";
    else pri = Integer.toString(cc.getHousePrise());
    hou.setText("$" + pri);

    // The buttons
    buyStreet.setEnabled(
        game.getCash() >= game.getCurrentCard().getValue()
            && game.getCurrentCard().getStreet() != GameMechanics.DEFAULT_STREET
            && game.getPlayer().getUserId() != game.getCurrentCard().getOwnerId());

    buyHouse.setEnabled(
        game.getCash() >= game.getCurrentCard().getHousePrise()
            && game.getCurrentCard().getHouses() < 5
            && game.getCurrentCard().getStreet() != GameMechanics.DEFAULT_STREET
            && game.getPlayer().getUserId() == game.getCurrentCard().getOwnerId());

    // Do the houses
    for (int i = 1; i <= 5; i++) {
      ImageView houses = new ImageView(this);
      houses = (ImageView) findViewById(ivid[i]);
      if (cc.getHouses() >= i) houses.setImageResource(hoid[i]);
      else houses.setImageResource(hoid[0]);
      houses.invalidate();
    }

    return;
  }
示例#2
0
  @Override
  public void onLocationChanged(Location location) {
    Log.v(TAG, "Location Changed");
    nofixes++;
    StringBuilder sb = new StringBuilder();

    // Get some cash on each fix and make sound
    game.foundCash();
    mp.get(0).start();
    // vib.vibrate(100);
    try {
      sb.append(
          game.getPlayer().getUserId()
              + ", "
              + game.getPlayer().getUser()
              + ", "
              + game.getPlayer().getEmail()
              + "\n");
      sb.append(nofixes + ", ");

      // Decode point address
      List<Address> listan = new LinkedList<Address>();
      Geocoder adam = new Geocoder(this.getBaseContext());
      listan.addAll(adam.getFromLocation(location.getLatitude(), location.getLongitude(), 9));
      Log.v(TAG, Integer.toString(nofixes));

      sb.append(location.getProvider());

      // Conversion to UTM
      CoordinateConversion bertil = new CoordinateConversion();
      String cesar = bertil.latLon2UTM(location.getLatitude(), location.getLongitude());
      String[] david = cesar.split(" ");

      // if new square - update!
      String newid =
          david[0]
              + Character.getNumericValue(david[1].toCharArray()[0])
              + david[2].substring(0, 3)
              + david[3].substring(0, 4);

      if (!newid.matches(game.getCurrentCard().getId()) && game.getPlayer().getUserId() != 0) {
        Log.v(TAG, "NEW AREA!!!");

        if (!dbc.existsCard(newid)) {
          Log.v(TAG, "NEW CARD! (Insert card)");

          game.setCurrentCard(new Card(cesar, "", "", 0, GameMechanics.DEFAULT_OWNER, 0, 0));
          game.getCurrentCard().setLocationData(this.getBaseContext(), cesar);

          dbc.insertCard(game.getCurrentCard());
        } else {
          Log.v(TAG, "CARD EXISTS! (Load card)");
          Card lc = dbc.loadCard(newid); // Load the new card from db
          if (lc != null) {
            Log.d(TAG, Integer.toString(lc.getOwnerId()));
            game.setCurrentCard(lc);
            game.getCurrentCard().setOwner(dbc.loadUserName(lc.getOwnerId()));
            game.getCurrentCard().setLocationData(this.getBaseContext(), cesar);
          }
          // potential owner / disable button issue? or will it be fixed in the update views?....
          // yes probably
          // pay taxes!
          if (game.getPlayer().getUserId() != lc.getOwnerId() && lc.getOwnerId() != 0)
            dbc.insertTransfer(
                game.getPlayer().getUserId(),
                lc.getOwnerId(),
                lc.getId(),
                lc.getTax(),
                0); // 0 = tax
        }
        syncAllCash(true);
        // make a new sound
        mp.get(2).start();
      } else {
        Log.v(TAG, "SAME OLD AREA!");
        game.getCurrentCard().setLocationData(this.getBaseContext(), cesar);

        syncAllCash(false);
      }

      // Update current card and funds
      updateMainContent(game.getCurrentCard());

      sb.append(cesar + ", ");
      sb.append(game.getCurrentCard().getId() + "\n");
      sb.append("\n");
      sb.append(location.getProvider() + ", ");
      sb.append(location.getAccuracy() + "\n");

      /*for(int i = 0; i < listan.size(); i++){
      	sb.append(listan.get(i).getThoroughfare() + ", " + listan.get(i).getLocality() + "\n");
      }*/

      // Debug text
      if (DEBUG) tw.setText(sb.toString());

    } catch (Exception e) {
      e.printStackTrace();
    }

    if (game.getAddedCash() > 100) mp.get(3).start();
  }