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

2017/6/6

Timer, Counter, Scoreboard. Need help in my game

1
2
3
FeVo FeVo

2017/6/7

#
Super_Hippo wrote...
I also started with Greenfoot in school like four and a half years ago, but I continued programming with it and it became a hobby. Give it a chance, it's a lot of fun if you understand what you are doing. If a line starts with a for example "private", it can't be in a method. It is either a method itself (e. g. the theCounter method) or a variable (e. g. counter, timer, time...). The variables belong to the beginning of the class, just where in line 21, you already have a time variable. So instead of this line, insert these:
private Counter counter[] = {new Counter("Roter Boxer: "), new Counter("Blauer Boxer: ")};
private Counter timer = new Counter("Zeit: ");
private int time = 30*55; //about 30 seconds
In the prepare method, you add objects. (I really dislike the Save the World feature since it usually results in a mess like that for new programmers...) Anyways, I told you to add the three objects, so you can place this code in the prepare method:
//the coordinates should be altered so they are added to the correct position
addObject(counter[0], 70, 30);
addObject(counter[1], 120, 30);
addObject(timer, 170, 30);
The getter-method for the counters is, as the name says, a method. So it could for example be in line 563:
public Counter getCounter(int i) {return counter[i];}
Then, you only need to add the act method in the same way. A new method must not be placed in another method, but anywhere in the class. I personally place the act method right after the constructor, so after line 33:
public void act()
{
    if (--time % 55 == 0)
    {
        timer.add(-1);
        if (time==0)
        {
            if (counter[0].getValue() > counter[1].getValue()) //red won
            else if (counter[0].getValue() < counter[1].getValue()) //blue won
            else //draw -- Unentschieden
        }
    }
}
if I try to add the act method, there come 3 errors: 1. and 2. at the 2 "else": ´else´ without "if" and 3. at the "}" : illegal start of statement What should I do? And I also have 2 other "wishes" for my game can u help me there too?
Super_Hippo Super_Hippo

2017/6/7

#
The errors happen because you have to add some code (e. g. adding an actor with an image showing who won) instead of the comments.
danpost danpost

2017/6/7

#
Upon a tie (both players having the same score), you could go into sudden death overtime by changing line 10 to this:
else time = 1;
Next player to score will win.
FeVo FeVo

2017/6/7

#
danpost wrote...
Upon a tie (both players having the same score), you could go into sudden death overtime by changing line 10 to this:
else time = 1;
Next player to score will win.
Ok thank U.
Super_Hippo wrote...
The errors happen because you have to add some code (e. g. adding an actor with an image showing who won) instead of the comments.
Where should i write what? Can u do it pls, if its ok and explain then? And there are also Errors in the "private void makeNewCoin" line. Will they disappear then?
danpost danpost

2017/6/7

#
You should be able to rid yourself of the 'makeNewCoin' errors by changing lines 548 and 549 to:
int rand = 2+Greenfoot.getRandomNumber(16);
int rand2 = 2+Greenfoot.getRandomNumber(16);
changing lines 554 and 555 to:
rand = 2+Greenfoot.getRandomNumber(16);
rand2 = 2+Greenfoot.getRandomNumber(16);
and changing line 559 to:
addObject(coin, rand, rand2);
Super_Hippo Super_Hippo

2017/6/7

#
if (counter[0].getValue() > counter[1].getValue()) showText("Rot hat gewonnen", 100, 100);
If that is not good enough, you can add an actor and give it an image showing text:
if (counter[0].getValue() > counter[1].getValue())
{
    Actor a = new Actor() {};
    a.setImage(new GreenfootImage("Rot hat gewonnen", 30, Color.BLACK, new Color(255,255,255,255)));
    addObject(a, getWidth/2, getHeight()/2);
}
FeVo FeVo

2017/6/8

#
Super_Hippo wrote...
if (counter[0].getValue() > counter[1].getValue()) showText("Rot hat gewonnen", 100, 100);
If that is not good enough, you can add an actor and give it an image showing text:
if (counter[0].getValue() > counter[1].getValue())
{
    Actor a = new Actor() {};
    a.setImage(new GreenfootImage("Rot hat gewonnen", 30, Color.BLACK, new Color(255,255,255,255)));
    addObject(a, getWidth/2, getHeight()/2);
}
There arent mistakes anymore but it still doesnt work.. It doesnt counts the coins collected and the time gets from "0" to "-(idk)". How can I make that it starts at 30 and goes down to 0 and if its 0 there should come the message or the picture I could design, depending on who collected more coins. If both got the same amount there should come a 10 second sudden death and the one who got more alltogether will win. And of course it should count the collected coins, so I can see it in the Counter. Maybe we should start from 0 with that, bcos it doesnt worked? Thanks a lot in front!
Super_Hippo Super_Hippo

2017/6/8

#
After this line:
addObject(timer, 170, 30);
add this:
timer.add(30);
For the 10 seconds sudden death, change
else time = 1;
to
else
{
    time = 10*55;
    timer.add(10);
}
To count the score, you need the line I gave you in the beginning:
//for red
((MyWorld) getWorld()).getCounter(0).add(1);

//for blue
((MyWorld) getWorld()).getCounter(1).add(1);
You have to add the line whenever red/blue collected a coin.
FeVo FeVo

2017/6/8

#
Super_Hippo wrote...
After this line:
addObject(timer, 170, 30);
add this:
timer.add(30);
For the 10 seconds sudden death, change
else time = 1;
to
else
{
    time = 10*55;
    timer.add(10);
}
To count the score, you need the line I gave you in the beginning:
//for red
((MyWorld) getWorld()).getCounter(0).add(1);

//for blue
((MyWorld) getWorld()).getCounter(1).add(1);
You have to add the line whenever red/blue collected a coin.
Sorry, but Im actually a bit confused and "silly" right now... Could u post all what I need to add into my legacy (idk if this is the right expression)"Wiese" Code and tell me where to add it or just edit my "legacy" Wiese Code and with all the things I need that it works and post it? Thanks very much for your work and endurance with me!
Super_Hippo Super_Hippo

2017/6/8

#
I think I explained where each line should go. Which one do you have trouble with? Btw, you don't have to quote the whole very last post every single time.
FeVo FeVo

2017/6/8

#
Ok xD, I deleted the codes and my "Wiese" code is the same as before i asked. So I dont have any idea anymore were what should be bcos this all confuses me and I only have 5 to 10 minutes until i need to go, so it would take too long to look after all and I need my game finished tomorrow and I'll come back too late so I need to finish it now and that is why I asked.. Thanks nevertheless and it would be soo awesome if u could do it. I know what is standing there and can explain it in the class so its not a problem for my if u do it now without explaining and so on.
Super_Hippo Super_Hippo

2017/6/8

#
What did you delete? You mean everything suggested in the thread? Why? If this really confuses you, how could you explain it in class? In the time you wrote this message, you could have easily insert the five missing lines. And it is 4 p. m., it's still some time until tomorrow ;)
FeVo FeVo

2017/6/9

#
i have got a week again and I did it all. Now my only problem is that the Timer counts up from 0 but it should count down from 1 minute (I doubled the speed so..) and if its at 0 there should come an image on the whole world which shows the following Text in Black on White: Der rote Boxer, der blaue Boxer //depends on who collected more coins// hat gewonnen, da er am meisten Münzen eingesammelt hat. Thanks in front
Super_Hippo Super_Hippo

2017/6/9

#
The timer shouldn't count up as it is right now. Show what you have. To create the image, you could use what you got here: https://www.greenfoot.org/topics/59430
FeVo FeVo

2017/6/10

#
idk how I can make, that it counts down. And I thought we already made, that there comes an image after the 30 seconds but there wont come anything
There are more replies on the next page.
1
2
3