Guest User

Untitled

a guest
Jun 24th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. /**
  2. * Löcher: x < 20 und y < 20
  3. * x > 370 y < 20
  4. * x > 370 y > 210
  5. * x < 20 y > 210
  6. */
  7. public class BilliardMitTisch
  8. {
  9. Turtle toni;
  10. public BilliardMitTisch()
  11.  
  12. {
  13. toni = new Turtle();
  14. zeichneTisch();
  15. toni.setzeRichtung(20);
  16. toni.zumStart(150,100);
  17. toni.hebeStift();
  18. toni.zeige();
  19. toni.vor(1);
  20. //push();
  21. }
  22.  
  23. public void zeichneTisch(){
  24. toni.zumStart(20,10);
  25. toni.setzeRichtung(0);
  26. for (int k = 0; k < 2; k++){
  27. toni.vor(350);
  28. toni.hebeStift();
  29. toni.vor(10);
  30. toni.drehe(90);
  31. toni.vor (10);
  32. toni.senkeStift();
  33. toni.vor(200);
  34. toni.hebeStift();
  35. toni.vor(10);
  36. toni.drehe(90);
  37. toni.vor (10);
  38. toni.senkeStift();
  39. }
  40. }
  41.  
  42. public void drehe(int r){
  43. toni.drehe(r);
  44. }
  45.  
  46. public void inDieMitte(){
  47. toni.geheNach(150, 100);
  48. }
  49.  
  50. public void push(){
  51. for (int k = 1000; k > 0; k--){
  52. toni.setzeTempo(k/100);
  53. //Wenn toni innerhalb des Feldes ist, so
  54. if(toni.liesX()> 10 && toni.liesX() < 380 &&
  55. toni.liesY()> 10 && toni.liesY() < 230){
  56. toni.vor(1);
  57. }
  58. // sonst ist er am Rand und muss abbprallen
  59. else{
  60. // eingelocht?
  61. if (toni.liesX() <= 20 && toni.liesY() <= 20){
  62. break;
  63. }
  64. //links oder rechts am Rand?
  65. if (toni.liesX()<= 10 || toni.liesX() >= 380){
  66. double neueRichtung = 180 - toni.liesRichtung();
  67. toni.setzeRichtung(neueRichtung);
  68. toni.vor(1);
  69. }
  70. //toni ist am unteren oder oberen Rand
  71. else{
  72. double neueRichtung = -toni.liesRichtung();
  73. toni.setzeRichtung(neueRichtung);
  74. toni.vor(1);
  75. }
  76. //break;
  77. }
  78. }
  79. }
  80. }
Add Comment
Please, Sign In to add comment