You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5KB

  1. package de.hems.trafficsim;
  2. import androidx.appcompat.app.AppCompatActivity;
  3. import androidx.constraintlayout.widget.ConstraintLayout;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.TextView;
  7. import java.util.Observable;
  8. import java.util.Observer;
  9. public class MainActivity extends AppCompatActivity implements Observer {
  10. protected Track track;
  11. protected TrackView trackView;
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_main);
  16. this.track = new Track(20, 50);
  17. this.trackView = new TrackView(this, this.track);
  18. this.track.addObserver(this);
  19. ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.constr_layout);
  20. layout.addView(this.trackView);
  21. }
  22. @Override
  23. public void update(Observable observable, Object o) {
  24. String s = "";
  25. for (Vehicle v: this.track.getVehicles()){
  26. s+= "Vehicle " + v.id + " | "
  27. + "Pos = " + v.getPosition() + " | "
  28. + "Vel = " + v.getCurVelocity()+ " | "
  29. + "\n";
  30. ;
  31. }
  32. TextView view = (TextView) findViewById(R.id.debugTextView);
  33. view.setText(s);
  34. view.invalidate();
  35. this.trackView.invalidate();
  36. }
  37. public void onStepButtonClick (View view) {
  38. //for (int j = 0; j < 3000; j++) {
  39. this.track.timeElapse(50);
  40. //}
  41. }
  42. }