private void Restart() { canvas = new Canvas(colorCanvasToRestart, graphics.ClientWidth, graphics.ClientHeight); canvas.Render(graphics); graphics.DrawString("Игра окончена", "Arial", colorTextToRestart1, graphics.ClientWidth - graphics.ClientWidth, graphics.ClientHeight - graphics.ClientHeight, 25); graphics.DrawString($"Ваш счёт : {currentScore}", "Arial", colorTextToRestart2, graphics.ClientWidth - graphics.ClientWidth, graphics.ClientHeight - graphics.ClientHeight + 40, 25); graphics.DrawString($"Ваш лучший счёт : {maxScore}", "Arial", colorTextToRestart2, graphics.ClientWidth - graphics.ClientWidth, graphics.ClientHeight - graphics.ClientHeight + 80, 25); graphics.DrawString("Нажмите Y для рестарта или N для выхода", "Arial", colorTextToRestart2, graphics.ClientWidth - graphics.ClientWidth, graphics.ClientHeight - graphics.ClientHeight + 120, 20); graphics.FlipPages(); bool temp = true; do { if (Input.IsKeyDown(Keys.KEY_Y)) { ClearGameObject(); NewSnake(); Start(); temp = false; } else if (Input.IsKeyDown(Keys.KEY_N)) { temp = false; } }while (temp); }
public void Start() { while (true)// Game Loop { foreach (var obj in objects) { obj.Update(this); } foreach (var obj in delObjects) { objects.Remove(obj); } objects.AddRange(tempObjects); tempObjects.Clear(); delObjects.Clear(); result = IsGameOver(); if (result != 0) { break; } Thread.Sleep(10); // clearing screen before painting new frame graphics.FillRectangle(0xFF00FF00, 0, 0, graphics.ClientWidth, graphics.ClientHeight); //painting new frame foreach (var obj in objects) { obj.Render(graphics); } // double buffering technique is used graphics.FlipPages(); } if (result == 1) { graphics.DrawString("G A M E O V E R", "Arial", 0xFF000080, 500, 400, 30); } if (result == 2) { graphics.DrawString("W I N", "Arial", 0xFF000080, 600, 400, 30); } // double buffering technique is used graphics.FlipPages(); Console.ReadKey(); }
public void ShowMessage(string str, int indent) { while (!Input.IsKeyDown(Keys.ESCAPE)) { _graphics.FillRectangle(0xff000000, indent, _lineHeight, _graphics.ClientWidth / 2, _graphics.ClientHeight - _lineHeight * 2); _graphics.DrawString($"{str}", "Arial", 0xffffffff, indent, _lineHeight, 12); _graphics.DrawString("Press Escape to Exit...", "Arial", 0xffffffff, indent, _graphics.ClientHeight / 2, 10); _graphics.FlipPages(); Thread.Sleep(100); } }
static void Main(string[] args) { Console.WindowWidth = 60; Console.WindowHeight = 30; Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight); Console.BackgroundColor = ConsoleColor.Black; Console.CursorVisible = false; Console.Clear(); ConsoleGraphics graphics = new ConsoleGraphics(); GameScore game = new GameScore(); bool restart = false; while (true) { if (game.GameIsOn) { StartGame(graphics, game); } if (!restart) { Restart(graphics, game); if (Input.IsKeyDown(Keys.SPACE)) { restart = true; game.GameIsOn = true; } } graphics.FlipPages(); Thread.Sleep(80); } }
public static void ShowHighscore(ConsoleGraphics graphics) { graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight); Button Back = new Button("Back", 0, 0, 120, 20, 0xFFFF00FF, graphics); Back.AddToBoard(graphics); graphics.DrawString("Name", "Arial", 0xFFFF00FF, 15, 20); graphics.DrawString("Score", "Arial", 0xFFFF00FF, 120, 20); string[] lines = System.IO.File.ReadAllLines("Highscore.txt"); for (int i = 0; i < lines.Length; i++) { string[] result = lines[i].Split(';'); graphics.DrawString(result[0], "Arial", 0xFFFF00FF, 15, 20 * (i + 2)); graphics.DrawString(result[1], "Arial", 0xFFFF00FF, 120, 20 * (i + 2)); } graphics.FlipPages(); while (true) { if (Input.IsMouseLeftButtonDown) { if (Back.IsCollision(Input.MouseX, Input.MouseY)) { return; break; } } } }
public void PlayGame() { while (true) { ConsoleGraphics graphics = new ConsoleGraphics(); Console.CursorVisible = false; Button start = new Button(graphics, 0, 0, 200, 50, graphics.ClientWidth / 2 - 100, graphics.ClientHeight / 2 - 150); Button exit = new Button(graphics, 200, 270, 190, 50, graphics.ClientWidth / 2 - 95, graphics.ClientHeight / 2); while (!exit.Push()) { start.Render(graphics); exit.Render(graphics); if (start.Push() == true || exit.Push() == true) { break; } graphics.FlipPages(); System.Threading.Thread.Sleep(10); } if (exit.Push() == true) { break; } Level level = new Level(); level.Level_1(graphics); } }
static void Main(string[] args) { Console.SetWindowPosition(0, 0); Console.WindowHeight = 34; Console.WindowWidth = 48; Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight); Console.BackgroundColor = ConsoleColor.White; Console.CursorVisible = false; Console.Clear(); ConsoleGraphics graphics = new ConsoleGraphics(); //Console.WriteLine(graphics.ClientHeight); //Console.WriteLine(graphics.ClientWidth); GameEngine engine = new TetrisGameEngine(graphics); Field Field = new Field(graphics); Field.FillField(graphics); engine.Start(Field, engine); graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight); graphics.FlipPages(); Console.WriteLine("game is over"); Console.ReadLine(); Console.WriteLine("Play again? "); Console.WriteLine(" if yes press any key"); Console.WriteLine("if no press escape"); var key = Console.ReadKey(); if (key.Key != ConsoleKey.Escape) { Main(null); } }
public void Start(Field Field, GameEngine Engine) { int indexObject = rnd.Next(0, objects.Count); bool gameState = true; while (gameState) { //foreach (var item in gameObject) //{ objects[indexObject].Update(Field, Engine); gameState = objects[indexObject].endGame; //} Field.ClearLine(); graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight); for (int i = 0; i < Field.Rectangles.GetLength(0); i++) { for (int j = 0; j < Field.Rectangles.GetLength(1); j++) { graphics.FillRectangle((uint)Field.Rectangles[i, j].Color, Field.Rectangles[i, j].x, Field.Rectangles[i, j].y, Field.size, Field.size); } } //foreach (var item in gameObject) //{ objects[indexObject].Render(graphics); //} graphics.FlipPages(); Thread.Sleep(25); } }
public void Start() { while (true) { //Game loop foreach (var obj in objects) { obj.Update(this); } objects.AddRange(tempObjects); tempObjects.Clear(); //Clearing screen before painting new frame graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight); foreach (var obj in objects) { obj.Render(graphics); } //double buffering technique is used graphics.FlipPages(); Thread.Sleep(100); } }
public static void Run() { while (true) { ConsoleGraphics graphics = new ConsoleGraphics(); GameEngine engine = new ArkanoidGameEngine(graphics); engine.Start(); graphics.DrawString("FOR NEW GAME PRESS SPASE\n FOR EXIT GAME PRESS ESC", "Arial", 0xFF000080, 460, 450, 20); graphics.DrawString("(FOR RESET BEST SCORS PRESS (R)", "Arial", 0xFF000080, 530, 550, 10); graphics.FlipPages(); while (Console.KeyAvailable) { Console.ReadKey(); } ConsoleKeyInfo keyInfo = Console.ReadKey(); ConsoleKey key = keyInfo.Key; if (key == ConsoleKey.Escape) { break; } if (key == ConsoleKey.R) { Scors.WriteInFileBestScors(0); Scors.SetBestScors(0); } } }
public virtual void Show(int indent) { for (int i = 0; i < directoryItems.Count; i++) { if (_selectedIndex == i) { directoryItems[i].TextSelection(_graphics, _selectedIndex, indent, LineHeight); directoryItems[i].Show(_graphics, _selectedIndex, indent, LineHeight); } else { directoryItems[i].Show(_graphics, i, indent, LineHeight); } } _graphics.FlipPages(); Thread.Sleep(100); }
static void Main(string[] args) { ConsoleGraphics g = new ConsoleGraphics(); Console.CursorVisible = false; while (true) { g.FillRectangle(0xFF00FF00, 10, 10, 40, 40); g.FlipPages(); } }
public void Start() { while (!Exit) { _graphics.FillRectangle(Settings.BlackColor, 0, 0, _graphics.ClientWidth, _graphics.ClientHeight); _hints.ShowHints(); _tabView.Show(); _graphics.FlipPages(); _userActionListener.ReadInput(); } }
public void ShowWindow(string titleText, string inputText, bool isDialogWindow, bool waitForClosing) { _graphics.FillRectangle(Settings.ActiveColor, Settings.MessageWindowCoordinateX, Settings.MessageWindowCoordinateY, Settings.MessageWindowWidth, Settings.MessageWindowHeiht); if (isDialogWindow) { _graphics.FillRectangle(0xFF0055de, Settings.MessageWindowCoordinateX + 10, Settings.MessageWindowCoordinateY + 40, Settings.MessageWindowWidth - 20, 30); } _graphics.DrawString(titleText, Settings.FontName, Settings.BlackColor, Settings.MessageWindowCoordinateX + 10, Settings.MessageWindowCoordinateY); _graphics.DrawString(inputText, Settings.FontName, Settings.BlackColor, Settings.MessageWindowCoordinateX + 10, Settings.MessageWindowCoordinateY + 40); _graphics.FlipPages(); while (waitForClosing) { if (Console.ReadKey(true).Key == ConsoleKey.Enter) { return; } } }
private void DrawTitileScreen() { bool proceed = false; while (!proceed) { canvas.Render(consoleGraphics); consoleGraphics.DrawString("TETЯIS", "Times New Roman", (uint)Colors.Yellow, 150, 80, 100); consoleGraphics.DrawString(" PRESS SPACE TO START", "Consolas", (uint)Colors.Yellow, 230, 650, 20); consoleGraphics.DrawString("LOGO BY FREEPNG.RU EDUCATIONAL PROJECT ©2019", "Consolas", (uint)Colors.Yellow, 225, 750, 10); ConsoleImage logo = consoleGraphics.LoadImage(@"logo.bmp"); consoleGraphics.DrawImage(logo, 255, 300); consoleGraphics.FlipPages(); if (Input.IsKeyDown(Keys.SPACE)) { proceed = true; } } Utility.SleepLong(); }
public bool Restart() { while (true) { _canvas.Render(_graphics); _graphics.DrawString("GAME OVER", "Arial", 0xFFbd1a1a, 100, 200, 30); _graphics.DrawString($"You have: {points} points", "Arial", 0xFFbd1a1a, 100, 250, 16); _graphics.DrawString($"Do you wont play again?\nPress Y(Yes)/N(No)", "Arial", 0xFFbd1a1a, 100, 270, 16); if (Input.IsKeyDown(Keys.KEY_N)) { return(false); } else if (Input.IsKeyDown(Keys.KEY_Y)) { return(true); } _graphics.FlipPages(); Thread.Sleep(30); } }
public void Start() { while (true) { foreach (var item in gameObj) { item.Update(this); } foreach (var item in gameObj) { item.Render(cg); } cg.FlipPages(); } }
public void Start() { while (true) { // Game Loop _curScene.Update(this); // clearing screen before painting new frame _graphics.FillRectangle(ResourcesManager.ColorResources.MenuBackgroundColor, 0, 0, _graphics.ClientWidth, _graphics.ClientHeight); _curScene.Render(_graphics); // double buffering technique is used _graphics.FlipPages(); Thread.Sleep(80); } }
public void Level_1(ConsoleGraphics graphics) { Field field = new Field(0xFFFFFF00, 0, 0, graphics.ClientWidth, graphics.ClientHeight); Bat bat = new Bat(graphics, 100, 600, 130, 30); Ball ball = new Ball(graphics, 20, 300, 20, 20); Target[] targets = new Target[20]; for (int i = 0; i < targets.Length; i++) { if (i % 2 == 0) { targets[i] = new Target(graphics, graphics.ClientWidth * (i + 1) / targets.Length - 32, 50, 32, 32); } else { targets[i] = new Target(graphics, graphics.ClientWidth * (i + 1) / targets.Length - 32, 25, 32, 32); } } while (ball.speedX != 0 && ball.count < targets.Length * 10) { field.RenderField(graphics); bat.Render(graphics); bat.UpdateBat(graphics); ball.Render(graphics); ball.ToBeatOfTheField(field); ball.ToBeatOfTheBat(bat); for (int i = 0; i < targets.Length; i++) { targets[i].Render(graphics); ball.ToBeatOfTheTargets(targets[i]); } graphics.FlipPages(); System.Threading.Thread.Sleep(10); } Console.Clear(); Console.WriteLine($"Your Score is {ball.count} points"); }
static void Main(string[] args) { Console.CursorVisible = false; ConsoleGraphics graphics = new ConsoleGraphics(); uint color = 0xFFFF0000; int xStart = 0; int xEnd = 100; int yStart = 0; int yEnd = 100; int thickness = 5; graphics.DrawLine(color, xStart, yStart, xEnd, yEnd, thickness); graphics.FlipPages(); Console.ReadLine(); }
static void Main(string[] args) { Console.CursorVisible = false; ConsoleGraphics cg = new ConsoleGraphics(); Canvas canvas = new Canvas(0xFFbdc1c9, cg.ClientWidth, cg.ClientWidth); Apple apple = new Apple(0xFF7f711, canvas); Head head = new Head(0xFFFF0000, 60, 0, canvas); while (true) { apple.Spawn(cg); head.Move(); canvas.Render(cg); head.Render(cg); cg.FlipPages(); Thread.Sleep(130); } }
public void ShowProperties(SystemItem item) { bool exit = false; while (!exit) { _graphics.FillRectangle(Settings.ActiveColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY, Settings.PropertiesWidth, Settings.PropertiesHeight); _graphics.DrawString("Name:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY, Settings.FontSize); _graphics.DrawString(item.Name, Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY, Settings.FontSize); _graphics.DrawString("Parent directory:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + Settings.FontSize + 1, Settings.FontSize); _graphics.DrawString(item.ParentDirectory, Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + Settings.FontSize + 1, Settings.FontSize); _graphics.DrawString("Root directory:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 2) + 1, Settings.FontSize); _graphics.DrawString(item.Root, Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 2) + 1, Settings.FontSize); _graphics.DrawString("Last read time:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 3) + 1, Settings.FontSize); _graphics.DrawString($"{item.LastAccessTime}", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 3) + 1, Settings.FontSize); _graphics.DrawString("Last write time:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 4) + 1, Settings.FontSize); _graphics.DrawString($"{item.LastWriteTime}", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 4) + 1, Settings.FontSize); _graphics.DrawString("Size:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 5) + 1, Settings.FontSize); _graphics.DrawString(item.Size.ToViewableSize(), Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 5) + 1, Settings.FontSize); if (item is FileItem file) { _graphics.DrawString("Is read only:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 6) + 1, Settings.FontSize); _graphics.DrawString($"{file.IsReadOnly}", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 6) + 1, Settings.FontSize); } if (item is FolderItem folder) { _graphics.DrawString("Files:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 6) + 1, Settings.FontSize); _graphics.DrawString($"{folder.CountFiles}", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 6) + 1, Settings.FontSize); _graphics.DrawString("Folders:", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 7) + 1, Settings.FontSize); _graphics.DrawString($"{folder.CountFolders}", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX + Settings.PropertiesInfoCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 7) + 1, Settings.FontSize); } _graphics.DrawString("Press Enter to continue :", Settings.FontName, Settings.BlackColor, Settings.PropertiesCoordinateX, Settings.PropertiesCoordinateY + (Settings.FontSize * 9) + 1, Settings.FontSize + 3); _graphics.FlipPages(); if (Console.ReadKey(true).Key == ConsoleKey.Enter) { exit = true; } } }
static void Main(string[] args) { ConsoleGraphics g = new ConsoleGraphics(); List <IUiComponent> components = new List <IUiComponent>(); var firstbutton = new Button(10, 10); var secondbutton = new Button(50, 50); components.Add(firstbutton); components.Add(secondbutton); firstbutton.ChangePosition += Firstbutton_ChangePosition; while (true) { foreach (var component in components) { component.Draw(g); } g.FlipPages(); } }
public static bool ContinueGame(ConsoleGraphics graphics, GameEngine engine) { var scoreCounter = engine.GetFirstObjectByType <ScoreCounter>(); graphics.DrawImagePart(graphics.LoadImage("Images/snake-gameover.jpg"), 0, 0, graphics.ClientWidth, graphics.ClientHeight, 0, 0); graphics.DrawString($"Current score:{scoreCounter.Score}", Settings.FontName, Settings.WhiteColor, 320, 450, 36); graphics.DrawString($"Best score:{scoreCounter.BestScore}", Settings.FontName, Settings.WhiteColor, 350, 520, 36); graphics.FlipPages(); while (true) { if (Input.IsKeyDown(Keys.SPACE)) { return(true); } if (Input.IsKeyDown(Keys.ESCAPE)) { return(false); } } }
static void Main(string[] args) { Console.CursorVisible = false; ConsoleGraphics graphics = new ConsoleGraphics(); Field field = new Field(); Cross cross = new Cross(); while (true) { graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight); graphics.DrawString("0", "Arial", 0xFF00FFFF, 200, 500, 50); field.Render(graphics); if (Input.IsMouseLeftButtonDown) { cross.Render(graphics); } graphics.FlipPages(); //Thread.Sleep(50); } }
static void Main(string[] args) { Console.CursorVisible = false; ConsoleGraphics graphics = new ConsoleGraphics(); Rectangle r = new Rectangle(0xFFFF0000, 0, graphics.ClientHeight, 100, 100); while (true) { graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight); //y = graphics.ClientHeight; //x = graphics.ClientWidth; r.Update(graphics); r.Render(graphics); graphics.FlipPages(); Thread.Sleep(10); } }
public static void MainMenu(ConsoleGraphics graphics) { while (updateMenu) { graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight); Button Start = new Button("Start Game", 130, 150, 120, 20, 0xFFFFFF00, graphics); Button Score = new Button("High Score", 130, 200, 120, 20, 0xFFFFFF00, graphics); Button Exit = new Button("Exit", 130, 250, 120, 20, 0xFFFFFF00, graphics); Start.AddToBoard(graphics); Score.AddToBoard(graphics); Exit.AddToBoard(graphics); graphics.FlipPages(); while (true) { if (Input.IsMouseLeftButtonDown) { if (Start.IsCollision(Input.MouseX, Input.MouseY)) { StartGame(new ConsoleGraphics()); updateMenu = false; break; } if (Score.IsCollision(Input.MouseX, Input.MouseY)) { ShowHighscore(graphics); break; } if (Exit.IsCollision(Input.MouseX, Input.MouseY)) { Environment.Exit(0); break; } } } } }
public static void Greeting(ConsoleGraphics graphics) { graphics.DrawImagePart(graphics.LoadImage("Images/snake-start.jpg"), 0, 0, graphics.ClientWidth, graphics.ClientHeight, 0, 0); graphics.FlipPages(); Console.ReadLine(); }
static void Main(string[] args) { //Сделать что бы треугольник двигался управляются с клавиатуры стрелочками //Квадрат двигался по кругу //Кошка и звезда двигались по прямоугольной траэктории. ConsoleGraphics graphics = new ConsoleGraphics(); // создается новый обьект Console.CursorVisible = false; // прячется курсор // graphics.DrawLine(0xFFFF0000, 0, 0, graphics.ClientWidth, graphics.ClientHeight, 5); // (цвет- RGB запись, координаты начала линии (x,y), координаты конца, ширина) // Console.ReadLine(); //Paint Rectagle // graphics.FillRectangle(0xFFFF0000, 50, 50, 100, 100); // Triangle Triangle s1 = new Triangle(graphics, 100, 100, 100); s1.DrawTriangle(); // Star Star s2 = new Star(graphics, 300, 100, 100); // s2.DrawTStar(); //Cat(from image) //ConsoleImage image = graphics.LoadImage("C:\\Users\\oksan\\Desktop\\Cards\\Cat.jpg"); // graphics.DrawImage(image, 500,200); /* * 1. Clear Screen! * 2. Update object * 3. Render again */ //while (true) //{ // // Clear Screen // graphics.FillRectangle(0xFF00FF00, 0, 0, graphics.ClientWidth, graphics.ClientHeight); // // Update object // s1.UpdateTriangle(); // // Draw again // s1.DrawTriangle(); //} ConsoleGraphics graphics1 = new ConsoleGraphics(); while (true) { // Clear Screen // Update object //draw graphics1.FlipPages(); // решает проблему моргания, последний метод отрисовки Thread.Sleep(10); } // Thread.Sleep(10); //притормозить использование //Square[] s = new Square[200]; //int y = 40; //int index = 0; //for (int z = 0; z < 8; z++) //{ // int x = 5; // for (int i = 0; i < 20; i++) // { // s[index] = new Square(graphics, x, y, 15); // s[index].DrawSuare(); // x += 30; // index++; // } // y += 50; //} // Square s1 = new Square(graphics, 10, 50, 50); //Square s2 = new Square(graphics, 110, 50, 50); //Square s3 = new Square(graphics, 210, 50, 50); //Square s4 = new Square(graphics, 310, 50, 50); //Square s5 = new Square(graphics, 410, 50, 50); //s1.DrawSuare(); //s2.DrawSuare(); //s3.DrawSuare(); //s4.DrawSuare(); //s5.DrawSuare(); }
public void Start() { snake.AddFirst(new SnakeChain(graphics)); Apple apple = new Apple(); apple.Update(this); // Game loop. while (true) { // Snake Loop int i = 0; foreach (var snakeChain in snake) { if (i == 0) { snakeChain.SetFirst(); } snakeChain.Update(this, snake); i++; } // clearing screen before painting new frame graphics.FillRectangle(0xFF000000, 0, 0, 655, 656); graphics.DrawRectangle(0xFFA9A9A9, 10, 10, 640, 640, 20); // FFA9A9A9-dark grey // Thus, we have a matrix 34x34 for a game. // But as we have a frame which has the same h/w as a snake - this reduces the playable zone to 32x32. int[] snakeHeadCoords = snake.First().GetCoords(); /// !!!!!!!!!!!!!!!!!!!!!!!!!! if ( (snakeHeadCoords[0] == 0 || snakeHeadCoords[0] >= 640) || (snakeHeadCoords[1] == 0 || snakeHeadCoords[1] >= 640) ) { GameOver("out-of-frame"); return; } // Let's paint the apple apple.Render(graphics); // Have we eaten an apple? if (IsAppleEaten(snake.First(), apple)) { applesEaten++; Console.WriteLine(" Apples eaten: " + applesEaten); SaveNextSnakeChain(); // Regenerate apple coords. apple.Update(this); } foreach (var snakeChain in snake) { snakeChain.Render(graphics); } // double buffering technique is used graphics.FlipPages(); Thread.Sleep(100); } }