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

2015/12/5

Writing Code for Tron Game

aang.18 aang.18

2015/12/5

#
I have a couple questions, for some reason I can't get the game to end when the cycles touch the world edge, I also for my project need to add an instruction and you win screen, should that screen be done by changing the world or just adding an image and then removing said image. Thanks.
aang.18 aang.18

2015/12/5

#
I also can't seem to stop the game when the cycles or trails collide.
ChethanU1 ChethanU1

2015/12/5

#
There is a point when we want to finish the game. Naturally, The command to stop to game is Greenfoot.stop(); Use System.out.println or Endgame.title to display message. To find edge isEdge(); Use these.
ChethanU1 ChethanU1

2015/12/5

#
if(collide()) { Greenfoot.stop(); Endgame.title }
ChethanU1 ChethanU1

2015/12/5

#
imageEndgame = new GreenfootImage("What ever you want to change.png"); setImage(imageEndgame); to just adding an image and then removing said image.
aang.18 aang.18

2015/12/5

#
Question, collide is not a method so I used getOneIntersectingObject, but I can't stop the game since I have to say return false else return false, is there a way to end the game?
aang.18 aang.18

2015/12/5

#
Also how do I add the instruction screen and then populate and create the world?
danpost danpost

2015/12/5

#
You can always break the problem down a little further. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if (collide()) gameOver();
//
private boolean collide()
{
     return objectCollision() || edgeCollision();
}
 
private boolean objectCollision()
{
    return collideCycle() || collideTrail();
}
 
private boolean collideCycle()
{
    return getOneIntersectingObject(Cycle.class) != null;
}
 
private boolean collideTrail()
{
    return getOneIntersectingObject(Trail.class) != null;
}
 
private boolean edgeCollision()
{
    return isAtEdge();
}
This code is probably not the exact code you would be using. It is only supplied to show the mechanism of breaking down the problem. Actually, however, this is an extreme example -- as everything in that code-set could be condensed to this:
1
if (getOneIntersectingObject(Cycle.class) != null || getOneIntersectingObject(Trail.class) != null || isAtEdge()) gameOver();
danpost danpost

2015/12/5

#
aang.18 wrote...
Also how do I add the instruction screen and then populate and create the world?
You can use an Actor or World subclass to create an instruction screen. Myself, I will usually go with a World subclass if the instruction would possibly be viewed in the middle of gameplay (which you may want to do during pausing of the game -- if you allow that). As far as populating and creating "the world" -- you need to specify which world you are referring to; or, rather, show attempted class code.
aang.18 aang.18

2015/12/5

#
Thank you all very much the game is more or less complete now.
aang.18 aang.18

2015/12/5

#
s
ChethanU1 ChethanU1

2015/12/5

#
void populate(){ Actor0 c = new Actor0(); addObject(c, 1, 1); Actor1 w = new Actor1(); int r3, r4; for(int i=0; i<3; i++){ w = new Actor1(); r3 = Greenfoot.getRandomNumber(450); r4 = Greenfoot.getRandomNumber(450); addObject(w, r3, r4); } }
You need to login to post a reply.