Esempio n. 1
0
        public TextOutput(TextOutputInfo info)
        {
            TopLeft           = info.TopLeft;
            m_backgroundColor = info.BackgroundColor;
            m_color           = info.Color;

            m_listMessages = new List <string>();
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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();
        }