I have decided to work on a console based snake game, I am doing this because I want to learn basic c# skills before move on to c# graphics programming.
I am able to move the snake from the center to the edge of the screen, it is just a start, but I am learning.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace snakegame
{
class Program
{
static void Main(string[] args)
{
const int board_size = 17;
char[,] board = new char[board_size, board_size];
int horizontal = 5, vertical = 8, count = 0;
for (int i = 0; i < board_size; i++)
{
for (int j = 0; j < board_size; j++)
{
board[i, j] = '.';
}
}
void draw_board()
{
for (int i = 0; i < board_size; i++)
{
for (int j = 0; j < board_size; j++)
{
Console.Write(board[i, j]);
}
Console.WriteLine();
}
}
while (count < 6)
{
board[vertical, horizontal] = '*';
board[vertical, horizontal + 1] = '*';
board[vertical, horizontal + 2] = '*';
board[vertical, horizontal + 3] = '*';
board[vertical, horizontal + 4] = '*';
board[vertical, horizontal + 5] = '*';
board[vertical, horizontal + 6] = '*';
draw_board();
horizontal++;
count++;
System.Threading.Thread.Sleep(1000);
Console.Clear();
}
}
}
}
I think it is better to use Timer instead of Sleep. I found this example in the Internet: