public SnakeGame( BoardInfo boardInfo, SnakeInfo snakeInfo, AppleInfo appleInfo, TextOutputInfo textOutputInfo) { // --- support e.g. hearts Console.OutputEncoding = System.Text.Encoding.Unicode; m_listGameObjects = new List <IGameObject>(); m_userInput = new UserInputComponent(); m_soundComponent = new SoundComponent(); m_storageBestResult = new BestResultStorage(Constants.BEST_RESULTS_FILE); m_snakeInfo = snakeInfo; //readonly m_appleInfo = appleInfo; //readonly m_textOutputInfo = textOutputInfo; //readonly m_boardInfo = boardInfo; }
public Snake(SnakeInfo info) { m_listSnakeItems = new List <SnakeItem>(); m_listSnakeItems.Add(new SnakeItem { Current = info.SnakeHead, WasNeverDraw = true }); for (int i = 0; i < Constants.INITIAL_SNAKE_BODY_COUNT; i++) { m_listSnakeItems.Add(new SnakeItem { // add to the left Current = getPossiblePointOnDirection(Direction.Right), WasNeverDraw = true }); } //Head = m_listSnakeItems[0].Current; m_colorHead = info.ColorHead; m_colorTail = info.ColorTail; CurrentUpdatePeriodSec = m_OriginalUpdatePeriodSec = info.UpdatePeriodSec; Stop = false; }
static void Main(string[] args) { Console.CursorVisible = false; Console.Title = "Snake game by Nathan Krasney 2019 . version : " + UtilsGeneric.Utils.GetAssemblyFileVersion(); int nBoardOffset = 2; ConsoleColor bacgroundColor = ConsoleColor.Black; Console.SetWindowSize( Constants.BOARD_WIDTH + 2 * nBoardOffset, Constants.BOARD_HEIGHT + 2 * nBoardOffset); BoardInfo boardInfo = new BoardInfo { BoardTopLeft = new Point { x = nBoardOffset, y = nBoardOffset }, BoardBottomRight = new Point { x = nBoardOffset + Constants.BOARD_WIDTH - 1, y = nBoardOffset + Constants.BOARD_HEIGHT - 1 }, ColorBorder = new ColorChar( '■', ConsoleColor.Blue, bacgroundColor) }; SnakeInfo snakeInfo = new SnakeInfo { SnakeHead = new Point { x = (boardInfo.BoardTopLeft.x + boardInfo.BoardBottomRight.x) / 2, y = (boardInfo.BoardTopLeft.y + boardInfo.BoardBottomRight.y) / 2 }, ColorHead = new ColorChar( 'Q', ConsoleColor.Red, bacgroundColor), ColorTail = new ColorChar( 'o', ConsoleColor.Green, bacgroundColor), UpdatePeriodSec = 0.1f }; AppleInfo appleInfo = new AppleInfo { ColorHead = new ColorChar( '@', ConsoleColor.Cyan, bacgroundColor), Head = new Point { x = (snakeInfo.SnakeHead.x + boardInfo.BoardBottomRight.x) / 2, y = snakeInfo.SnakeHead.y } }; TextOutputInfo textOutputInfo = new TextOutputInfo { TopLeft = new Point { x = boardInfo.BoardTopLeft.x + nBoardOffset, y = boardInfo.BoardTopLeft.y - nBoardOffset }, Color = ConsoleColor.Red, BackgroundColor = bacgroundColor }; SnakeGame game = new SnakeGame( boardInfo, snakeInfo, appleInfo, textOutputInfo); game.Run(); Console.ReadLine(); }