Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import greenfoot.*;
- public class MyWorld extends World
- {
- //deklaracia
- CFish Fish1;
- CFish Fish2;
- CFish Fish3;
- CShark Shark1;
- CPufferFish PufferFish;
- public MyWorld()
- {
- super(800, 600, 1);
- //inicializacia
- Fish1 = new CFish("RybaPrva",10, "8", "4", "5", "6"); //aby nebolo treba pri kazdom spusteni zadavat klavesy
- //Fish1 = new CFish("RybaPrva",10); //pre zadavanie klaves cez okno.
- //Treba aj odkomentovat posledny riadok konstruktora triedy MyWorld "Fish1.ConfigureKeys();"
- this.addObject(Fish1, 200, 300);
- Fish2 = new CFish("RybaDruha", 10, "W", "A", "S", "D");
- this.addObject(Fish2, 200, 200);
- Fish3 = new CFish("RybaTretia", 10, "up", "left", "down", "right");
- this.addObject(Fish3, 200, 400);
- Shark1 = new CShark(Fish1, 10);
- this.addObject(Shark1, 500, 250);
- PufferFish = new CPufferFish();
- this.addObject(PufferFish, 0, 100);
- //Fish1.ConfigureKeys();
- }
- public void GenerateTrash()
- {
- //generacia odpadu v nahodnych intervaloch
- if (Greenfoot.getRandomNumber(500) < 2)
- {
- int Type = Greenfoot.getRandomNumber(3);
- CTrash Trash = null;
- //generacia nahodneho odpadu fries/plast/apple
- switch (Type)
- {
- case 0:
- Trash = new CFries();
- break;
- case 1:
- Trash = new CMacroPlast();
- break;
- case 2:
- Trash = new CApple();
- break;
- }
- //prida Trash na suradniciach [random; 0]
- this.addObject(Trash, 50 + Greenfoot.getRandomNumber(700), 0);
- }
- }
- public void GenerateFood()
- {
- //generacia jedla v nahodnych intervaloch
- if (Greenfoot.getRandomNumber(500) < 1)
- {
- int Size = Greenfoot.getRandomNumber(3) + 1;
- //prida Food na suradniciach [0; random]
- this.addObject(new CFood(Size), 0, Greenfoot.getRandomNumber(500) + 50);
- }
- }
- //volanie metod generacii
- public void act()
- {
- GenerateFood();
- GenerateTrash();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement