Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: AS Assignment project - Creating a game in Greenfoot

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question AS Assignment project - Creating a game in Greenfoot

    Hi there,

    I spent two months developing my game as an AS assignment. The game is fully executable, but now the counter will not count the points when the ship gets the objects.


    Will anyone be able to help!


    Thanks
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: AS Assignment project - Creating a game in Greenfoot

    Can you post the code here in the forum so all can see ?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: AS Assignment project - Creating a game in Greenfoot

    Quote Originally Posted by Norm View Post
    Can you post the code here in the forum so all can see ?
    public void Ship extends Actor
    {
        private int score = 0;
       private Counter counter;
     
       public Ship(Counter pointCounter)
       {
           counter = pointCounter;
        }
     
        /**
         * Act - do whatever the Ship wants to do. This method is called whenever
         * the 'Act' or 'Run' button gets pressed in the environment.
         */
        public void act() 
        {
            move(10);
     
        if (Greenfoot.isKeyDown("up"))
            {
                move(10);
        }
        if (Greenfoot.isKeyDown("down"))
        {
              move(-10);
        }    
        if (Greenfoot.isKeyDown("right"))
        {
            turn(10);
        }
       if (Greenfoot.isKeyDown("left"))
       {
           turn(-10);
        }
        if (Greenfoot.isKeyDown("q"))
        {
            turn(180);
        }
        Actor binary1 = getOneIntersectingObject(Binary1.class);
        if (binary1 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary1.setLocation(xCoord, yCoord);
            shipWorld.increaseScore();
            Greenfoot.playSound("kaboom.wav");
    }
       Actor binary0 = getOneIntersectingObject(Binary0.class);
       if (binary0 !=null)
       {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary0.setLocation(xCoord, yCoord);
            shipWorld.increaseScore();
            Greenfoot.playSound("kaboom.wav");
    }
        Actor submarine = getOneIntersectingObject(Submarine.class);
    if (submarine != null)
     {
        // we have hit a sub so we get access to the
        // world using the getWorld() method and then
        // use the removeObject method to remove the 
        // ship from the game.
        World shipWorld = getWorld();
        shipWorld.removeObject(this);
        Greenfoot.playSound("kaboom.wav");
       }
      }
    }

    public class Binary0 extends Actor
    {
        private int score = 0;
        private Counter counter;
     
        public Binary0(Counter pointCounter)
        {
            counter = pointCounter;
        }
     
        public void act()
        {
            binary0();
        }
     
        public void binary0()
        {
        Actor binary0 = getOneIntersectingObject(Binary0.class);
        if (binary0 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary0.setLocation(xCoord, yCoord);
            shipWorld.increaseScore();
            Greenfoot.playSound("kaboom.wav");
        }
        }
    }
    public class Binary1 extends Actor
    {
      public int score = 0;
        /**
         * Act - do whatever the Binary1 wants to do. This method is called whenever
         * the 'Act' or 'Run' button gets pressed in the environment.
         */
        public void act() 
        {
            Actor ship = getOneIntersectingObject(Ship.class);
            if (ship !=null)
             {
                ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
                int xCoord = Greenfoot.getRandomNumber(600);
                int yCoord = Greenfoot.getRandomNumber(400);
                ship.setLocation(xCoord, yCoord);
                shipWorld.increaseScore();
                Greenfoot.playSound("kaboom.wav");
            }
            Actor submarine = getOneIntersectingObject(Submarine.class);
            if (submarine !=null)
            {
                ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
                int xCoord = Greenfoot.getRandomNumber(600);
                int yCoord = Greenfoot.getRandomNumber(400);
                submarine.setLocation(xCoord, yCoord);
                shipWorld.decreaseScore();
                Greenfoot.playSound("kaboom.wav");
        }   
     }
    }
    public class Counter extends Actor
    {
       private int score = 0;
       private Counter counter;
     
       public void Score()
       {
           setImage(new GreenfootImage(200, 30));
           subtract();
           add();
           update();
        }
     
        public void add()
        {
            score++;
            update();
       }
     
       public void subtract()
       {
           score--;
           update();
        }
     
       public void update()
       {
           GreenfootImage img = getImage();
           img.clear();
           img.setColor(Color.WHITE);
           img.drawString("Score:  "  + score, 4, 20);
        }
    }
    public class Submarine extends Actor
    {
        private int score = 0;
        /**
            * Act - do whatever the Sub wants to do. This method is called whenever
            * the 'Act' or 'Run' button gets pressed in the environment.
            */
           public void act()
           {
            move(10);
            binary0();
            binary1();
            int xCoord = getX();
            if(xCoord <=0 || xCoord >=599)
            {
                int random = Greenfoot.getRandomNumber(41);
                turn(35 + random);
            }
            int yCoord = getY();
            if(yCoord <=0 || yCoord >=399)
            {
                int random = Greenfoot.getRandomNumber(41);
                turn(35 + random);
            }
        }
     
        public void binary0()
        {
          Actor binary0 = getOneIntersectingObject(Binary0.class);
        if (binary0 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary0.setLocation(xCoord, yCoord);
            shipWorld.decreaseScore();
            Greenfoot.playSound("kaboom.wav");
        }
    }
    public void binary1()
    {
      Actor binary1 = getOneIntersectingObject(Binary1.class);
        if (binary1 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary1.setLocation(xCoord, yCoord);
            shipWorld.decreaseScore();
            Greenfoot.playSound("kaboom.wav");
        }
      }
    }
    public class ShipGameWorld extends World
    {
        private int score = 0;
        private Counter counter;
     
         public ShipGameWorld()
        {
            super(600, 400, 1);
            prepare();
        }
     
        public void increaseScore()
        {
            score = score + 50;
        }
     
        public void decreaseScore()
        {
            score = score - 1;
        }
     
        public int getScore()
        {
            return score;
        }
     
        /**
         * Prepare the world for the start of the program. That is: create the initial
         * objects and add them to the world.
         */
        private void prepare()
        {
            Ship ship = new Ship(counter);
            addObject(ship, 283, 264);
            ship.setLocation(228, 165);
            ship.setLocation(326, 175);
            Binary0 binary0 = new Binary0(counter);
            addObject(binary0, 99, 274);
            Binary0 binary02 = new Binary0(counter);
            addObject(binary02, 464, 303);
            Binary1 binary1 = new Binary1();
            addObject(binary1, 368, 286);
            Binary0 binary03 = new Binary0(counter);
            addObject(binary03, 481, 83);
            Binary1 binary12 = new Binary1();
            addObject(binary12, 182, 79);
            Binary0 binary04 = new Binary0(counter);
            addObject(binary04, 194, 335);
            Submarine submarine = new Submarine();
            addObject(submarine, 199, 282);
            Counter counter = new Counter();
            addObject(counter, 41, 373);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            Counter counter2 = new Counter();
            addObject(counter2, 25, 383);
            removeObject(counter2);
            increaseScore();
            decreaseScore();
            getScore();
            Counter counter3 = new Counter();
            addObject(counter3, 515, 364);
            counter3.setLocation(114, 375);
            Counter counter4 = new Counter();
            addObject(counter4, 66, 338);
            counter4.Score();
            counter4.setLocation(120, 334);
            removeObject(counter);
            removeObject(counter3);
            counter4.setLocation(112, 376);
            counter4.setLocation(114, 371);
            getScore();
            decreaseScore();
        }
    }
    Last edited by helloworld922; April 5th, 2012 at 11:53 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: AS Assignment project - Creating a game in Greenfoot

    Sorry, I forgot to ask you to use code tags:
    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    One thing I see missing if anyone wanted to copy, compile, execute and test the code, is there are no import statements.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: AS Assignment project - Creating a game in Greenfoot

    Quote Originally Posted by Norm View Post
    Sorry, I forgot to ask you to use code tags:
    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    One thing I see missing if anyone wanted to copy, compile, execute and test the code, is there are no import statements.
    edited by helloworld922: see above post for formatted code
    Last edited by helloworld922; April 5th, 2012 at 11:56 AM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: AS Assignment project - Creating a game in Greenfoot

    I wonder what happened with your code tags. I expected to see this:
    <YOUR CODE HERE>

    I did put up the top import
    You must have used invisible ink.
    Last edited by Norm; April 5th, 2012 at 11:43 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: AS Assignment project - Creating a game in Greenfoot

    [QUOTE=Norm;62889]I wonder what happened with your code tags. I expected to see this:
    <import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
     
    /**
     * Write a description of class ShipGameWorld here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class ShipGameWorld extends World
    {
        private int score = 0;
        private Counter counter;
     
         public ShipGameWorld()
        {
            super(600, 400, 1);
            prepare();
        }
     
        public void increaseScore()
        {
            score = score + 50;
        }
     
        public void decreaseScore()
        {
            score = score - 1;
        }
     
        public int getScore()
        {
            return score;
        }
     
        /**
         * Prepare the world for the start of the program. That is: create the initial
         * objects and add them to the world.
         */
        private void prepare()
        {
            Ship ship = new Ship(counter);
            addObject(ship, 283, 264);
            ship.setLocation(228, 165);
            ship.setLocation(326, 175);
            Binary0 binary0 = new Binary0(counter);
            addObject(binary0, 99, 274);
            Binary0 binary02 = new Binary0(counter);
            addObject(binary02, 464, 303);
            Binary1 binary1 = new Binary1();
            addObject(binary1, 368, 286);
            Binary0 binary03 = new Binary0(counter);
            addObject(binary03, 481, 83);
            Binary1 binary12 = new Binary1();
            addObject(binary12, 182, 79);
            Binary0 binary04 = new Binary0(counter);
            addObject(binary04, 194, 335);
            Submarine submarine = new Submarine();
            addObject(submarine, 199, 282);
            Counter counter = new Counter();
            addObject(counter, 41, 373);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            counter.setLocation(31, 376);
            Counter counter2 = new Counter();
            addObject(counter2, 25, 383);
            removeObject(counter2);
            increaseScore();
            decreaseScore();
            getScore();
            Counter counter3 = new Counter();
            addObject(counter3, 515, 364);
            counter3.setLocation(114, 375);
            Counter counter4 = new Counter();
            addObject(counter4, 66, 338);
            counter4.Score();
            counter4.setLocation(120, 334);
            removeObject(counter);
            removeObject(counter3);
            counter4.setLocation(112, 376);
            counter4.setLocation(114, 371);
            getScore();
            decreaseScore();
        }
    }
     
     
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
     
    /**
     * Write a description of class Ship here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Ship extends Actor
    {
       private int score = 0;
       private Counter counter;
     
       public Ship(Counter pointCounter)
       {
           counter = pointCounter;
        }
     
        /**
         * Act - do whatever the Ship wants to do. This method is called whenever
         * the 'Act' or 'Run' button gets pressed in the environment.
         */
        public void act() 
        {
            move(10);
     
        if (Greenfoot.isKeyDown("up"))
            {
                move(10);
        }
        if (Greenfoot.isKeyDown("down"))
        {
              move(-10);
        }    
        if (Greenfoot.isKeyDown("right"))
        {
            turn(10);
        }
       if (Greenfoot.isKeyDown("left"))
       {
           turn(-10);
        }
        if (Greenfoot.isKeyDown("q"))
        {
            turn(180);
        }
        Actor binary1 = getOneIntersectingObject(Binary1.class);
        if (binary1 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary1.setLocation(xCoord, yCoord);
            shipWorld.increaseScore();
            Greenfoot.playSound("kaboom.wav");
    }
       Actor binary0 = getOneIntersectingObject(Binary0.class);
       if (binary0 !=null)
       {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary0.setLocation(xCoord, yCoord);
            shipWorld.increaseScore();
            Greenfoot.playSound("kaboom.wav");
    }
        Actor submarine = getOneIntersectingObject(Submarine.class);
    if (submarine != null)
     {
        // we have hit a sub so we get access to the
        // world using the getWorld() method and then
        // use the removeObject method to remove the 
        // ship from the game.
        World shipWorld = getWorld();
        shipWorld.removeObject(this);
        Greenfoot.playSound("kaboom.wav");
       }
      }
    }
     
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
     
    /**
     * Write a description of class Binary0 here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Binary0 extends Actor
    {
        private int score = 0;
        private Counter counter;
     
        public Binary0(Counter pointCounter)
        {
            counter = pointCounter;
        }
     
        public void act()
        {
            binary0();
        }
     
        public void binary0()
        {
        Actor binary0 = getOneIntersectingObject(Binary0.class);
        if (binary0 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary0.setLocation(xCoord, yCoord);
            shipWorld.increaseScore();
            Greenfoot.playSound("kaboom.wav");
        }
        }
    }
     
     
     
     
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
     
    /**
     * Write a description of class Submarine here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Submarine extends Actor
    {
        private int score = 0;
        /**
            * Act - do whatever the Sub wants to do. This method is called whenever
            * the 'Act' or 'Run' button gets pressed in the environment.
            */
           public void act()
           {
            move(10);
            binary0();
            binary1();
            int xCoord = getX();
            if(xCoord <=0 || xCoord >=599)
            {
                int random = Greenfoot.getRandomNumber(41);
                turn(35 + random);
            }
            int yCoord = getY();
            if(yCoord <=0 || yCoord >=399)
            {
                int random = Greenfoot.getRandomNumber(41);
                turn(35 + random);
            }
        }
     
        public void binary0()
        {
          Actor binary0 = getOneIntersectingObject(Binary0.class);
        if (binary0 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary0.setLocation(xCoord, yCoord);
            shipWorld.decreaseScore();
            Greenfoot.playSound("kaboom.wav");
        }
    }
     
    public void binary1()
    {
      Actor binary1 = getOneIntersectingObject(Binary1.class);
        if (binary1 !=null)
        {
            ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
            int xCoord = Greenfoot.getRandomNumber(600);
            int yCoord = Greenfoot.getRandomNumber(400);
            binary1.setLocation(xCoord, yCoord);
            shipWorld.decreaseScore();
            Greenfoot.playSound("kaboom.wav");
        }
      }
    }
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
    import java.awt.Color;
    /**
     * This counter class adds or subtracts the value of points 
     * from the current points value.
     * @author (Ryan Fagan)
     * @version (1.0)
     */
    public class Counter extends Actor
    {
       private int score = 0;
       private Counter counter;
       public void Score()
       {
           setImage(new GreenfootImage(200, 30));
           subtract();
           add();
           update();
        }
     
        public void add()
        {
            score++;
            update();
       }
     
       public void subtract()
       {
           score--;
           update();
        }
     
       public void update()
       {
           GreenfootImage img = getImage();
           img.clear();
           img.setColor(Color.WHITE);
           img.drawString("Score:  "  + score, 4, 20);
        }
    }
     
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
     
    /**
     * Write a description of class Binary1 here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Binary1 extends Actor
    {
      public int score = 0;
        /**
         * Act - do whatever the Binary1 wants to do. This method is called whenever
         * the 'Act' or 'Run' button gets pressed in the environment.
         */
        public void act() 
        {
            Actor ship = getOneIntersectingObject(Ship.class);
            if (ship !=null)
             {
                ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
                int xCoord = Greenfoot.getRandomNumber(600);
                int yCoord = Greenfoot.getRandomNumber(400);
                ship.setLocation(xCoord, yCoord);
                shipWorld.increaseScore();
                Greenfoot.playSound("kaboom.wav");
            }
            Actor submarine = getOneIntersectingObject(Submarine.class);
            if (submarine !=null)
            {
                ShipGameWorld shipWorld = (ShipGameWorld)getWorld();
                int xCoord = Greenfoot.getRandomNumber(600);
                int yCoord = Greenfoot.getRandomNumber(400);
                submarine.setLocation(xCoord, yCoord);
                shipWorld.decreaseScore();
                Greenfoot.playSound("kaboom.wav");
        }   
     }
    }>

Similar Threads

  1. Help with assignment about a board game (enum and array question)
    By Kranti1992 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 12th, 2012, 07:47 AM
  2. Creating a Sudoku Program Assignment
    By xion0374 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 17th, 2012, 07:48 PM
  3. guessing game assignment
    By scottey313 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 22nd, 2011, 07:52 PM
  4. Dice game code creating help!
    By kodols in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 22nd, 2011, 07:01 PM
  5. help with board game assignment
    By pjay in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 19th, 2011, 12:58 PM