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

2019/1/8

Help!!!!!!!!! Can you please help me with my Counter source code.

mrflex mrflex

2019/1/8

#
The Program shows that everything is fine and without a syntax error. But as soon as a point should go up caused by a collision a white screen comes up with a mistake notice. The Code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { public int score; public Counter() { setImage(new GreenfootImage("0", 20, Color.WHITE, Color.BLACK)); } public void act() { if(score>=10){ setLocation(400,250); setImage(new GreenfootImage("The player2 won!",60,Color.RED,Color.BLACK)); Greenfoot.stop(); } } public void scoreCount(int amount){ score += amount; setImage(new GreenfootImage("" + score)); } }
danpost danpost

2019/1/8

#
mrflex wrote...
The Program shows that everything is fine and without a syntax error. But as soon as a point should go up caused by a collision a white screen comes up with a mistake notice. << Code Omitted >>
Need to see collision codes.
mrflex mrflex

2019/1/8

#
give me your email ill send you my game
mrflex mrflex

2019/1/8

#
Code from Player: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class player1 here. * * @author (your name) * @version (a version number or a date) */ public class player1 extends Actor { /** * Act - do whatever the player1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { checkKeypress(); } public void checkKeypress() { if (Greenfoot.isKeyDown("left")){ move(-8); } if (Greenfoot.isKeyDown("right")){ move(8); } } } Food which when hit player needs to be count: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class food here. * * @author (your name) * @version (a version number or a date) */ public class food extends Actor { /** * Act - do whatever the food wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setRotation(90); move(5); spielerBeruehrt(); if(isAtEdge()){ setLocation(Greenfoot.getRandomNumber(560),0); } if(isTouching(player1.class)){ setLocation(Greenfoot.getRandomNumber(560),0); } if(isTouching(player2.class)){ setLocation(Greenfoot.getRandomNumber(560),0); } } private void spielerBeruehrt(){ if(isTouching (player1.class)){ Sky skyWorld = (Sky) getWorld(); Counter counter = skyWorld.getCounter(); counter.scoreCount(1); } if(isTouching (player2.class)){ } } }
danpost danpost

2019/1/8

#
In the last line in your Counter class, you try to create an image -- but you are missing some arguments for the constructor of that image.
mrflex mrflex

2019/1/8

#
what is missing
danpost danpost

2019/1/8

#
mrflex wrote...
what is missing
Font size, text color and background Color. See here.
You need to login to post a reply.