Exemple #1
0
        //#####################################################################################

        private void Form_Main_Paint(object sender, PaintEventArgs e)
        {
            if (this.checkBox_drawMap.Checked)
            {
                m_view.DrawBoard(m_server.GameBoard, this.ClientRectangle, true, e.Graphics);

                m_effectView.UpdateAndDrawEffect(e.Graphics);


                if (this.checkBox_showUsersScreen.Checked)
                {
                    var loginUsers = m_server.UserDirector.LoginUsers;

                    foreach (var user in loginUsers)
                    {
                        var rect = m_server.GameBoardDirector.GetUserScreen(user.Name);

                        rect.X      *= m_view.TileSize;
                        rect.Y      *= m_view.TileSize;
                        rect.Width  *= m_view.TileSize;
                        rect.Height *= m_view.TileSize;

                        rect.X += m_view.BoardLocation.X;
                        rect.Y += m_view.BoardLocation.Y;

                        e.Graphics.DrawRectangle(Pens.Red, rect);
                    }
                }
            }
        }
Exemple #2
0
        public static async Task BoardUpdate(Board board)
        {
            var onlineBoard  = new BoardRepository(Connection());
            var updatedBoard = await onlineBoard.FetchBoard();

            foreach (var content in updatedBoard)
            {
                var obj = board.Container.FirstOrDefault(x => x.Id == content.Id);
                if (obj != null)
                {
                    obj.Id = content.Id;
                }
                Convert(content, board);
            }
            BoardView.DrawBoard(board.BoardState());
        }
Exemple #3
0
        public void PlaceShips(int xSt, int ySt)
        {
            BoardView boardView = new BoardView(xSt, ySt);

            boardView.DrawBoard(xSt, ySt);

            int length = 2;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    int        deckQty;
                    Coordinate upperLeft    = new Coordinate();
                    bool       isHorizontal = true;
                    String     isHorizontalStr;
                    Ship       ship = new Ship();
                    ship.Coordinates = new Coordinate[i + 1];
                    ship.Health      = i + 1;
                    ship.Length      = i + 1;
                    do
                    {
                        bool error;
                        deckQty = i + 1;
                        if (i > 0)
                        {
                            do
                            {
                                error = false;
                                Console.Write("Задайте ориентацию " + (j + 1) + "-го " + deckQty + "-палубного корабля(h - горизонтальная, v - вертикальная): ");
                                isHorizontalStr = Console.ReadLine();
                                if (isHorizontalStr == "h")
                                {
                                    isHorizontal = true;
                                }
                                else if (isHorizontalStr == "v")
                                {
                                    isHorizontal = false;
                                }
                                else
                                {
                                    error = true;
                                }
                                if (error)
                                {
                                    Console.WriteLine("Неверный символ! Повторите ввод.");
                                }
                            } while (error);
                        }

                        do
                        {
                            error = false;
                            Console.Write("Введите координату верхней или левой палубы " + (j + 1) + "-го " + deckQty + "-палубного корабля: ");
                            if (!int.TryParse(Console.ReadLine(), out var x))
                            {
                                error = true;
                            }
                            if (!int.TryParse(Console.ReadLine(), out var y))
                            {
                                error = true;
                            }
                            if (upperLeft.X < 0 || upperLeft.X > 9 || upperLeft.Y < 0 || upperLeft.Y > 9)
                            {
                                error = true;
                            }

                            if (!error)
                            {
                                upperLeft = new Coordinate(x, y);
                                boardView.DrawShoot(true, upperLeft);
                            }
                            if (error)
                            {
                                Console.Write("Ошибка! Попробуйте еще раз.");
                            }
                        } while (error);
                        if (!CheckFreeSpace(upperLeft.X, upperLeft.Y, deckQty, isHorizontal, Game.PlayerBoard))
                        {
                            Console.Write("Здесь нельзя располагать корабль. Попробуйте еще раз.");
                        }
                    } while (!CheckFreeSpace(upperLeft.X, upperLeft.Y, deckQty, isHorizontal, Game.PlayerBoard));
                    for (int s = 0; s < deckQty; s++)
                    {
                        if (isHorizontal)
                        {
                            ship.Coordinates[s] = new Coordinate(upperLeft.X + s, upperLeft.Y);
                        }
                        else
                        {
                            ship.Coordinates[s] = new Coordinate(upperLeft.X, upperLeft.Y + s);
                        }
                    }
                    MadeShipArea(ship);
                    Game.PlayerBoard.Ships.Add(ship);
                }
                length--;
            }
        }