How to Implement the Snake Game Using Struct and Constants in C++?

  • Context: C/C++ 
  • Thread starter Thread starter FallArk
  • Start date Start date
  • Tags Tags
    Game
Click For Summary

Discussion Overview

The discussion revolves around implementing the Snake Game in C++ using structures and constants. Participants are focused on understanding the game mechanics, struct usage, and function implementation, including how to manage player movements and game state without using global variables.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants seek clarification on the purpose of the move variable, initially thinking it represented moves left for the player.
  • There is a discussion on how to utilize the TAILLENGTH constant to limit the snake's growth and manage tail removal after reaching this length.
  • Participants express confusion regarding the use of the _cell struct, particularly how to access its members correctly within a 2D array.
  • One participant suggests that user input for direction should be handled in the movePlayer function rather than in showBoard, emphasizing that showBoard should only display the game state.
  • There are suggestions on how to implement the movePlayer function to read user input and update the game state accordingly.

Areas of Agreement / Disagreement

Participants generally agree on the need to clarify the use of the move variable and the struct, but there are differing opinions on the best way to implement user input and manage the game state. The discussion remains unresolved regarding the specific implementation details.

Contextual Notes

There are limitations in the current code regarding the proper initialization of the board and the handling of user input. Participants have not reached a consensus on the best approach to manage the snake's movement and tail length within the game logic.

  • #31
manveenkaur said:
So did you not figure out something?
Nope.
 
Technology news on Phys.org
  • #32
How did u guys deal with the tail?
 
  • #33
I am still not able to get a solution. I'll really appreciate it if someone could help me. M problem is that my opponent does not move. Please help!
 
  • #34
manveenkaur said:
I am still not able to get a solution. I'll really appreciate it if someone could help me. M problem is that my opponent does not move. Please help!

It appears that you are using an underscore '_' instead of a regular minus sign '-'. When you make the changes the code should work!
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
1
Views
4K
  • · Replies 11 ·
Replies
11
Views
10K
  • · Replies 1 ·
Replies
1
Views
2K