Results 1 to 2 of 2
  1. #1
    liveurlife007 is offline Member
    Join Date
    Feb 2014
    Location
    Manchester
    Posts
    4
    Rep Power
    0

    Default Help needed to place food to my snake game.

    Hello guys ..I'm doing my lab work but I'm having trouble while adding food to my game. I have finished part A and B.
    I have this method to help me but don't know how to use it. I have to use setFood() method..
    x = (int) (Math.random() * n);
    y = (int) (Math.random() * n);

    Here is my code

    public class Game
    {

    // ----------------------------------------------------------------------
    // Part a: the score message

    private String scoreName;

    public String getScoreMessage()
    {
    return "A message";
    } // getScoreMessage


    public void setScoreMessage(String message)
    {
    scoreName = message;
    } // setScoreMessage


    public String getAuthor()
    {
    return "Mr John";
    } // getAuthor


    // ----------------------------------------------------------------------
    // Part b: constructor and grid accessors
    private final int gridSize;
    private final Cell [] [] gridArray;


    public Game(int requiredGridSize)
    {
    gridSize = requiredGridSize;gridArray = new Cell [gridSize] [gridSize];
    for (int i = 0; i < gridSize ; i ++ )
    for (int b = 0; b < gridSize; b ++ )
    gridArray [i] [b] = new Cell();

    } // Game


    public int getGridSize()
    {
    return gridSize;
    } // getGridSize


    public Cell getGridCell(int x, int y)
    {
    return gridArray [x] [y];
    } // getGridCell


    // ----------------------------------------------------------------------
    // Part c: initial game state

    // Part c-1: setInitialGameState method

    public void setInitialGameState(int requiredTailX, int requiredTailY,
    int requiredLength, int requiredDirection)
    {
    for (int i = 0; i < gridSize; i++)
    for (int b = 0; b < gridSize; b++)
    gridArray[i][b].setClear();

    } // setInitialGameState


    // ----------------------------------------------------------------------
    // Part c-2 place food

  2. #2
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    3

    Default Re: Help needed to place food to my snake game.

    well from what I see you have a grid and the random numbers are picked to place the food randomly on the grid. Also when position code please use the code tags. Just click on the hashtag looking buttons
    With the right know how, anything is possible

Similar Threads

  1. Help needed to add food to my Snake game.
    By liveurlife007 in forum New To Java
    Replies: 4
    Last Post: 02-02-2014, 11:38 PM
  2. Snake game
    By surbhijain93 in forum New To Java
    Replies: 18
    Last Post: 11-07-2013, 02:13 PM
  3. Help needed with simple Java Snake game
    By AndySun94 in forum New To Java
    Replies: 1
    Last Post: 04-01-2012, 06:59 AM
  4. Snake Game
    By LuluMM in forum New To Java
    Replies: 0
    Last Post: 03-08-2012, 06:48 AM
  5. Stand O' Food Game Proyect
    By piachens in forum New To Java
    Replies: 1
    Last Post: 03-24-2008, 05:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •