Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. import static jsTools.Graph.*;
  2. import static jsTools.Input.*;
  3.  
  4. public class Zug {
  5.  
  6. /** Diese Klasse erzeugt den "Kopf" des Zuges */
  7. public static class Lok {
  8.  
  9. int b;
  10. int h;
  11. int d;
  12. int posx;
  13. int posy;
  14. String col;
  15.  
  16. Wagon wagen;
  17.  
  18. /** Dies ist der Konstruktor */
  19. Lok (){
  20. b=100;
  21. h=40;
  22. d=(h/3)*2;
  23. posx=50;
  24. posy=100;
  25. col="black";
  26. }
  27.  
  28. /** Diese Methode hängt einen übergebenen Wagen ans Ende des Zuges */
  29. void appWagon(Wagon w) {
  30.  
  31. }
  32.  
  33. /**
  34. * Diese Methode zeichnet die Lok an die Position gemäß der Attribute posx und posy.
  35. * Danach ruft sie die Zeichenmethode des angehängten Wagens auf. Die Position des Wagens
  36. * berechnet sich aus der Position der Lok (posx,posy) + dem Versatz durch die Länge der
  37. * Lok (posx + laengeLok.posy). Damit wird dann der ganze Zug gezeichnet.
  38. * */
  39. void paint() {
  40. addRect(posx, posy, b, h, col); //BASE
  41. addRect(posx + b - (b/5)*2, posy-(h/3), (b/5)*2, (h/3), col); //OBEN
  42. addRect(posx + b - (b/20)*9, posy - 2*(h/3), (b/20)*10, (h/3), col); //DACH
  43. addRect(posx, posy - (h/3), b/5, (h/3), col); //SCHORNSTEIN
  44. addCircleBorder(posx + b - d + (b/20), posy+h - ((h/3)*2)/2, d, col); //RAD RECHTS
  45. addCircleBorder(posx + b - d - (b/4), posy+h - ((h/3)*2)/2, d, col); //RAD MITTE
  46. addCircleBorder(posx - (d/8), posy+h - ((h/3)*2)/2, d, col); //RAD LINKS
  47. }
  48. }
  49.  
  50.  
  51. /**
  52. * Diese Klasse enthält als Attribut zur Organisation des Zuges die Referenz auf den an ihm
  53. * angehängten Wagen. Zum Zeichnen sind wiederum Attribute, die die Geometrie der Wagen festlegen
  54. * vorzusehen (Länge, ...).
  55. * */
  56. public static class Wagon {
  57.  
  58. int b;
  59. int h;
  60. int d;
  61. int s;
  62. int posx;
  63. int posy;
  64. String col;
  65. String text;
  66.  
  67. // Wagon next;
  68. // Wagon (Wagon n){
  69. // next=n;
  70. // }
  71.  
  72. /** Dies ist der Konstruktor */
  73. Wagon (){
  74. b=100;
  75. h=40;
  76. d=(h/3)*2;
  77. s=b/5;
  78. posy=100;
  79. col="black";
  80. }
  81.  
  82. void paint(int n) {
  83. posx=50+(n*(b+s));
  84. text=""+n;
  85.  
  86. if (n==0) return;
  87. addRect(posx, posy, b, h, col);
  88. addRect(posx-s, posy+(h/5)*4, s, h/15, col);
  89. addCircleBorder(posx + (b/15), posy+h - ((h/3)*2)/2, d, col);
  90. addCircleBorder(posx + b - d - (b/15), posy+h - ((h/3)*2)/2, d, col);
  91. addRectBorder(posx+(b/2)-(b/8), posy+(h/4), b/4, h/2, white, text);
  92.  
  93. n--;
  94. paint(n);
  95.  
  96. }
  97.  
  98. }
  99.  
  100.  
  101. public static void main (String args []) {
  102.  
  103. // int n=readInt("Wieviele Wagons? ");
  104. int n=3;
  105.  
  106. Lok l = new Lok();
  107. l.paint();
  108.  
  109. Wagon w = new Wagon();
  110. w.paint(n);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement