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

2011/11/19

Beginner Programmer, please help!

shutterbugemily shutterbugemily

2011/11/19

#
I have no idea what I'm doing, anything you guys can tell me would be helpful...I'm not a good programmer. This is what I need to do... Problem: You will use Greenfoot to create a scenario which is a simple simulation of a fish aquarium. The scenario must meet the following requirements: I have these done... • The aquarium world should be at least 600 by 400 cells in size. • Background graphics: Set an image file for the aquarium. • There are three different types of fish: Yellow, Green, and Striped. I don't know how to do these... • All fish start at random locations within the aquarium. The number of each type fish can be varied depend on your aquarium size. • All fish move: o Yellow fish only move randomly, o Green fish move horizontally, and o Striped fish move diagonally. o Striped fish move at 2 cells per “act” (they are faster because they have racing stripes); all other fish move 1 cell per “act”. o Each type of fish should change direction when they touch the edges of the aquarium. • Fish eat other fish: Yellow fish eat only other Yellow fish, Green fish eat only Yellow fish and Striped fish eat any other non-striped type of fish. One fish eats another fish when the fish intersect each other in the aquarium. Eaten fish are removed from the aquarium. If two yellow fish intersect on of the two is eaten and the other is not. This can be random or by any rule you decide that makes sense in your code. • Fish eat to live: Yellow fish must eat another fish every 800 “acts”, Green fish must eat another fish every 400 “acts”, Striped fish must eat another fish every 200 “acts”. If an individual fish does not eat before the required time, it starves to death. If a fish starves it should go “belly up” (the fish’s image should be turned upside down) and stop moving (or float belly up to the top and then stop moving). No fish will eat a fish which has died of starvation.
Royalblue64 Royalblue64

2011/11/19

#
Fortunately, this is not too hard. However, I have some questions: - When the fish reach the edge of the world, do they have to turn a specific amount? - Do you want me to make this simulation, post the code, and then you have it? (I trust that you will use it then look at what I did and learn from it) - Also, is this like some sort of assignment at a school? If so, when do you need it by? But I would be happy to do this for you under the condition that you do actually attempt to learn how I got everything to work.
shutterbugemily shutterbugemily

2011/11/20

#
I think they just have to turn around and go in the other direction. It's due tomorrow at midnight, and that would actually be perfect because I've been really sick and I've missed basically every example and I'm just so lost. I would probably be able to teach myself, thank you so much!
Royalblue64 Royalblue64

2011/11/20

#
These are all of the individual classes starting with the world class. For ease, just use the names I've given as the name of the class. Each class here can be copy & pasted into the right class. If you have any questions about the code, ask me. Also, if you want to post this simulation on www.greenfoot.org, you can, but make sure that you give me credit! PUT THIS UNDER 'WORLD' AquariumWorld import greenfoot.*; public class AquariumWorld extends World { public AquariumWorld() { super(600, 400, 1); addFish(); } public void addFish() { for (int i = 0; i < getWidth() / 100; i++) { addObject(new Yellowfish(), Greenfoot.getRandomNumber(600) + 20, Greenfoot.getRandomNumber(400) + 20); } // CUT add other fish } } PUT THIS UNDER 'ACTOR' Fish // CUT: Animal class deleted - not needed. It's easier without it anyway PUT THE REST UNDER 'FISH' Yellowfish import greenfoot.*; public class Yellowfish extends Animal { public void act() { moveRandomly(); checkForWorldEdge(); checkForYellowfish(); subtractHealth(); checkHealth(); } private int health = 800; public void moveRandomly() { // CUT } public void checkForWorldEdge() { // CUT } public void checkForYellowfish() { // CUT } public void subtractHealth() { // CUT } public void checkHealth() { // CUT } } Greenfish import greenfoot.*; public class Greenfish extends Animal { public void act() { moveHorizontally(); checkForWorldEdge(); checkForYellowfish(); subtractHealth(); checkHealth(); } private int health = 400; private int turn = 25; public void moveHorizontally() { // CUT } public void checkForWorldEdge() { // CUT } public void checkForYellowfish() { // CUT } public void subtractHealth() { // CUT } public void checkHealth() { // CUT } }
mik mik

2011/11/20

#
Come on guys - that's not how it's done. If you're posting a complete solution of what is clearly school homework, you're not helping. If it's your homework, you might first be happy to get it, but all that happens is that your teacher thinks you're okay, moves on to more difficult stuff, and at the end you fail the test. @Royalblue64: It's great that you're willing to help, but if you really want to help: Explain how to do it, don't poste the code for copy and paste. (And by the way: there are much simpler ways to do many of these things that you have posted. If you're starting to talk about it, you would find out!) I have deleted parts of the code posted above. -mik-
darkmist255 darkmist255

2011/11/20

#
@shutterbugemily Yeah, I hope you're not just copying stuff down. Read it over, get an understanding of what's happening in the code, then with that in mind, go and write some stuff out. Your mark is important in class, but once you're done class your understanding is worth way more than your marks.
Royalblue64 Royalblue64

2011/11/20

#
mik wrote...
Come on guys - that's not how it's done. If you're posting a complete solution of what is clearly school homework, you're not helping. If it's your homework, you might first be happy to get it, but all that happens is that your teacher thinks you're okay, moves on to more difficult stuff, and at the end you fail the test. @Royalblue64: It's great that you're willing to help, but if you really want to help: Explain how to do it, don't poste the code for copy and paste. (And by the way: there are much simpler ways to do many of these things that you have posted. If you're starting to talk about it, you would find out!) I have deleted parts of the code posted above. -mik-
I asked him first if he would try to interpret the code and understand how everything worked, and he said that he could and would. Also, if you take some code that you don't understand and use it for other things that are assigned, you start to understand how it works anyway. I've used that as a way to learn code in more than one programming language. Now on a different topic, I see that you deleted just about every method I made and said that there were simpler ways to do it. What ways are these? Some stuff I get, like the code I ripped from the animal class I could use something else, but the other stuff? I don't really see how I could get rid of all of those methods... Any help with that would be great. And by the way: I actually meant to put in comments explaining stuff but I forgot. Sorry.
rjl8789 rjl8789

2011/11/28

#
Would it be possible from someone to show the completed version, so you can see it actually running in Greenfoot?
You need to login to post a reply.