Hello! So I am fairly new here. I just started the other day but I have little experience using Java. I am trying to learn more for school competition because I am good with other programming as well. Here is my problem. I have a game with little set up yet, but I want to make it turn based and the snakes controlled by an A.I. So what I want is one move for one piece a turn. I want to be able to have it controlled by mouse in that case, correct? Here is my code:
The snakes are A.I.
The spiders are Player Controlled with mouse
The ants are backround (I want them to move around randomly. Don't know how)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Spider here. * * @author (your name) * @version (a version number or a date) */ public class Spider extends Actor { /** * Act - do whatever the Spider wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown("w")) { turn(-3); } if (Greenfoot.isKeyDown("s")) { turn(3); } if (Greenfoot.isKeyDown("d")) { move(1); } Actor snake; snake = getOneObjectAtOffset(0, 0, Snake.class); if (snake != null) { World world; world = getWorld(); world.removeObject(snake); } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Snake here. * * @author (your name) * @version (a version number or a date) */ public class Snake extends Actor { /** * Act - do whatever the Snake wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Ant here. * * @author (your name) * @version (a version number or a date) */ public class Ant extends Actor { /** * Act - do whatever the Ant wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } }