#Snake Game Not Working

1 messages · Page 1 of 1 (latest)

drowsy rune
jovial saffronBOT
#

<@&987246883653156906> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

I'm sorry, but as an AI language model, I cannot directly access or review code on external platforms like GitHub. However, I can provide you with some general tips to review and debug your Snake Game in Java:

  1. Start by identifying the specific issue or error you are facing. Is the game not running at all? Are there any error messages or exceptions being thrown?

  2. Review the code and make sure all necessary dependencies and libraries are properly imported.

  3. Check if the game loop is implemented correctly. The game loop is responsible for updating the game state (snake movement, collision detection, etc.) and rendering it on the screen.

  4. Verify that user input is being correctly captured and processed to control the snake's movement.

  5. Ensure that collision detection is working properly, checking for collisions with walls, obstacles, or itself (if applicable).

  6. Debug any logic errors by using print statements or a debugger to track the flow of execution and variable values.

  7. Consider using a graphical library like JavaFX or Swing to create a visual interface for your game.

  8. Break down your code into smaller functions or methods to improve readability and maintainability.

  9. Test your code with different scenarios and inputs to ensure it handles edge cases correctly.

If you encounter any specific issues while reviewing your code, feel free to ask for help by providing relevant snippets of code along with a description of the problem you are facing.

drowsy rune
ember loom
#

In which way is it not working? It's easier for us to help if you share the specific thing that's not behaving as expected, and the relevant snippet.

drowsy rune
#

first of all its not moving i'e the 0 sometime stays in one place then sometime moves its not constant

#

i think its to do with the thread

drowsy rune
#
private void renderSnake(Snake snake) {
    for (Bit bit : snake.bits) {
      terminal.puts(Capability.cursor_address, bit.prevX, bit.prevY);
      System.out.print("A");
      terminal.flush();
      terminal.puts(Capability.cursor_address, bit.currX, bit.currY);
      System.out.print("O");
      terminal.flush();
    }
jovial saffronBOT
drowsy rune
jovial saffronBOT
#

The code you provided is incomplete, but based on what you've shared, it seems like you are trying to render the snake by printing "A" at the previous position of each bit.

To erase the snake bits, you need to clear the previous position before rendering the new position. One way to do this is by printing a space character (" ") at the previous position before rendering "A" at the new position.

Here's an updated version of the renderSnake method that includes erasing the previous position:

private void renderSnake(Snake snake) {
    for (Bit bit : snake.bits) {
        terminal.puts(Capability.cursor_address, bit.prevX, bit.prevY);
        System.out.print(" "); // Erase previous position
        terminal.puts(Capability.cursor_address, bit.x, bit.y);
        System.out.print("A"); // Render new position
    }
}

This code clears the previous position by printing a space character and then renders the new position by printing "A". Make sure to adjust it according to your specific requirements and terminal library.