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

2014/5/1

Help wiht the finish of the game

1
2
BasseQ47 BasseQ47

2014/5/1

#
hey i am making this game for a project in school. it is a game where you travel in time and to move on in time you have to answer a question but my problem is that i cant get my score to work. and then i don't know how to make the next question appear after you have answered on the first one. and at last i have a man that have to move up a time line when ever that you has given a correct answer i hope that some one in her can help me i have to be finish on Sunday World class
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
/**
 * Write a description of class world here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Timeworld extends World
{
    public Counter scoreCounter;
    int correctButton;
    int Questing_1;
   
    GreenfootSound backgroundmusic = new GreenfootSound("Zack Hemsey - Mind Heist Evolution.mp3");
       /**
     * Constructor for objects of class world.
     * 
     */
    public Timeworld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1500, 900, 1); 
        
        Counter counter = new Counter();
        addObject(counter, 908,48);
        
        addObject(new Man() , 1300 ,800);
        addObject(new TimeLine() , 1250 ,450);
        addObject(new Questing_1(counter), 320,300);
        addObject(new correctButton(), 450,430);
        addObject(new buttonEorror(), 350,430);
        addObject(new buttonEorror(), 250,430);
       
      
    }
            public void act()
    {
        Counter counter = new Counter();
        if (Greenfoot.isKeyDown("2"))  
        
        {
         
         addObject(new Questing_2(counter), 320, 300);
         addObject(new correctButton(), 250,430);
         addObject(new buttonEorror(), 350,430);
         addObject(new buttonEorror(), 450,430);
        }
        if (Greenfoot.isKeyDown("3"))       
          {
         addObject(new Questing_3(counter), 320, 300);
         addObject(new correctButton(), 250,430);
         addObject(new buttonEorror(), 350,430);
         addObject(new buttonEorror(), 450,430);
        }
         if (Greenfoot.isKeyDown("4"))       
        {
         
         addObject(new Questing_4(counter), 320, 300);
         addObject(new correctButton(), 350,430);
         addObject(new buttonEorror(), 250,430);
         addObject(new buttonEorror(), 450,430);
     
        }
          if (Greenfoot.isKeyDown("5"))       
        {
         
         addObject(new Questing_5(counter), 320, 300);
         addObject(new correctButton(), 250,430);
         addObject(new buttonEorror(), 350,430);
         addObject(new buttonEorror(), 450,430);
        }
       
     
        
   
     
    
        
   
    }
     public void started()  
    {  
     backgroundmusic.play();
    }  
    public void gameOver() 
    {
        addObject(new ScoreBoard(scoreCounter.getValue()),getWidth()/2,getHeight()/2);
         Greenfoot.playSound("Sons Of Odin - Patrick Doyle.mp3");
         if(backgroundmusic.isPlaying())  
         {  
             backgroundmusic.stop();  
            }  
    }
       public void countScore(int score)
    {
        scoreCounter.add(score);
    }
    
     
}
   All the Questions classes 
[code]import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Instructions here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Questing_1 extends Actor
{
    private Counter counter;
    public GreenfootImage Questing_1 = new GreenfootImage("Questing_1.png"); 
     public Questing_1(Counter pointCounter)
        {
            counter = pointCounter;
        }
    public void act() 
    {
         Actor correctButton = getOneObjectAtOffset(450, 430, correctButton.class);
           
            if (Greenfoot.mouseClicked(correctButton)&&(this!= null))
            {
              
               counter.add(10);
               getWorld().removeObject(this);
               
              
              
            }
          
            
     }
  
}

public class Questing_2 extends Actor
{
   private Counter counter;
   
    private GreenfootImage Questing_2 = new GreenfootImage("Questing_2.png"); 
     public Questing_2(Counter pointCounter)
        {
            counter = pointCounter;
        }
       
     public void act() 
     {
      Actor correctButton = getOneObjectAtOffset(250, 430, correctButton.class); 
      
            if (Greenfoot.mouseClicked(correctButton))
            {
              
               counter.add(10);
               getWorld().removeObject(this);
               
              
              
            }
         
           
     }
}

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

/**
 * Write a description of class Questing_3 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Questing_3 extends Actor
{
   private Counter counter;
    private GreenfootImage Questing_1 = new GreenfootImage("Questing_3.png"); 
     public Questing_3(Counter pointCounter)
        {
            counter = pointCounter;
        }
      public void act() 
    {
       Actor correctButton = getOneObjectAtOffset(250, 430, correctButton.class);
            if (Greenfoot.mouseClicked(correctButton))
            {
              
               
               counter.add(10);
               getWorld().removeObject(this);
               
              
              
            }
            
     }    
}

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

/**
 * Write a description of class Questing_4 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Questing_4 extends Actor
{
    private Counter counter;
    private GreenfootImage Questing_1 = new GreenfootImage("Questing_4.png"); 
     public Questing_4(Counter pointCounter)
        {
            counter = pointCounter;
        }
    public void act() 
    {
         Actor correctButton = getOneObjectAtOffset(350, 430, correctButton.class);
            
           
            if (Greenfoot.mouseClicked(correctButton))
            {
              
               
               counter.add(10);
               getWorld().removeObject(this);
               
              
              
            }
         
    }    
}

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

/**
 * Write a description of class Questing_5 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Questing_5 extends Actor
{
  private Counter counter;
    private GreenfootImage Questing_1 = new GreenfootImage("Questing_5.png"); 
     public Questing_5(Counter pointCounter)
        {
            counter = pointCounter;
        }
    public void act() 
    {
       Actor correctButton = getOneObjectAtOffset(250, 430, correctButton.class);
           
            if (Greenfoot.mouseClicked(correctButton))
            {
              
               counter.add(10); 
               getWorld().removeObject(this);
               
              
              
            }
          
    }    
}
my TimeLine class
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class TimeLine here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class TimeLine extends Actor
{
   private GreenfootImage TimeLine = new GreenfootImage("TimeLine.png");    
}
my ScoreBoard
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
import java.awt.Font;
import java.util.Calendar;

public class ScoreBoard extends Actor
{
    public static final float FONT_SIZE = 48.0f;
    public static final int WIDTH = 400;
    public static final int HEIGHT = 300;
    
    /**
     * Create a score board with dummy result for testing.
     */
    public ScoreBoard()
    {
        
        this(100);
    }

    /**
     * Create a score board for the final result.
     */
    public ScoreBoard(int score)
    {
        makeImage("Game Over", "Score: ", score);
    }

    /**
     * Make the score board image.
     */
    private void makeImage(String title, String prefix, int score)
    {
        GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);

        image.setColor(new Color(0,255,255, 128));
        image.fillRect(0, 0, WIDTH, HEIGHT);
        image.setColor(new Color(0, 0, 0, 128));
        image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
        Font font = image.getFont();
        font = font.deriveFont(FONT_SIZE);
        image.setFont(font);
        image.setColor(Color.WHITE);
        image.drawString(title, 60, 100);
        image.drawString(prefix + score, 60, 200);
        setImage(image);
    }
}
my buttonEorror class 
[code]import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class buttomEorror_1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class buttonEorror extends Actor
{
 
        private boolean onThis=false;  
  
        public void act()  
        {  
             {
          if(Greenfoot.mouseMoved(null))  
            onThis = Greenfoot.mouseMoved(this);  
            if(onThis)  
            setImage("ButtonPressed.png");
            else  
            setImage("Buttonnotpress.png"); 
        }
          
        Actor correctButton = getOneIntersectingObject(correctButton.class);
          if (Greenfoot.mouseClicked(correctButton))
          {
              
              getWorld().removeObject(this);
             
          }
         if (Greenfoot.mouseClicked(this))
            {
              Timeworld Timeworld = (Timeworld)getWorld();
              GameOver gameover = new GameOver();
              Timeworld.gameOver();
             
            }
        
       
       
my counter class 

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

/**
 * A simple counter with graphical representation as an actor on screen.
 * 
 * @author mik
 * @version 1.0
 */
public class Counter extends Actor
{
    private static final Color transparent = new Color(0,0,0,0);
    private GreenfootImage background;
    private int value;
    private int target;

    /**
     * Create a new counter, initialised to 0.
     */
    public Counter()
    {
        background = getImage();  // get image from class
        value = 0;
        target = 0;
        updateImage();
    }
    
    /**
     * Animate the display to count up (or down) to the current target value.
     */
    public void act() 
    {
        if (value < target) {
            value++;
            updateImage();
        }
        else if (value > target) {
            value--;
            updateImage();
        }
    }

    /**
     * Add a new score to the current counter value.
     */
    public void add(int score)
    {
        target += score;
    }

    /**
     * Return the current counter value.
     */
    public int getValue()
    {
        return value;
    }

    /**
     * Set a new counter value.
     */
    public void setValue(int newValue)
    {
        target = newValue;
        value = newValue;
        updateImage();
    }

    /**
     * Update the image on screen to show the current value.
     */
    private void updateImage()
    {
        GreenfootImage image = new GreenfootImage(background);
        GreenfootImage text = new GreenfootImage("" + value, 22, Color.BLACK, transparent);
        image.drawImage(text, (image.getWidth()-text.getWidth())/2, 
                        (image.getHeight()-text.getHeight())/2);
        setImage(image);
    }
}

my Man class 

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

/**
 * Write a description of class man here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Man extends Actor
{
   
   public void act()
   {  
       
            
   }
   
}
here is a pic of my game hope that you guys can help me
danpost danpost

2014/5/2

#
In your TimeWorld class, you declare a Counter field call 'scoreCounter' at line 10 which, apparently, is not being used. Then, in your constructor of the class, at lines 24 and 25, you create a Counter object and assign it to a local variable called 'counter' in the one line and then add it into the world in the other. This Counter object is then passed to a new Questing_1 object that you add into the world at line 29. Next, in your 'act' method, you create another Counter object and set it to a local variable, also called 'counter'. For every act cycle that one of the detected keys are down (which could be many in a row), you will create and add a new Counter object into the world, one on top of another (as well as multiple other objects (which include Questing_# objects buttonEorror objects and correctButton objects). You need to put additional condition(s) on the code that spawns and adds actors into your world in the 'act' method. You need to work with only one Counter (there should only be one occurrence of 'new Counter()' per counter within your code).
BasseQ47 BasseQ47

2014/5/2

#
okay thank you for your reply can we just take one thing at the time i really like to find out how i get my questions to get a new question to spawn when the previous question has been answered. so first i delete all the counters so that is only appears once in the world class
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
/**
 * Write a description of class world here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Timeworld extends World
{
    public Counter scoreCounter;
    int correctButton;
    int Questing_1;
   
    GreenfootSound backgroundmusic = new GreenfootSound("Zack Hemsey - Mind Heist Evolution.mp3");
       /**
     * Constructor for objects of class world.
     * 
     */
    public Timeworld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1500, 900, 1); 
        
        Counter counter = new Counter();
        addObject(counter, 908,48);
        
        addObject(new Man() , 1300 ,800);
        addObject(new TimeLine() , 1250 ,450);
        addObject(new Questing_1(), 320,300);
        addObject(new correctButton(), 450,430);
        addObject(new buttonEorror(), 350,430);
        addObject(new buttonEorror(), 250,430);
       
      
    }
            public void act()
    {
        
        if (Greenfoot.isKeyDown("2"))  
        
        {
         
         addObject(new Questing_2(), 320, 300);
         addObject(new correctButton(), 250,430);
         addObject(new buttonEorror(), 350,430);
         addObject(new buttonEorror(), 450,430);
        }
        if (Greenfoot.isKeyDown("3"))       
          {
         addObject(new Questing_3(), 320, 300);
         addObject(new correctButton(), 250,430);
         addObject(new buttonEorror(), 350,430);
         addObject(new buttonEorror(), 450,430);
        }
         if (Greenfoot.isKeyDown("4"))       
        {
         
         addObject(new Questing_4(), 320, 300);
         addObject(new correctButton(), 350,430);
         addObject(new buttonEorror(), 250,430);
         addObject(new buttonEorror(), 450,430);
     
        }
          if (Greenfoot.isKeyDown("5"))       
        {
         
         addObject(new Questing_5(), 320, 300);
         addObject(new correctButton(), 250,430);
         addObject(new buttonEorror(), 350,430);
         addObject(new buttonEorror(), 450,430);
        }
       
     
        
   
     
    
        
   
    }
     public void started()  
    {  
     backgroundmusic.play();
    }  
    public void gameOver() 
    {
        addObject(new ScoreBoard(scoreCounter.getValue()),getWidth()/2,getHeight()/2);
         Greenfoot.playSound("Sons Of Odin - Patrick Doyle.mp3");
         if(backgroundmusic.isPlaying())  
         {  
             backgroundmusic.stop();  
            }  
    }
       public void countScore(int score)
    {
        scoreCounter.add(score);
    }
    
     
}
    
   
     
   


danpost danpost

2014/5/2

#
Please explain what your 'Questing_1' through 'Questing_5' objects do. Are they just to display images, each having one question and several options? Also, please post the code to one of those classes.
BasseQ47 BasseQ47

2014/5/2

#
yes Questing_1 one is just a image where i through the world have added some buttons the only thing they do is remove them selve the correctButton is pressed. here is the code for Questing_1
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Instructions here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Questing_1 extends Actor
{
    private Counter counter;
    public GreenfootImage Questing_1 = new GreenfootImage("Questing_1.png"); 
    
    public void act() 
    {
         Actor correctButton = getOneObjectAtOffset(450, 430, correctButton.class);
           
            if (Greenfoot.mouseClicked(correctButton)&&(this!= null))
            {
              
               
               getWorld().removeObject(this);
               
              
              
            }
          
            
     }
  
}
danpost danpost

2014/5/2

#
But what does the image look like? is there any text on the image? if so, what does it say?
BasseQ47 BasseQ47

2014/5/2

#
okay here it is the 3 red buttons are not part of the image the one on the left are correctBotton and the two others are buttonEorror i have 5 Questions displayed the same way through out the game.
BasseQ47 BasseQ47

2014/5/2

#
danpost danpost

2014/5/2

#
Okay. So, it is a panel that contains a question with its optional answers; and you have five different classes -- one for each question. Being you only want to add or change the question at specific times (not every act cycle), you need to move the code that you have in the act method to another method. This can be done easily, just by changing the name of the method from 'act' to something like 'nextQuestion'. Now, you will have something like this;
import greenfoot.*;

public class Timeworld extends World
{
    public Counter scoreCounter;
    int correctButton;
    int question;
   
    GreenfootSound backgroundmusic = new GreenfootSound("Zack Hemsey - Mind Heist Evolution.mp3");

    public Timeworld()
    {    
         super(1500, 900, 1); 
        
        scoreCounter = new Counter();
        addObject(scoreCounter, 908, 48);
        
        addObject(new Man() , 1300 ,800);
        addObject(new TimeLine() , 1250 ,450);
        nextQuestion();
    }

    public void nextQuestion()
    {
        question++;
        removeObjects(getObjects(buttonEorror.class));
        removeObjects(getObjects(correctButton.class));
        removeObjects(getObjects(Questing_1.class));
        removeObjects(getObjects(Questing_2.class));
        removeObjects(getObjects(Questing_3.class));
        removeObjects(getObjects(Questing_4.class));
        removeObjects(getObjects(Questing_5.class));
        if (question == 1)
        {
            addObject(new Questing_1(), 320, 300);
            addObject(new correctButton(), 450, 430);
            addObject(new buttonEorror(), 350, 430);
            addObject(new buttonEorror(), 250, 430);
        }
        if (question == 2)
        {
            addObject(new Questing_2(), 320, 300);
            addObject(new correctButton(), 250 ,430);
            addObject(new buttonEorror(), 350, 430);
            addObject(new buttonEorror(), 450, 430);
        }
        if (question == 3)       
        {
            addObject(new Questing_3(), 320, 300);
            addObject(new correctButton(), 250, 430);
            addObject(new buttonEorror(), 350, 430);
            addObject(new buttonEorror(), 450, 430);
        }
        if (question == 4)       
        {
            addObject(new Questing_4(), 320, 300);
            addObject(new correctButton(), 350, 430);
            addObject(new buttonEorror(), 250, 430);
            addObject(new buttonEorror(), 450, 430);
        }
        if (question == 5)       
        {
            addObject(new Questing_5(), 320, 300);
            addObject(new correctButton(), 250, 430);
            addObject(new buttonEorror(), 350, 430);
            addObject(new buttonEorror(), 450, 430);
        }
    }
   
    public void started()  
    {  
        backgroundmusic.play();
    }  

    public void gameOver() 
    {
        addObject(new ScoreBoard(scoreCounter.getValue()),getWidth()/2,getHeight()/2);
        Greenfoot.playSound("Sons Of Odin - Patrick Doyle.mp3");
        if(backgroundmusic.isPlaying())  
        {  
            backgroundmusic.stop();  
        }  
    }

    public void countScore(int score)
    {
        scoreCounter.add(score);
        nextQuestion();
    }
}
danpost danpost

2014/5/2

#
I added the 'removeObjects' lines into the 'nextQuestion' method to eliminate the excess actors in the world. Also, notice that I call the 'nextQuestion' method from the constructor, for the first question, and from the 'countScore' method, for the rest.
BasseQ47 BasseQ47

2014/5/2

#
So far so good but the Question 2 does not appear but it looks like it should
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
/**
 * Write a description of class world here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Timeworld extends World
{
    public Counter scoreCounter;
    int correctButton;
    int question;
   
    GreenfootSound backgroundmusic = new GreenfootSound("Zack Hemsey - Mind Heist Evolution.mp3");
   
      
       /**
     * Constructor for objects of class world.
     * 
     */
    public Timeworld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1500, 900, 1); 
        
        Counter counter = new Counter();
        addObject(counter, 908,48);
        
   
        
        nextQuestion(); 
        
       
      
    }
    public void nextQuestion()  
    {  
       
        question ++;
        removeObjects(getObjects(buttonEorror.class));  
        removeObjects(getObjects(correctButton.class));  
        removeObjects(getObjects(Questing_1.class));  
        removeObjects(getObjects(Questing_2.class));  
        removeObjects(getObjects(Questing_3.class));  
        removeObjects(getObjects(Questing_4.class));  
        removeObjects(getObjects(Questing_5.class)); 
        
        if (question == 1)  
        {  
            addObject(new Questing_1(), 320, 300);  
            addObject(new correctButton(), 450, 430);  
            addObject(new buttonEorror(), 350, 430);  
            addObject(new buttonEorror(), 250, 430);  
            
        }  
        
        if (question == 2)  
        {  
            addObject(new Questing_2(), 320, 300);  
            addObject(new correctButton(), 250 ,430);  
            addObject(new buttonEorror(), 350, 430);  
            addObject(new buttonEorror(), 450, 430);  
            
        }  
        
        if (question == 3)         
        {  
            addObject(new Questing_3(), 320, 300);  
            addObject(new correctButton(), 250, 430);  
            addObject(new buttonEorror(), 350, 430);  
            addObject(new buttonEorror(), 450, 430);  
        } 
        
        if (question == 4)         
        {  
            addObject(new Questing_4(), 320, 300);  
            addObject(new correctButton(), 350, 430);  
            addObject(new buttonEorror(), 250, 430);  
            addObject(new buttonEorror(), 450, 430);  
        }  
        
        if (question == 5)         
        {  
            addObject(new Questing_5(), 320, 300);  
            addObject(new correctButton(), 250, 430);  
            addObject(new buttonEorror(), 350, 430);  
            addObject(new buttonEorror(), 450, 430);  
        }  
    }  
     public void started()  
    {  
     backgroundmusic.play();
    }  
    public void gameOver() 
    {
        addObject(new ScoreBoard(scoreCounter.getValue()),getWidth()/2,getHeight()/2);
         Greenfoot.playSound("Sons Of Odin - Patrick Doyle.mp3");
         if(backgroundmusic.isPlaying())  
         {  
             backgroundmusic.stop();  
            }  
    }
       public void countScore(int score)
    {
        scoreCounter.add(score);
        nextQuestion();
    }
    
     
}
    
   
danpost danpost

2014/5/2

#
Are you getting any error messages? or, what is it doing that it should not be doing and what is it not doing that it should? Is the score being incremented?
BasseQ47 BasseQ47

2014/5/2

#
when i run it and answer the first question when it disappears like it should but it dose not spwan question number 2. and i dont see anypoints in my score when i answer the question why is that
danpost danpost

2014/5/2

#
I will need to see your 'correctButton' class code.
BasseQ47 BasseQ47

2014/5/2

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 import java.awt.*;  
/**
 * Write a description of class corretButtom here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class correctButton extends Actor
{
        Counter counter = new Counter();
        private boolean onThis=false;  
        
        Questing_1 Questing_1 = new Questing_1();
        
        public void act()  
         {  
             
            if(Greenfoot.mouseMoved(null))  
            onThis = Greenfoot.mouseMoved(this);  
            if(onThis)  
            setImage("ButtonPressed.png");
            else  
            setImage("Buttonnotpress.png"); 
        
            if ((Greenfoot.mouseClicked(this)))
            {
              
              
              counter.add(10);
             
              
             
              
              
            }

            
          
            if ((Greenfoot.mouseClicked(this)))
            {
              
              
              getWorld().removeObject(this);
             
              
             
              
              
            }
           
          
        
       
           
                      }   
       }
There are more replies on the next page.
1
2