Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Löcher: x < 20 und y < 20
- * x > 370 y < 20
- * x > 370 y > 210
- * x < 20 y > 210
- */
- public class BilliardMitTisch
- {
- Turtle toni;
- public BilliardMitTisch()
- {
- toni = new Turtle();
- zeichneTisch();
- toni.setzeRichtung(20);
- toni.zumStart(150,100);
- toni.hebeStift();
- toni.zeige();
- toni.vor(1);
- //push();
- }
- public void zeichneTisch(){
- toni.zumStart(20,10);
- toni.setzeRichtung(0);
- for (int k = 0; k < 2; k++){
- toni.vor(350);
- toni.hebeStift();
- toni.vor(10);
- toni.drehe(90);
- toni.vor (10);
- toni.senkeStift();
- toni.vor(200);
- toni.hebeStift();
- toni.vor(10);
- toni.drehe(90);
- toni.vor (10);
- toni.senkeStift();
- }
- }
- public void drehe(int r){
- toni.drehe(r);
- }
- public void inDieMitte(){
- toni.geheNach(150, 100);
- }
- public void push(){
- for (int k = 1000; k > 0; k--){
- toni.setzeTempo(k/100);
- //Wenn toni innerhalb des Feldes ist, so
- if(toni.liesX()> 10 && toni.liesX() < 380 &&
- toni.liesY()> 10 && toni.liesY() < 230){
- toni.vor(1);
- }
- // sonst ist er am Rand und muss abbprallen
- else{
- // eingelocht?
- if (toni.liesX() <= 20 && toni.liesY() <= 20){
- break;
- }
- //links oder rechts am Rand?
- if (toni.liesX()<= 10 || toni.liesX() >= 380){
- double neueRichtung = 180 - toni.liesRichtung();
- toni.setzeRichtung(neueRichtung);
- toni.vor(1);
- }
- //toni ist am unteren oder oberen Rand
- else{
- double neueRichtung = -toni.liesRichtung();
- toni.setzeRichtung(neueRichtung);
- toni.vor(1);
- }
- //break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment