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.

45 lines
1.2KB

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