Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public void Start()
        {
            while (true)
            {
                if (snakeF.GameOver)
                {
                    objects.RemoveAll(o => o is Part);
                    graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight);
                }
                // 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(70);
            }
        }
Ejemplo n.º 3
0
 void DrawStatArea(ConsoleGraphics graphics)
 {
     graphics.FillRectangle((uint)BorderColor, X, Y, TotalWidth, TotalHeight);          //Draw border
     graphics.FillRectangle((uint)Color.White, X + 4, Y + 4, StatWidth, StatHeight);    //Draw background
     graphics.DrawString("Score:", "", (uint)Color.Black, X + 5, Y + 10);
     graphics.DrawString($"{PlayingArea.Score}", "DS-Digital", (uint)Color.Black, X + 3, Y + 30, 30);
     graphics.DrawString("Last score:", "", (uint)Color.Black, X + 5, Y + 90);
     graphics.DrawString($"{PlayingArea.LastScore}", "DS-Digital", (uint)Color.Black, X + 3, Y + 110, 30);
     graphics.DrawString("HiScore:", "", (uint)Color.Red, X + 5, Y + 170);
     graphics.DrawString($"{PlayingArea.HiScore}", "DS-Digital", (uint)Color.Red, X + 3, Y + 190, 30);
 }
Ejemplo n.º 4
0
 void DrawPlayingArea(ConsoleGraphics graphics)
 {
     graphics.FillRectangle((uint)BorderColor, 0, 0, TotalWidth, TotalHeight);          //Draw border
     graphics.FillRectangle((uint)BackgroundColor, X, Y, PlayingWidth, PlayingHeight);  //Draw background
     for (int y = Y; y < PlayingHeight; y += Segment.CellSize)
     {
         for (int x = X; x < PlayingWidth; x += Segment.CellSize)
         {
             segment.Render(x, y, CellsColor, graphics);                                  //Draw background cells
         }
     }
 }
Ejemplo n.º 5
0
 private void BtnEsc_OnClick(object sender, ControlEventArg e)
 {
     File.WriteAllText("save.txt", currentLvl.LvlNum.ToString());
     isExit            = true;
     btnSpace.OnClick -= OnClick;
     btnEsc.OnClick   -= BtnEsc_OnClick;
     cg.FillRectangle(0xFF000000, 0, 0, 600, 600);
     foreach (Control cc in arrowBtns)
     {
         cc.OnClick -= OnClick;
     }
 }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        private void DrawDatails(string diskName)
        {
            _graphic.FillRectangle(0xff000000, Indent + 1, 0, (_graphic.ClientWidth / 2), _graphic.ClientHeight);

            _graphic.DrawString($"{diskName}", "Arial", 0xffffffff, Indent, 0, 12);
            _graphic.DrawString("F1-copy  :  F2-cut  :  F3-paste  :  F4-list of disks  :  F5-properties  :  F6-rename  :  F7-criate folder",
                                "Arial", 0xffffffff, 0, _graphic.ClientHeight - _actions.LineHeight, 10);

            _graphic.DrawLine(0xffffffff, _graphic.ClientWidth / 2, 0, _graphic.ClientWidth / 2, _graphic.ClientHeight - _actions.LineHeight);
            _graphic.DrawLine(0xffffffff, 0, _graphic.ClientHeight - _actions.LineHeight, _graphic.ClientWidth, _graphic.ClientHeight - _actions.LineHeight);
            _graphic.DrawLine(0xffffffff, 0, _actions.LineHeight - 1, _graphic.ClientWidth, _actions.LineHeight - 1);
        }
Ejemplo n.º 8
0
        private void LoadItem_Click()
        {
            int lvl = 10;

            cg.FillRectangle(0xFF000000, 0, 0, 200, 200);
            if (File.Exists("save.txt"))
            {
                lvl = int.Parse(File.ReadAllText("save.txt"));
            }
            if (lvl > 9 && lvl < 50)
            {
                Player ge = new Player(cg, lvl);
                ge.Start();
            }
        }
Ejemplo n.º 9
0
 public void Render(ConsoleGraphics graphics)
 {
     for (int i = 0; i < _cells.Length; i++)
     {
         graphics.FillRectangle(_cells[i].Color, _cells[i].X, _cells[i].Y, FieldSize.width, FieldSize.height);
     }
 }
Ejemplo n.º 10
0
 private static void Restart(ConsoleGraphics graphics, GameScore score)
 {
     graphics.FillRectangle(0xFFFFFFFF, 0, 0, graphics.ClientWidth, graphics.ClientHeight);
     graphics.DrawString("Game is over", "Arial", 0xFF000000, 150, 150);
     graphics.DrawString($"Your score: {score.Score.ToString()}", "Arial", 0xFF00FF00, 150, 170);
     graphics.DrawString("If you want to restart, press Space", "Arial", 0xFF000000, 150, 190);
 }
Ejemplo n.º 11
0
 public void Render(ConsoleGraphics graphics)
 {
     for (int i = 0; i < obj.Length; i++)
     {
         graphics.FillRectangle(obj[i].Color, obj[i].X, obj[i].Y, width, height);
     }
 }
Ejemplo n.º 12
0
        public override void OnPaint(PaintEventArgs e)
        {
            ConsoleGraphics g     = e.Graphics;
            var             items = _items;

            g.FillRectangle(ColorResources.ListViewBackgroundColor, Position.X, Position.Y, Size.Width, Size.Height);
            int lastIndex = _visibleItemsFirstIndex + _visibleItemsCount > items.Count ?
                            items.Count : _visibleItemsFirstIndex + _visibleItemsCount;

            for (int i = _visibleItemsFirstIndex; i < lastIndex; i++)
            {
                items[i].Draw(g,
                              new Point(_itemsStartPosition.X + NumericConstants.MarginUpLeft,
                                        _itemsStartPosition.Y + (i - _visibleItemsFirstIndex) *
                                        NumericConstants.ListViewItemHeight + NumericConstants.MarginUpLeft),
                              new Size(NumericConstants.ListViewItemHeight, Size.Width - NumericConstants.MarginRightDown));
            }
            g.DrawLine(ColorResources.AppBackground, Position.X, Position.Y + NumericConstants.ListViewItemHeight,
                       Position.X + Size.Width, Position.Y + NumericConstants.ListViewItemHeight,
                       NumericConstants.WindowBorderThikness);
            g.DrawLine(ColorResources.AppBackground, Position.X, Size.Height - NumericConstants.ListViewItemHeight,
                       Position.X + Size.Width, Size.Height - NumericConstants.ListViewItemHeight,
                       NumericConstants.WindowBorderThikness);

            g.DrawString(_drawingPath, StringResources.FontName, ColorResources.ListItemTextColor,
                         Position.X, Position.Y, NumericConstants.FontSize);
            g.DrawString($"{SelectedIndex + 1}/{this._items.Count}", StringResources.FontName, ColorResources.ListItemTextColor,
                         Position.X + 22, Size.Height - NumericConstants.ListViewItemHeight + 3, NumericConstants.FontSize);
        }
Ejemplo n.º 13
0
 public void Render(ConsoleGraphics graphics)
 {
     for (int i = 0; i < FieldSize.numberCellWidth; i++)
     {
         for (int j = 0; j < FieldSize.numberCellHeigh; j++)
         {
             if (fieldGrid[i, j] == 1)
             {
                 graphics.FillRectangle(ColorFigure.figureColor, FieldSize.width * i + FieldSize.xMin, FieldSize.height * j +
                                        FieldSize.yMin, FieldSize.width, FieldSize.height);
                 if (j == 0)
                 {
                     game.GameIsOn = false;
                 }
             }
         }
     }
     figure?.Render(graphics);
     for (int i = FieldSize.xMin; i <= FieldSize.xMax; i += FieldSize.width * 10)
     {
         graphics.DrawLine(ColorFigure.fieldColor, i, FieldSize.yMin, i, FieldSize.yMax, 3);
     }
     for (int i = FieldSize.yMin; i <= FieldSize.yMax; i += FieldSize.height * 20)
     {
         graphics.DrawLine(ColorFigure.fieldColor, FieldSize.xMin, i, FieldSize.xMax, i, 3);
     }
 }
Ejemplo n.º 14
0
 public void Render(ConsoleGraphics graphics)
 {
     foreach (SnakeSegment c in _snake)
     {
         graphics.FillRectangle(Settings.SnakeColor, c.X + 1, c.Y + 1, Settings.SizeCell - 1, Settings.SizeCell - 1);
     }
 }
Ejemplo n.º 15
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public void Start()
        {
            while (_game.GameIsOn)
            {
                // 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);
            }
        }
Ejemplo n.º 17
0
        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);
            }
        }
Ejemplo n.º 18
0
 public void Draw(ConsoleGraphics g)
 {
     if (Input.IsMouseLeftButtonDown)
     {
         ChangePosition?.Invoke(this);
     }
     g.FillRectangle(0xff00ff00, x, y, sizeW, sizeH);
 }
Ejemplo n.º 19
0
 public override void Draw(ConsoleGraphics g)
 {
     g.DrawRectangle(ColorResources.TextBoxBorderColor, _position.X, _position.Y, _size.Width, _size.Height,
                     NumericConstants.WindowBorderThikness);
     g.FillRectangle(ColorResources.TextBoxBackgroundColor, _position.X, _position.Y, _size.Width, _size.Height);
     g.DrawString(Text, StringResources.FontName, ColorResources.ListItemSelectedTextColor, _position.X,
                  _position.Y, NumericConstants.TextBoxFontSize);
 }
Ejemplo n.º 20
0
        public void Spawn(ConsoleGraphics cg)
        {
            Random random = new Random();

            _x = random.Next(10, _canvas.ClientWidth - 30);
            _y = random.Next(10, _canvas.ClientHeigth - 400);
            cg.FillRectangle(_color, _x, _y, size, size);
        }
Ejemplo n.º 21
0
 public override void Render(ConsoleGraphics graphics)
 {
     for (int i = 0; i < bigRectangl.GetLength(0); i++)
     {
         for (int j = 0; j < bigRectangl.GetLength(1); j++)
         {
             graphics.FillRectangle((uint)color, x + j * size, y + i * size, size, size);
         }
     }
 }
Ejemplo n.º 22
0
 public override void Render(ConsoleGraphics graphics)
 {
     graphics.FillRectangle(ResourcesManager.ColorResources.MainSceneBackgroundColor, 0, 0, _gameFieldSize.Width, _gameFieldSize.Height);
     foreach (var obj in _objects)
     {
         obj.Render(graphics);
     }
     _player.Render(graphics);
     _gui.Render(graphics);
 }
Ejemplo n.º 23
0
        //if (Field.Rectangles[y / size + 1, x / size].CelsValue != 1 && Field.Rectangles[y / size + 1, x / size + 1].CelsValue != 1)
        //{
        //    if (y != graphics.ClientHeight - size * 2 && Field.Rectangles[y / size + 2, x / size].CelsValue != 1 && Field.Rectangles[y / size + 2, x / size + 1].CelsValue != 1)
        //    {
        //        if (Input.IsKeyDown(Keys.LEFT))
        //        {
        //            if (x > 0 && Field.Rectangles[y / size, x / size - 1].CelsValue == 0 && Field.Rectangles[y / size + 1, x / size - 1].CelsValue == 0) x -= size;
        //        }
        //        else if (Input.IsKeyDown(Keys.RIGHT))
        //        {
        //            if (x < graphics.ClientWidth - size * 2 - 5 && Field.Rectangles[y / size, x / size + 2].CelsValue == 0 &&
        //                Field.Rectangles[y / size + 1, x / size + 2].CelsValue == 0) x += size;
        //        }
        //        if (Input.IsKeyDown(Keys.DOWN) || i % 10 == 0)
        //        {
        //            if (y <= graphics.ClientHeight - size * 3)
        //            {
        //                if (Field.Rectangles[y / size + 2, x / size].CelsValue == 0 && Field.Rectangles[y / size + 2, x / size + 1].CelsValue == 0) y += size;
        //            }
        //            else
        //            {
        //                if (y < graphics.ClientHeight - size) y += size;
        //            }
        //        }
        //        i++;
        //    }
        //    else
        //    //    {
        //    int fieldX = x;
        //    int fieldY = y;
        //    for (int i = 0; i < LFigure.GetLength(0); i++)
        //    {
        //        for (int j = 0; j < LFigure.GetLength(1); j++)
        //        {
        //            Field.Rectangles[fieldY / size, fieldX / size].Color = LFigure[i, j].Color;
        //            Field.Rectangles[fieldY / size, fieldX / size].CelsValue = LFigure[i, j].CelsValue;
        //            fieldX += size;
        //        }
        //        fieldY += size;
        //        fieldX = x;
        //    }
        //    x = startX;
        //    y = startY;

        //    return endGame = true;
        //}
        //else
        //{
        //    return endGame = false;
        //}

        //    if(i%10==0)
        //    {
        //        for (int i = LFigure.GetLength(0)-1; ;)
        //        {
        //            for (int j = 0; j < LFigure.GetLength(1); j++)
        //            {
        //                if (y<=graphics.ClientHeight-size*4)
        //                {
        //                    if (Field.Rectangles[,] )
        //                        y += size;
        //                }
        //            }

        //        }
        //    }
        //    i++;
        //    return endGame = true;
        //}

        public override void Render(ConsoleGraphics graphics)
        {
            for (int i = 0; i < LFigure.GetLength(0); i++)
            {
                for (int j = 0; j < LFigure.GetLength(1); j++)
                {
                    graphics.FillRectangle((uint)LFigure[i, j].Color, LFigure[i, j].x, LFigure[i, j].y, size, size);
                }
            }
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            ConsoleGraphics g = new ConsoleGraphics();

            Console.CursorVisible = false;
            while (true)
            {
                g.FillRectangle(0xFF00FF00, 10, 10, 40, 40);
                g.FlipPages();
            }
        }
Ejemplo n.º 25
0
        private void DisplayDrives(uint color, Tab tab)
        {
            int textCoordinateY = tab.CoordinateY;
            var listDrives      = tab.GetListDrives();

            for (int i = 0; i < listDrives.Count; i++)
            {
                if (i == tab.Position)
                {
                    _graphics.FillRectangle(color, tab.CoordinateX, textCoordinateY + 5, Settings.TabWidth, Settings.FontSize);
                    _graphics.DrawString($"{listDrives[i].Name}", Settings.FontName, Settings.BlackColor, tab.CoordinateX, textCoordinateY, Settings.FontSize);
                }
                else
                {
                    _graphics.DrawString($"{listDrives[i].Name}", Settings.FontName, color, tab.CoordinateX, textCoordinateY, Settings.FontSize);
                }

                textCoordinateY += Settings.FontSize + 1;
            }
        }
Ejemplo n.º 26
0
        public void Draw(ConsoleGraphics graphics, Point position, Size size)
        {
            uint textColor = ColorResources.ListItemTextColor;

            if (_parent.Enabled && Selected)
            {
                graphics.FillRectangle(ColorResources.ListItemBackgroundColor, position.X, position.Y, size.Width, size.Height);
                textColor = ColorResources.ListItemSelectedTextColor;
            }
            graphics.DrawString(Text, StringResources.FontName, textColor, position.X, position.Y, NumericConstants.FontSize);
        }
Ejemplo n.º 27
0
 public void Start()
 {
     while (!Exit)
     {
         _graphics.FillRectangle(Settings.BlackColor, 0, 0, _graphics.ClientWidth, _graphics.ClientHeight);
         _hints.ShowHints();
         _tabView.Show();
         _graphics.FlipPages();
         _userActionListener.ReadInput();
     }
 }
Ejemplo n.º 28
0
        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();
        }
Ejemplo n.º 29
0
        public override void OnPaint(PaintEventArgs e)
        {
            ConsoleGraphics g = e.Graphics;

            g.FillRectangle(ColorResources.WindowBackgroundColor, Position.X, Position.Y, Size.Width, Size.Height);
            g.DrawRectangle(ColorResources.WindowBorderColor, Position.X + NumericConstants.MarginUpLeft,
                            Position.Y + NumericConstants.MarginUpLeft, Size.Width - NumericConstants.MarginRightDown,
                            Size.Height - NumericConstants.MarginRightDown, NumericConstants.WindowBorderThikness);
            g.DrawString(_message, StringResources.FontName, ColorResources.WindowTextColor,
                         Position.X + 10, Position.Y + 10, NumericConstants.FontSize);
            _okButton.Draw(g);
        }
Ejemplo n.º 30
0
        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;
                }
            }
        }