User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,646 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,431 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:

C / C++ FAQ's and Practice problems

Join Date: Jun 2008
Location: WA, USA
Posts: 647
Reputation: Alex Edwards has a spectacular aura about Alex Edwards has a spectacular aura about 
Rep Power: 3
Solved Threads: 54
Alex Edwards Alex Edwards is offline Offline
Practically a Master Poster

Re: C / C++ FAQ's and Practice problems

  #16  
Jul 22nd, 2008
Here's a toughy.

Write the Snaker program, using either a JFrame, GraphicsProgram or a JApplet (any GUI of your choice really).

Your snaker object will start off as one circle. That circle represents a head.

The body grows by encountering "snake-food" on the screen. When the head runs over the snake-food, the snake-food is consumed and a body-part is appended to the end of the snaker.

The snaker is moved by the keyboard, and can only move in the up, down, left and right directions. It has a static speed and the body parts always follow the same path as the one before it (except for the head). The snaker starts off without motion, then gains moment (permanently) after the first key is pressed.

In addition, there is no such thing as snap-movement. The snaker cannot move down if it is currently moving up, left if it is moving right... etc. This should be self-explanatory.

Also, the body cannot move immediately. In order to specify a new direction, the snaker must first clear the radius (or length) of the body-part before it in order to move forward.

Whatever part of the Snaker appears off of the screen on one side of the pane must appear on the other side.

Points are calculated when the Snaker consumes food and as time goes on.

The game is over if the Snaker runs into itself.

Your Snaker must consist of a LinkedList, and a Thread. Also implement a timer that tracks the time elapsed in the game.

Your Snaker must also implement the Serializable or Externalizable interfaces to save the current locations of the body parts, the direction of the head, and the score if the player decides to exit. Your Snaker GUI will need to implement a WindowListener that listens for things such as loss of focus (where the game should pause) and the window close operation (where the window will automatically save the game to a random object-file (that is not already named in the current directory) then exit once it is called).

Edit: Wow I'm very sorry! I thought this was for Java and not C++ O_O

Ok instead of a JFrame it can be a Win32 project. >_>
Last edited by Alex Edwards : Jul 22nd, 2008 at 3:06 pm.
Reply With Quote  
All times are GMT -4. The time now is 11:02 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC