This site requires JavaScript, please enable it in your browser!
Greenfoot back
jdkdoen05
jdkdoen05 wrote ...

2022/1/4

Ending a programm

1
2
3
danpost danpost

2022/2/22

#
jdkdoen05 wrote...
So we now did that but Player2 wins after just 1 second. The programm ends after just 2 seconds.
Well, progress ... I guess. How many check points are you using and how are you assigning them their id values?
jdkdoen05 jdkdoen05

2022/3/1

#
We are using 9 Checkpoints.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/** 
 * Write a description of class Gegner here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Spieler2  extends Mover
{
     GreenfootImage gameName = new GreenfootImage ("Winner 2.png");
      private int distanceCompleted;
      private int numberOfCheckPoints;
      
    public void act()
    {
        if (Greenfoot.isKeyDown("a")) 
        {
        turn(-2);
        move(1);
        }
        if (Greenfoot.isKeyDown("d"))
        {
        turn(2);
        move(1);
        }
        if (Greenfoot.isKeyDown("s")) 
        {
        move();
        }
        if (Greenfoot.isKeyDown("w"))
        {
        backward();
        }
        int numberOfCheckPoints = getWorld().getObjects(Checkpoint.class).size();
        Checkpoint checkPoint = (Checkpoint)getOneIntersectingObject(Checkpoint.class);
        if (checkPoint != null && (distanceCompleted + 1)%numberOfCheckPoints == checkPoint.identificationNumber);
        {
            distanceCompleted++;
            if (distanceCompleted == 210*numberOfCheckPoints) 
            {
               Greenfoot.setWorld(new Winner2());
            }
        }
        {
         if(this.isTouching(Checkpoint.class))
         this.numberOfCheckPoints = this.numberOfCheckPoints + 1;
        }
        {
         if(this.isTouching(Bariiere.class))
         move();
        }
        {
         if(this.isTouching(Oel.class))
         turn(60);
        }
   }
}
 
jdkdoen05 jdkdoen05

2022/3/1

#
I think what you mean is in line 13.
jdkdoen05 jdkdoen05

2022/3/1

#
We have 9 Chechpoints, but we now have the number 210, because the game ends after 11 seconds. Thats the half of 21.
jdkdoen05 jdkdoen05

2022/3/1

#
Now again for understanding. We have that Fixed the game ending after a certain number of seconds. the higher we set the numberOfCheckpoints, the longer the game goes.
danpost danpost

2022/3/1

#
jdkdoen05 wrote...
I think what you mean is in line 13.
That line can be removed.
danpost danpost

2022/3/1

#
jdkdoen05 wrote...
Now again for understanding. We have that Fixed the game ending after a certain number of seconds. the higher we set the numberOfCheckpoints, the longer the game goes.
Remove lines 45 through 48. The player should not be changing the number of check points. The value in line 40, currently 210, is what determines how many complete laps the player is to traverse. So, currently, you have the player doing 210 laps. Side note: not sure why you have line 11 in the class. There is no need to retain that image during play time. That, and I do not see it being used in the class (although, I may have missed it).
jdkdoen05 jdkdoen05

2022/3/2

#
But if we remove line 13 it says that it cannot find the symbol. So there is no variable.
jdkdoen05 jdkdoen05

2022/3/2

#
The program still ends after 2 seconds
danpost danpost

2022/3/2

#
jdkdoen05 wrote...
But if we remove line 13 it says that it cannot find the symbol. So there is no variable.
Where does it say that? (show revised code and indicate on which line the error is located)
jdkdoen05 jdkdoen05

2022/3/2

#
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)

/**
 * Dies Klasse beschreibt eine Krabbe.
 * 
 * @author (your name)
 * @version (a version number or a date)
 */
public class Spieler1  extends Mover
      
{
    private int distanceCompleted;
    private int removeTouching;
    private int numberOfCheckPoints;
        
    public void act()
    {
      
      if (Greenfoot.isKeyDown("left")) 
       {
        turn(-2);
        move(1);
        }
      if (Greenfoot.isKeyDown("right"))
       {
        turn(2);
        move(1);
        }
      if (Greenfoot.isKeyDown("down"))
        {
        move();
        }
      if (Greenfoot.isKeyDown("up"))
        {
        backward();
        }
      int numberOfCheckPoints = getWorld().getObjects(Checkpoint.class).size();
        Checkpoint checkPoint = (Checkpoint)getOneIntersectingObject(Checkpoint.class);
      if (checkPoint != null && (distanceCompleted + 1)%numberOfCheckPoints == checkPoint.identificationNumber);
        {
            distanceCompleted++;
            if (distanceCompleted == 900*numberOfCheckPoints) 
            {
               Greenfoot.setWorld (new Winner2());
            }
       
      if(this.isTouching(Checkpoint.class))
         {
         this.numberOfCheckPoints = this.numberOfCheckPoints + 1;
         }
      if(this.isTouching(Bariiere.class))
         {
         move();
         }
      if(this.isTouching(Spieler2.class))
         {
         move();
         }
      if(this.isTouching(Oel.class))
         {
         turn(60);
         Greenfoot.delay(5);
         turn(60);
         Greenfoot.delay(5);
         turn(60);
         Greenfoot.delay(5);
         turn(60);
         Greenfoot.delay(5);
         turn(60);
         Greenfoot.delay(5);
         turn(60);
         removeTouching(Oel.class);
         removeTouching(Oelfleck.class);
         }
    }
   }
}  
jdkdoen05 jdkdoen05

2022/3/2

#
The problem comes in line 49 and 42 when i delete line 14.
danpost danpost

2022/3/3

#
jdkdoen05 wrote...
The problem comes in line 49 and 42 when i delete line 14.
Remove all instances of "this." from those lines that are in front of "numberOfCheckPoints".
jdkdoen05 jdkdoen05

2022/3/3

#
That doent works. It also stoped after 2 seconds.
danpost danpost

2022/3/3

#
jdkdoen05 wrote...
That doent works. It also stoped after 2 seconds.
So, no errors. Correct?
You need to login to post a reply.
1
2
3