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

2011/12/30

fixing my score board

1
2
3
programmer22 programmer22

2011/12/30

#
It still has the ')' expected error any ideas ? (sorry if that sounded rude)
darkmist255 darkmist255

2011/12/30

#
In your code it still says image.drawString(TRY AGAIN?, 60, 225); try changing it to image.drawString("TRY AGAIN?", 60, 225); The parentheses tell it that it's text, not a variable.
programmer22 programmer22

2011/12/30

#
also still want to know how to make the score board appear when the game ends and how to make it show the proper score ( sorr if that sounded rude to)
programmer22 programmer22

2011/12/30

#
the try again thing works =D
darkmist255 darkmist255

2011/12/30

#
It didn't sound rude :D. To make it appear, you could make a new actor called "Scoreboard", then when the game ends, you can make another actor do "getWorld().addObject(new Scoreboard, coordinate X, coordinate Y);" to make it show the proper score, you need to have it access a variable where the score is shown. Basically, do something like this
int score;
private void addedToWorld(world World)
{
    score = getWorld().score;
}
and put a way to keep track of the score in the world class.
programmer22 programmer22

2011/12/30

#
would it make it easier for you to tell me how to do this if i posted the source code on here? because after reading that im thinking that 1 ive seen another game that had a source code (Marbles) and it only had one score board and then im thinking that i have a counter then im thinking would it make it easier if he/she saw the code ?
programmer22 programmer22

2011/12/30

#
or would it be easier if i try what u just said?
darkmist255 darkmist255

2011/12/30

#
What part of it are you specifically having trouble with right now?
programmer22 programmer22

2011/12/30

#
well none of it really i just want to make the score board apear at the end of the game and for it to have a correct score
MultiplayerBanana MultiplayerBanana

2012/8/16

#
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.awt.Color;
import java.awt.Font;
import java.util.Calendar;

/**
* The ScoreBoard is used to display results on the screen. It can display some
* text and several numbers.
* 
* @author MultiplayerBanana
* @version 0.0.1
*/
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);
}

/**
* Create a score board for any message.
*/
public ScoreBoard(String txt)
{
makeTxt(txt);
}

/**
* Write anything on the board
*/
private void makeTxt(String txt)
{
GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);

image.setColor(new Color(0, 0, 0, 160));
image.fillRect(0, 0, WIDTH, HEIGHT);
image.setColor(new Color(255, 255, 255, 100));
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(txt, 60, 100);
setImage(image);
}

/**
* Make the score board image.
*/
private void makeImage(String title, String prefix, int score)
{
String tryAgain = "TRY AGAIN?";
GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
image.setColor(new Color(0, 0, 0, 160));
image.fillRect(0, 0, WIDTH, HEIGHT);
image.setColor(new Color(255, 255, 255, 100));
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, 75);
image.drawString(prefix + score, 60, 150);
image.drawString("TRY AGAIN?", 60, 225);  // THIS IS THE NEW CODE   
setImage(image);
}
}

Why not try this? It worked for me!

SPower SPower

2012/8/16

#
Do you really think it would help to reply to a forum which is 1 year old? And btw, I don't think that code is really yours, I've seen it multiple times...
trash1000 trash1000

2012/8/16

#
@Spower Well, there may be some people looking for something like this today, too. Besides, he didn't really say that it's his code.
danpost danpost

2012/8/16

#
@trash1000 @SPower The code MultiplayerBanana posted has the author's name included, if you did not see.
SPower SPower

2012/8/17

#
@danpost Sorry, I didn't see
danpost danpost

2012/8/17

#
@programmer22, my Menu Demo has a Button class with a Text sub-class that can be used to display a scoreboard. It has many methods to change the look, size, etc. It has several examples of large Text objects. For a text object with the same text as in the above code, you would use: "Game Over\nScore: " + score for its first parameter.
There are more replies on the next page.
1
2
3