ASCII Snake
NOTES
It was pointed out to me that we already have had at least 2 snake challenges before. However, seeing as they are from a couple years ago, I think another snake challenge would be nice. Below (from the description section to the end) I describe a "classic" snake challenge.
However, I want to differentiate this from the classic challenge. I am more than open to suggestions in the comments below. My idea is the following:
Make an "infinite" snake game. That is, every 10 points, the level changes and the snake is reset according to the following pattern:
--The nth level contains n obstacles in the form of the '#' character. These work the same as walls. They are randomly placed around the map, the difficulty is that they cannot create a situation where an ungettable 'x' exists. for example:
------------------------------
| # | 11
| |
| oooooo |
| o o |
| o v |
| o |
| |
| |
| x |
| |
------------------------------
would be unacceptable because if an "x" were to spawn in the corner, it would be an automatic game over. Also, the barriers may not form a wall which closes off areas of the arena.
I can flesh out this idea more if you think it is any good.
Please Give Me Feedback On This Question
When I have a working question, I will begin work on a basic solution in C++.
Description
The goal of this challenge is to create a real time (non-buffered input) ASCII version of the popular game Snake .
The board is 10 newlines by 32 spaces.
The boundary consists of the " | " and " - " characters.
The snake body is made of the "o" character.
The snake head is v,<,>,^ depending on direction of travel (intuitively)
The snake eats " x ".
For example a game board might look like:
------------------------------
| | 11
| |
| oooooo |
| o o |
| o v |
| o |
| |
| |
| x |
| |
------------------------------
In the new game, the snake has three body segments and a head. It gains one body segment every time it eats an "x".
The score (the number of segments+head) should be displayed somewhere on the screen.
The starting position of the snake and the starting position of the "x" is left to the writer.
After an "x" is eaten, the snake gains a segment, and a new "x" must spawn. "x"s may not spawn in a set of predetermined coordinates. They must spawn "pseudo-randomly" in the loosest sense of the phrase. This means that they can spawn using a random number generator or their position may be simply a function of the snake's position or some such simple rule.
The snake moves according to nonbuffered user input according to one or both of the following layouts:
"W" - change direction up.
"A" - change direction left.
"D" - change direction right.
"S" - change direction down.
AND/OR
"UP" - change direction up.
"DOWN" - change direction left.
"LEFT" - change direction right.
"RIGHT" - change direction down.
Note that, as per the rules of snake, at a given instance of the game, only three options are available to the player:
-- Do nothing (and continue moving straight)
-- Turn 90 degrees
-- Turn -90 degrees
Therefore, at a given instance, two of the movement buttons should be unresponsive. E.g. in the above case, only right and left are responsive.
Snake movement follows the normal pattern. For those of you not familiar with it: Let segment zero, $$s_0$$ be the head and segment $$s_n$$ be the very end of the snake. In a given frame, the snake has 3 choices, go straight, go left, or go right (from the snake's reference frame). $$s_0$$ moves into one of these spaces based on user input. Then $$s_i$$ moves into the space taken by $$s_{i-1}$$ on the previous frame.
If an "x" is eaten, then on the next frame the new segment $$s_{n+1}$$ is placed where $$s_n$$ was on the previous frame.
The game ends when the snake head collides with the snake body or a with a wall.
Rules
1) Only languages which are available for free may be used. Libraries may be used (for i/o, etc), however the actual snake program must be written by you. (if library overuse is an issue, it will be determined by up/down votes)
2) The game must be playable (i.e. the framerate must be acceptable on most machines, as determined by readers)
3) The winner is the program using the smallest number of bytes that fits the above description.
4) If an online compiler is available, it is recommended that you link it with your code so that others may play your game.
ascii-artcodegolf