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

2018/2/3

How can i use those classes (see in the topic) in my scenario

1
2
Super_Hippo Super_Hippo

2018/2/5

#
You need to get the score which should be used, so the score variable in the world in which the actor is (or in your case just the class because most of your variables are static for no reason...). Right now, the score variable is private so you will need a getter method to access it.
frequency frequency

2018/2/5

#
I am stuck man. Got no more ideas..
Super_Hippo Super_Hippo

2018/2/5

#
Which part of my message was unclear?
danpost danpost

2018/2/5

#
From what I gave, you should have been able to figure out that it should actually be 'World_30.getScore()' in the Timer30 class (and similar in the other timer classes). Apparently you are not applying yourself at all and having others do the work for you.
frequency frequency

2018/2/5

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

/**
 * Write a description of class Score here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class Score30 extends Scores
{
    private static final Color TEXT_COLOR=new Color(200,0,0);
    private static final Color TRANSPARENT_COLOR=new Color(0,0,0,0);
    
    /**
     * Act - do whatever the Score wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    
    private void updateImage()
    {
       String text="Score:"+World_30.getScore();
       GreenfootImage image=new
       GreenfootImage(text,30,TEXT_COLOR,TRANSPARENT_COLOR);
       setImage(image);
       
       
    }
    
    public void act() 
    {
        
        updateImage();
  
    }
    public Score30()
    {
        updateImage();
        
        
    }
    
  
  
    
}
MAIN MENU class
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class MainMenu here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainMenu extends World
{
    /**
    * Constructor for objects of class MainMenu.
    * 
    */
    private static final Color TEXT_COLOR = new Color(255,255,255);
    private static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
    public  static int highScore30, highScore60, highScore90;
    public MainMenu()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
            super(1500,800,1); 
            Items();
            Intro();
        
    }
    
    void Items()
    {   
            addObject(new thirty_seconds(),750,400);
            addObject(new sixty_seconds(),750,500);
            addObject(new ninety_seconds(),750,600);
            addObject(new Credits(),750,700);
            HiScores();
        
    }
    
    void Intro()
    {
             GreenfootSound sound = new GreenfootSound("START.wav");
             Greenfoot.playSound("START.wav");
    }

    public static void finalScore30(int score)
    {
    if (score > highScore30) 
    {
            highScore30 = score;
    }
    }
    
    
    public static void finalScore60(int score)
   {
    if (score > highScore60)
    {
            highScore60 = score;
    }
   }


    public static void finalScore90(int score)
    {
    if (score > highScore90)
    {
            highScore90 = score;
    }
   }
    
    private void HiScores()
    {
        GreenfootImage text = new GreenfootImage("30-second High Score: "+highScore30, 30, TEXT_COLOR, TRANSPARENT_COLOR);
        getBackground().drawImage(text, 1000, 50);
        text  = new GreenfootImage("60-second High Score: "+highScore60, 30, TEXT_COLOR, TRANSPARENT_COLOR);
        getBackground().drawImage(text, 1000, 504);
        text  = new GreenfootImage("90-second High Score: "+highScore90, 30, TEXT_COLOR, TRANSPARENT_COLOR);
        getBackground().drawImage(text, 1000, 570);
   }
}
I dont know why i cant get my self together. Maybe its the fact that i am not american, and cant get your things straight.
Danpost wrote...
Apparently you are not applying yourself at all and having others do the work for you.
Yea ikr.At school we stopped on addobjects stuff and then i had to carry on by my self.I got more stuff to do than wasting my time here dan.Wouldnt that be a stupid idea? I came here all alone.I have been using greenfoot 2 months. Calm down.I am not using AI or i am programmed to do this automatically.I edited the
MainMenu.saveHighScore(1,World_30.getScore());      
and added it to the timer30 class on the part
 if (cycles == 0)
        {
            Greenfoot.setWorld(new GameOverScreen());
            MainMenu.saveHighScore(1,World_30.getScore());      
            
            sound.play();
        }
I will be looking to this,and also find a solution to make the highscores go to a new class with a custom image next. See ya!
frequency frequency

2018/2/5

#
Superhippo wrote...
You need to get the score which should be used, so the score variable in the world in which the actor is (or in your case just the class because most of your variables are static for no reason...). Right now, the score variable is private so you will need a getter method to access it.
So you say that i somehow link them together? Make a variable on the mainmenu and one on the timer and just communicate? I also made my private voids to public
danpost danpost

2018/2/5

#
Super_Hippo wrote...
most of your variables are static for no reason.
I did not see any issues with what static fields were present. They are either global constants or used outside the scope of a single game (or there is only one used within any game).
Right now, the score variable is private so you will need a getter method to access it.
One is already present (as you may well have since found out).
frequency frequency

2018/2/5

#
Can just get where the hell to put this. MainMenu.saveHighScore(30,World_30.getScore()); . I got it that i must put it in the timer30 and etc classes.But,in the act?,a new void? Also i put the highscore on the gameover screen.class http://www.greenfoot.org/scenarios/20792 Thats what i changed
danpost danpost

2018/2/6

#
frequency wrote...
Can just get where the hell to put this. MainMenu.saveHighScore(30,World_30.getScore()); . I got it that i must put it in the timer30 and etc classes.But,in the act?,a new void?
See here.
frequency frequency

2018/2/6

#
Thanks. But i get underlines on > MainMenu.saveHighScore(1, score); ! Also i will put those in the scoreboard at the end of the game,So i will change MainMenu to GameOverScreen. Correct?
danpost danpost

2018/2/6

#
frequency wrote...
Thanks. But i get underlines on > MainMenu.saveHighScore(1, score); !
That was also given above. Read through the discussion before asking and making me repeat myself.
Also i will put those in the scoreboard at the end of the game,So i will change MainMenu to GameOverScreen. Correct?
You will have to be more specific as to what you are referring to -- and also show what class and what codes you are dealing with.
frequency frequency

2018/2/6

#
I am sorry, I have been messing with this for 2 hours now and i can not make it run. I dont know why i am finding this so struggling to be honest. I will list the classes that i feel like it should matter. GAME OVER CLASS
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class GameOverScreen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GameOverScreen extends World
{
    
    private static final Color TEXT_COLOR = new Color(255,255,255);
    private static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
    public  static int highScore30, highScore60, highScore90;
    
    /**
     * Constructor for objects of class GameOverScreen.
     * 
     */
    public GameOverScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        
        super(1500,800,1);
        
        
        //VOID
        Back();
        //END_VOID
        
        //OBJECTS
        HiScores();
        addObject(new MainMenuButton(),1355,700);

    }

    void Back()
    {
        setBackground(new GreenfootImage("SCOREBOARD.png"));
    }

     public static void finalScore30(int score)
    {
        
    if (score > highScore30) 
    {
            highScore30 = score;
    }
    }
    
    
    public static void finalScore60(int score)
   {
    if (score > highScore60)
    {
            highScore60 = score;
    }
   }


    public static void finalScore90(int score)
    {
    if (score > highScore90)
    {
            highScore90 = score;
    }
   }
    
    private void HiScores()
    {
        GreenfootImage text = new GreenfootImage(""+highScore30, 30, TEXT_COLOR, TRANSPARENT_COLOR);
        getBackground().drawImage(text, 625, 265);
        
         text  = new GreenfootImage(""+highScore60, 30, TEXT_COLOR, TRANSPARENT_COLOR);
        getBackground().drawImage(text, 625, 435);
        
        text  = new GreenfootImage(""+highScore90, 30, TEXT_COLOR, TRANSPARENT_COLOR);
        getBackground().drawImage(text, 625, 560);
        
        
        
        
        
        
        
        
       
   }
}







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

/**
 * Write a description of class Score here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class Score30 extends Scores
{
    private static final Color TEXT_COLOR=new Color(200,0,0);
    private static final Color TRANSPARENT_COLOR=new Color(0,0,0,0);
    
    /**
     * Act - do whatever the Score wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    
    private void updateImage()
    {
       String text="Score:"+World_30.getScore();
       GreenfootImage image=new
       GreenfootImage(text,30,TEXT_COLOR,TRANSPARENT_COLOR);
       setImage(image);
    }
    
    public void act() 
    {
        updateImage();
    }
    
    public Score30()
    {
        updateImage();
        
        
    }
    
  
  
    
}
TIMER 30 CLASS
import greenfoot.*;
import java.awt.Color;    
 
/**
 * an object that display the remaining time units before the scenario stops;
 * this class counts frames (or act cycles) as the regulating unit of time
 */
public class Timer30 extends Actor   
{      
    int time = 1; // seconds to run
    int fps = 55; // approximate number of frames per second (adjust as needed)
    int cycles = time * fps; // the countdown timer
    public static final Color TEXT_COLOR = new Color(255,255,255);
    public static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
    private int score = 0; //declare 'score' as private
    GreenfootSound sound = new GreenfootSound("DIE.wav");
    
   
    
    /*
     * sets the initial image of this Timer object
     */
    public Timer30()   
    {
        updateImage(); // shows remaining time
        
    }  
 
    /*
     * runs the timer and updates the image of this Timer object
     */
    public void act()   
    {    
        cycles--; // decrement countdown timer
        if (cycles % fps == 0)
        {
            updateImage();        // show the time remaining (only done when needed) 
           
        }
        if (cycles == 0)
        {
           
            Greenfoot.setWorld(new GameOverScreen());
           
            
            sound.play();
        }
    }
     
    
    
    /*
     * sets the image to the number of approximate seconds remaining on the timer
     */
    public  void updateImage()
    {
        setImage(new GreenfootImage("Seconds left " + (cycles+fps-1)/fps, 24,Color.RED, null));
        
  
    }

 



}
MAIN MENU CLASS
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class MainMenu here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainMenu extends World
{
    /**
    * Constructor for objects of class MainMenu.
    * 
    */
    private static final Color TEXT_COLOR = new Color(255,255,255);
    private static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
    public  static int highScore30, highScore60, highScore90;
    public MainMenu()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
            super(1500,800,1); 
            Items();
            Intro();
        
    }
    
    void Items()
    {   
            addObject(new thirty_seconds(),750,400);
            addObject(new sixty_seconds(),750,500);
            addObject(new ninety_seconds(),750,600);
            addObject(new Credits(),750,700);
            
        
    }
    
    void Intro()
    {
             GreenfootSound sound = new GreenfootSound("START.wav");
             Greenfoot.playSound("START.wav");
    }
}
   
    
danpost danpost

2018/2/6

#
Try putting it at line 42 of the timer class.
frequency frequency

2018/2/6

#
That was my first try ever. This is where i get the underlines http://prntscr.com/ib27ax
Super_Hippo Super_Hippo

2018/2/7

#
Where is your saveHighScore method now? It seems like it isn't in the MainMenu world anymore.
You need to login to post a reply.
1
2