public static ColoredChar ColoredCharFromCellStatus(CellStatus status)
        {
            ColoredChar result = new ColoredChar();

            switch (status)
            {
            case CellStatus.ClosedEmpty:
            case CellStatus.ClosedShip:
                result.BackgroundColor = ConsoleColor.White;
                result.Char            = '.';
                break;

            case CellStatus.Ship:
                result.BackgroundColor = ConsoleColor.Red;
                result.ForegroundColor = ConsoleColor.Black;
                result.Char            = 'X';
                break;

            case CellStatus.Empty:
                result.BackgroundColor = ConsoleColor.Blue;
                result.ForegroundColor = ConsoleColor.White;
                result.Char            = '-';
                break;

            default: throw new Exception();
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Sets the status of a cell
        /// </summary>
        /// <param name="row">Row number of cell</param>
        /// <param name="column">Column number of cell</param>
        /// <param name="status">New status of cell</param>
        public void Play(int row, int column, CellStatus status)
        {
            if (row < MIN_ROW_COLUMN || row > MAX_ROW_COLUMN)
            {
                throw new ArgumentOutOfRangeException(nameof(row), $"'{nameof(row)}' should be between {MIN_ROW_COLUMN} and {MAX_ROW_COLUMN}");
            }

            if (column < MIN_ROW_COLUMN || column > MAX_ROW_COLUMN)
            {
                throw new ArgumentOutOfRangeException(nameof(column), $"'{nameof(column)}' should be between {MIN_ROW_COLUMN} and {MAX_ROW_COLUMN}");
            }

            if (status != CellStatus.X && status != CellStatus.O)
            {
                throw new ArgumentException(nameof(status), $"'{nameof(status)}' '{status}' is invalid");
            }

            if (_cells[row, column] != CellStatus.Unmarked)
            {
                throw new InvalidOperationException($"Cell with row={row} and column={column} is already marked");
            }

            _cells[row, column] = status;

            if (Status == GameStatus.New)
            {
                Status = GameStatus.InProgress;
            }

        }
        public CellStatus[,] GetBoard()
        {
            var result = new CellStatus[BoardHeight, BoardWidth];

            Array.Copy(Board, result, Board.Length);
            return(result);
        }
        private static string GetSingleState(CellStatus status)
        {
            switch (status)
            {
            case CellStatus.ClosedMine:
                return(" ");

            case CellStatus.FlaggedMine:
                return("F");

            case CellStatus.OpenMine:
                Console.ForegroundColor = ConsoleColor.DarkRed;
                return("*");

            case CellStatus.ClosedAndNotAMine:
                return(" ");

            case CellStatus.OpenedAndNotAMine:
                return("1");

            case CellStatus.FlaggedAndNotMine:
                return("F");

            default:
                throw new InvalidEnumArgumentException("Unknown enum option!");
            }
        }
示例#5
0
 public Cell(int x, int y, int color = 0, int status = 1)
 {
     this.x      = x;
     this.y      = y;
     this.color  = (Color)color;
     this.status = (CellStatus)status;
 }
示例#6
0
 public CellInfo(int costSoFar, int estimatedTotal, CPos previousPos, CellStatus status)
 {
     this.CostSoFar      = costSoFar;
     this.EstimatedTotal = estimatedTotal;
     this.PreviousPos    = previousPos;
     this.Status         = status;
 }
示例#7
0
        private bool CheckHorizontalLines(MyTable table)
        {
            bool win = true;

            for (int i = 0; i < table.Rows; i++)
            {
                win = true;
                CellStatus cellStatus = table[i, 0].Status;

                if (cellStatus == CellStatus.Empty)
                {
                    win = false;
                    continue;
                }

                for (int j = 1; j < table.Columns; j++)
                {
                    if (cellStatus != table[i, j].Status)
                    {
                        win = false;
                        break;
                    }
                }

                if (win)
                {
                    return(true);
                }
            }
            return(win);
        }
        private bool CheckWinenrByStatus(CellStatus cellStatus)
        {
            bool hasWinner = false;

            // Check rows
            bool winnerRows = (cells[0, 0].Status == cellStatus && cells[0, 1].Status == cellStatus && cells[0, 2].Status == cellStatus) ||
                              (cells[1, 0].Status == cellStatus && cells[1, 1].Status == cellStatus && cells[1, 2].Status == cellStatus) ||
                              (cells[2, 0].Status == cellStatus && cells[2, 1].Status == cellStatus && cells[2, 2].Status == cellStatus);

            if (winnerRows)
            {
                return(true);
            }

            // Check cols
            bool winnerCols = (cells[0, 0].Status == cellStatus && cells[1, 0].Status == cellStatus && cells[2, 0].Status == cellStatus) ||
                              (cells[0, 1].Status == cellStatus && cells[1, 1].Status == cellStatus && cells[2, 1].Status == cellStatus) ||
                              (cells[0, 2].Status == cellStatus && cells[1, 2].Status == cellStatus && cells[2, 2].Status == cellStatus);

            if (winnerCols)
            {
                return(true);
            }

            // Check other
            bool winnerOther = (cells[0, 0].Status == cellStatus && cells[1, 1].Status == cellStatus && cells[2, 2].Status == cellStatus) ||
                               (cells[0, 2].Status == cellStatus && cells[1, 1].Status == cellStatus && cells[2, 0].Status == cellStatus);

            if (winnerOther)
            {
                return(true);
            }

            return(hasWinner);
        }
示例#9
0
        public string SolveFirstProblem()
        {
            //_currentGrid.Print(PrintCell);
            bool hasChanged = true;

            while (hasChanged)
            {
                var newGrid = new CellStatus[_currentGrid.YMax, _currentGrid.XMax];
                hasChanged = false;
                foreach (var cell in _currentGrid.All().ToList())
                {
                    if (cell.Value == CellStatus.EmptySeat && AreNoOccupiedSeatAround(_currentGrid.Around(cell)))
                    {
                        newGrid[cell.Y, cell.X] = CellStatus.OccupiedSeat;
                        hasChanged = true;
                    }
                    else if (cell.Value == CellStatus.OccupiedSeat && AreMoreTHan4NeighborOccupied(_currentGrid.Around(cell)))
                    {
                        newGrid[cell.Y, cell.X] = CellStatus.EmptySeat;
                        hasChanged = true;
                    }
                    else
                    {
                        newGrid[cell.Y, cell.X] = cell.Value;
                    }
                }

                _currentGrid = new Grid <CellStatus>(newGrid, _currentGrid.YMax, _currentGrid.XMax);
                //_currentGrid.Print(PrintCell);
            }

            return(_currentGrid.All().Count(s => s.Value == CellStatus.OccupiedSeat).ToString());
        }
示例#10
0
        public List <Figure> Build()
        {
            CellStatus side = CellStatus.Player1;
            int        y    = 1;

            for (int i = 0; i < 2; i++)
            {
                Figures.Add(new Сastle(side, new PointV2(8, y)));
                Figures.Add(new Сastle(side, new PointV2(1, y)));

                Figures.Add(new Bishop(side, new PointV2(7, y)));
                Figures.Add(new Bishop(side, new PointV2(2, y)));

                Figures.Add(new Horse(side, new PointV2(6, y)));
                Figures.Add(new Horse(side, new PointV2(3, y)));



                for (int iPawn = 1; iPawn <= 8; iPawn++)
                {
                    Figures.Add(new Pawn(side, new PointV2(iPawn, y)));
                }
                side = CellStatus.Player2;
                y    = 8;
            }

            Figures.Add(new King(side, new PointV2(5, 1)));
            Figures.Add(new Queen(side, new PointV2(4, 1)));

            Figures.Add(new King(side, new PointV2(4, 8)));
            Figures.Add(new Queen(side, new PointV2(5, 8)));

            return(Figures);
        }
示例#11
0
 public Cell(CellId id, CellStatus cellStatus, Side side, CellId[] connections)
 {
     Id          = id;
     Connections = (CellId[])connections.Clone();
     this.Side   = side;
     this.Status = cellStatus;
 }
示例#12
0
 public Cell(int rowLocation, int columnLocation, bool queen, CellStatus status)
 {
     RowLocation    = rowLocation;
     ColumnLocation = columnLocation;
     Queen          = queen;
     Status         = status;
 }
示例#13
0
        public void TestTriangleIntersection()
        {
            VoxelizingOctreeCell p = this;

            while (p != null)
            {
                for (int i = 0; i < p.Triangles.Count; i++)
                {
                    Triangle t = p.Triangles[i];
                    if (Intersects(ref t))
                    {
                        Status = CellStatus.Intersecting;
                        return;
                    }
                }

                p = p.Parent;
            }

            // If we're not intersecting any triangles make sure we're also not intersecting the mesh bounds.
            if (IntersectsMeshBounds())
            {
                Status = CellStatus.IntersectingBounds;
            }
        }
        private List <List <Cell> > CreateGridFromInput()
        {
            var grid = new List <List <Cell> >();

            for (int row = 0; row < _input.Count; row++)
            {
                var inputRow = _input[row];
                var cells    = new List <Cell>();
                for (int column = 0; column < inputRow.Length; column++)
                {
                    var        inputColumn = inputRow[column];
                    CellStatus status      = CellStatus.Empty;
                    if (inputColumn == '.')
                    {
                        status = CellStatus.Floor;
                    }
                    else if (inputColumn == '#')
                    {
                        status = CellStatus.Occupied;
                    }
                    cells.Add(new Cell(row, column, status));
                }
                grid.Add(cells);
            }
            return(grid);
        }
示例#15
0
        public List <VoxelizingOctreeCell> Find(CellStatus status)
        {
            List <VoxelizingOctreeCell> cellList = new List <VoxelizingOctreeCell>();

            m_root.Find(cellList, status);
            return(cellList);
        }
 public CellInfo(int costSoFar, int estimatedTotal, CPos previousPos, CellStatus status)
 {
     CostSoFar      = costSoFar;
     PreviousPos    = previousPos;
     Status         = status;
     EstimatedTotal = estimatedTotal;
 }
示例#17
0
        private static Cell SetupCell(CellStatus status, int livingNeighbors)
        {
            var cell = new Cell(status);

            var cellStatuses = new CellStatus[8];

            for (var i = 0; i < 8; ++i)
            {
                cellStatuses[i] = i < livingNeighbors ? CellStatus.Living : CellStatus.Dead;
            }

            var west = new Cell(cellStatuses[0]);

            cell.AddNeighbor(west, Direction.West);

            var east = new Cell(cellStatuses[1]);

            cell.AddNeighbor(east, Direction.East);

            cell.AddNeighbor(new Cell(cellStatuses[2]), Direction.North);
            cell.AddNeighbor(new Cell(cellStatuses[3]), Direction.South);

            west.AddNeighbor(new Cell(cellStatuses[4]), Direction.North);
            west.AddNeighbor(new Cell(cellStatuses[5]), Direction.South);

            east.AddNeighbor(new Cell(cellStatuses[6]), Direction.North);
            east.AddNeighbor(new Cell(cellStatuses[7]), Direction.South);

            return(cell);
        }
        public virtual int GetNeighborsCount(CellStatus SearchCellStatus)
        {
            int[,] SearchLocations = new int[, ] {
                { 0, -1 }, { 1, -1 }, { 1, 0 }, { 1, 1 }, { 0, 1 }, { -1, 1 }, { -1, 0 }, { -1, -1 }
            };

            int neighborCount = 0;

            for (int i = 0; i < SearchLocations.Length / 2; i++)
            {
                int xOfNeighborCell = X + SearchLocations[i, 0];
                int yOfNeigborCell  = Y + SearchLocations[i, 1];
                var neighborCell    = Board.Cells.Where(x => x.X == xOfNeighborCell && x.Y == yOfNeigborCell).FirstOrDefault();

                if (neighborCell == null)
                {
                    //if (SearchCellStatus == CellStatus.Dead)
                    //    neighborCount++;

                    continue;
                }

                if (neighborCell.Status == SearchCellStatus)
                {
                    neighborCount++;
                }
            }
            return(neighborCount);
        }
示例#19
0
        private void Shot()
        {
            if (_corditateI < Field.Size)
            {
                if (_shotState == CellStatus.Drowned)
                {
                    MarkDrownedShip();
                }
                Thread.Sleep(100);

                if (!(_cordinateJ < Field.Size))
                {
                    _cordinateJ = 0;
                    _corditateI++;
                }
                do
                {
                    _shotState = OponentField.Shot(OponentField.CellField[_corditateI, _cordinateJ]);
                    _cordinateJ++;
                    if (_cordinateJ != Field.Size)
                    {
                        continue;
                    }
                    _cordinateJ = 0;
                    _corditateI++;
                } while (OponentField.CellField[_corditateI, _cordinateJ].CellStatus == CellStatus.Miss);

                _currentShot = new Location(_corditateI, _cordinateJ);
            }

            if (_shotState != CellStatus.Miss)
            {
                Move();
            }
        }
示例#20
0
    //通过类型获得相应游戏对象
    public GameObject CreateObjByType(CellType type, CellStatus status)
    {
        //GameObject obj = null;
        string path = null;

        if (status == CellStatus.Ready)
        {
            path = "ReadyCell/Ready" + type;
        }
        if (status == CellStatus.Full)
        {
            path = "FullCell/Full" + type;
        }
        switch (type)
        {
        case CellType.Block:
            break;

        case CellType.Soap:
            break;

        default:
            break;
        }
        GameObject obj = Instantiate(Resources.Load(path)) as GameObject;

        return(obj);
    }
示例#21
0
 public void WorkOutLifeStatus()
 {
     if(_noOfLiveNeighbours != 1 && _noOfLiveNeighbours != 4)
         _cellStatus = CellStatus.Alive;
     else
         _cellStatus = CellStatus.Dead;
 }
        /// <summary>
        /// Generates grid of first generation.
        /// </summary>
        public WorldGenerationResult RandomGeneration(WorldSize worldSize)
        {
            if (worldSize.Rows < 1 || worldSize.Columns < 1) // worldSize size is invalid
            {
                throw new ArgumentOutOfRangeException("World Size has incorrect value", nameof(worldSize));
            }

            var firstGeneration = new CellStatus[worldSize.Rows, worldSize.Columns];
            int aliveCells      = 0;

            // Randomly initialize grid
            for (var row = 0; row < worldSize.Rows; row++)
            {
                for (var column = 0; column < worldSize.Columns; column++)
                {
                    firstGeneration[row, column] = (CellStatus)RandomNumberGenerator.GetInt32(0, 2);

                    var cell = firstGeneration[row, column];

                    if (cell == CellStatus.Alive)
                    {
                        aliveCells++;
                    }
                }
            }

            return(new WorldGenerationResult
            {
                AliveCells = aliveCells,
                IsGenerationAlive = aliveCells > 0,
                Generation = firstGeneration
            });
        }
示例#23
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            CellStatus cellStatus = (CellStatus)value;

            // switch CellStatus, return colour from application resources
            switch (cellStatus)
            {
            case CellStatus.Path:
                return(Application.Current.FindResource("PathCell"));

            case CellStatus.PathVisited:
                return(Application.Current.FindResource("VisitedCell"));

            case CellStatus.Wall:
                return(Application.Current.FindResource("WallCell"));

            case CellStatus.Start:
                return(Application.Current.FindResource("StartCell"));

            case CellStatus.Finish:
                return(Application.Current.FindResource("FinishCell"));

            case CellStatus.SolutionPath:
                return(Application.Current.FindResource("SolutionPathCell"));

            default:
                return(Application.Current.FindResource("PathCell"));
            }
        }
示例#24
0
        public int SecondPart()
        {
            var mat   = new CellStatus[GRID_SIZE, GRID_SIZE];
            var input = Input();

            PlaceInputInMatrix2(ref input, ref mat);

            int x = GRID_SIZE / 2;
            int y = GRID_SIZE / 2;

            var dir = Direction.UP;

            int totalInfected = 0;

            for (int i = 0; i < 10000000; ++i)
            {
                // Print(ref mat, x, y);
                if (Move2(ref mat, ref x, ref y, ref dir))
                {
                    ++totalInfected;
                }
            }

            return(totalInfected);
        }
示例#25
0
 public AStarNode(int parent, int g, int h, CellStatus status)
 {
     Parent = parent;
     G = g;
     H = h;
     Status = status;
 }
示例#26
0
        static void Made_Shot(object sender, EventArgs e)
        {
            Field field = (Field)sender;

            if (field == Form1.RightField)
            {
                leftStatistics.CountLeftShot--;
            }
            else
            {
                rightStatistics.CountLeftShot--;
            }

            CellStatus result = ((shotEventArgs)e).shotResult;

            if (result == CellStatus.Drowned)
            {
                if (field == Form1.RightField)
                {
                    rightStatistics.CountShips--;
                }
                else
                {
                    leftStatistics.CountShips--;
                }
            }
        }
示例#27
0
 public AStarNode(int parent, int g, int h, CellStatus status)
 {
     Parent = parent;
     G      = g;
     H      = h;
     Status = status;
 }
示例#28
0
        private bool CheckHorizontalLines(CellViewModel[,] cells)
        {
            bool win = true;

            for (int i = 0; i < cells.GetLength(0); i++)
            {
                win = true;
                CellStatus cellStatus = cells[i, 0].Status;

                if (cellStatus == CellStatus.Empty)
                {
                    win = false;
                    continue;
                }

                for (int j = 1; j < cells.GetLength(0); j++)
                {
                    if (cellStatus != cells[i, j].Status)
                    {
                        win = false;
                        break;
                    }
                }

                if (win)
                {
                    return(true);
                }
            }
            return(win);
        }
示例#29
0
 internal Snake(Pos startPos, CellStatus faction)
 {
     _length = 1;
     _body   = new LinkedList <Pos>();
     _body.AddFirst(startPos);
     _faction = faction;
 }
示例#30
0
 public CellInfo(int costSoFar, int estimatedTotal, CPos previousPos, CellStatus status)
 {
     CostSoFar = costSoFar;
     PreviousPos = previousPos;
     Status = status;
     EstimatedTotal = estimatedTotal;
 }
示例#31
0
 public void AddNeighbours(NeighbourCount neihghboursCount, CellStatus cellStatus)
 {
     for (int i = 0; i < (int)neihghboursCount; i++)
     {
         AddNeighbour(CellFactory(cellStatus).AddNeighbour(this));
     }
 }
示例#32
0
文件: Cell.cs 项目: ledomag/Life
        /// <summary>
        /// Создает Cell
        /// </summary>
        /// <param name="status">Статус</param>
        /// <param name="step">Шаг</param>
        public Cell(CellStatus status, byte step)
        {
            Status = status;
            Step   = step;

            OnCreated(new EventArgs());
        }
示例#33
0
        private static bool IsPointLost(Map map, MapPoint point, CellStatus enemyPointStatus)
        {
            var neighbours = new List <MapPoint>
            {
                map.GetPoint(point.X, point.Y, Direction.North),
                map.GetPoint(point.X, point.Y, Direction.South),
                map.GetPoint(point.X, point.Y, Direction.East),
                map.GetPoint(point.X, point.Y, Direction.West)
            };

            foreach (var neighbour in neighbours)
            {
                if (neighbour == null)
                {
                    return(false);
                }

                if (neighbour.CellStatus == enemyPointStatus)
                {
                    continue;
                }
                point.CellStatus = enemyPointStatus;
                if (!IsPointLost(map, neighbour, enemyPointStatus))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#34
0
            public bool isThreatingSomeone(/*ref CellStatus[,] currentBattleField,*/ int fieldSize)
            {
                CellStatus[,] currentBattleField = new CellStatus[fieldSize, fieldSize];
                bool isThreatingSomeone = false;

                for (int i = 0; i < moveX.Length; i++)
                {
                    int temp = i / 2 == 0 ? 0 : 2;
                    for (int j = temp; j < temp + 2; j++)
                    {
                        if (moveIsPossible(moveX[i], moveY[j], fieldSize))
                        {
                            //если противник в клетке хода есть, и если эта клетак не находится под атакой
                            if (field[x + moveX[i], y + moveY[j]] == CellStatus.enemy &&
                                currentBattleField[x + moveX[i], y + moveY[j]] != CellStatus.underAttack)
                            {
                                Console.WriteLine("field[" + x + " + " + moveX[i] + ", " + y + " + " + moveY[j] + "] == " + (field[x + moveX[i], y + moveY[j]].ToString()));
                                currentBattleField[x + moveX[i], y + moveY[j]] = CellStatus.underAttack;
                                figuresUnderAttack++;
                                isThreatingSomeone = true;
                            }
                        }
                    }
                }
                return(isThreatingSomeone);
            }
示例#35
0
        public static bool BoardIsEmpty(CellStatus[,] status)
        {
            for (int i = 0; i < status.GetLength(1); i++)
            {
                if (status[0, i] != CellStatus.Empty)
                    return false;
            }

            return true;
        }
示例#36
0
        public static bool IsValidCell(int r, int c, CellStatus[,] cells)
        {
            if (r < 0 || r >= cells.GetLength(0))
                return false;

            if (c < 0 || c >= cells.GetLength(1))
                return false;

            return true;
        }
 public Player(int x, int y, ConsoleColor color = ConsoleColor.DarkYellow, char character = (char)2)
 {
     CurrentPositionX = x;
     CurrentPositionY = y;
     LastPositionX = x;
     LastPositionY = y;
     PlayerColor = color;
     PlayerChar = character;
     lastPosition = CellStatus.Filled;
 }
示例#38
0
        private bool PlayInTheMiddle(CellStatus[,] cells)
        {
            if (Utils.BoardIsEmpty(cells))
                return true;

            if (Utils.IsPlayerFirstMove(cells, Color))
                return true;

            return false;
        }
        private BoardCoordinate? FindNextFreeSpace(CellStatus[,] workingSet, BoardCoordinate cellToStartSearch, ShipDirection direction, int shipLength)
        {
            // the free space must be a cluster of cells with 'Free' status, such that
            // they can be contiguous and none of the cells of the new ship lands on
            // a 'not available for placement' or 'ship part' field.
            for (var row = cellToStartSearch.Row; row < _gameConfiguration.BoardSize; row++)
            {
                for (var column = cellToStartSearch.Column; column < _gameConfiguration.BoardSize; column++)
                {
                    if (workingSet[row, column] == CellStatus.Free)
                    {
                        if (direction == ShipDirection.Horizontal)
                        {
                            // first - check if there is enough room to place the ship in the current row/column
                            if (column + shipLength > _gameConfiguration.BoardSize - 1)
                                continue;

                            // next, check if the entire span of the next few cells is available
                            var spanAvailable = true;
                            for (var c = column; c < column + shipLength; c++)
                            {
                                if (workingSet[row, c] != CellStatus.Free)
                                {
                                    spanAvailable = false;
                                    break;
                                }
                            }
                            if (!spanAvailable)
                                continue;
                        }
                        else
                        {
                            if (row + shipLength > _gameConfiguration.BoardSize - 1)
                                continue;

                            var spanAvailable = true;
                            for (var r = row; r < row + shipLength; r++)
                            {
                                if (workingSet[r, column] != CellStatus.Free)
                                {
                                    spanAvailable = false;
                                    break;
                                }
                            }
                            if (!spanAvailable)
                                continue;
                        }

                        return new BoardCoordinate(row, column);
                    }
                }
            }

            return null;
        }
示例#40
0
 public static Color GetPlayerFromStatus(CellStatus status)
 {
     switch (status)
     {
         case CellStatus.Red:
             return Color.Red;
         case CellStatus.Blue:
             return Color.Blue;
         default:
             throw new SystemException();
     }
 }
    //Constructor
    public GameField(int height, int width)
    {
        this.height = height;
        this.width = width;
        tmpList = new List<List<int>>();
        gameField = new CellStatus[height, width];

        //Not for here, must be in GameSettings
        Console.BufferHeight = Console.WindowHeight = height;
        Console.BufferWidth = Console.WindowWidth = width + 26;
        Console.CursorVisible = false;
    }
示例#42
0
        public static bool CanPlaceDiskAt(int r, int c, CellStatus[,] cells)
        {
            if (!IsValidCell(r, c, cells))
                return false;

            if (cells[r, c] == CellStatus.Empty)
            {
                if (r == 0 || (r > 0 && cells[r - 1, c] != CellStatus.Empty))
                {
                    return true;
                }
            }

            return false;
        }
示例#43
0
        internal static bool IsPlayerFirstMove(CellStatus[,] cells, Color color)
        {
            CellStatus status = GetStatusFromPlayer(color);

            for (int row = 0; row < cells.GetLength(0); row++)
            {
                for (int col = 0; col < cells.GetLength(1); col++)
                {
                    if (cells[row, col] == status)
                        return false;
                }
            }

            return true;

        }
	public void populateFunctional(string pmFunctionalName, string pmFunctionalButtonName, CellStatus pmStatus)
	{
		functionalNameInput.GetComponent<InputField> ().text = pmFunctionalName;
		Sprite lvButtonSprite = Resources.Load<Sprite> ("ObstaclesImages/Functional/"+pmFunctionalButtonName);

		functionalImage.GetComponent<Image> ().sprite = lvButtonSprite;
		pmStatus.edited = true;
		editedFunctionalCell = pmStatus;

		functionImput.GetComponent<InputField>().text = "DYNAMIC";
		functionalSelectButton.GetComponent<Button> ().interactable = true;
		functionalRemoveButton.GetComponent<Button> ().interactable = true;

		pmStatus.Function = "DYNAMIC";
		pmStatus.FigurineId = -1;
	}
        private Board ConvertWorkingSetIntoBoard(CellStatus[,] workingSet)
        {
            var generated = new Board(_gameConfiguration);

            workingSet.Foreach((row, column) =>
            {
                if (workingSet[row, column] == CellStatus.ShipPart)
                    generated.BoardRepresentation.Add(new BoardCoordinate(row, column));
            });

            if (!generated.IsValid)
            {
                throw new Exception("Generated board is invalid!");
            }

            return generated;
        }
示例#46
0
	private float distanceFromCenter = 0.0f; //this is going to be used to add varience in the spawned asteriods
	#pragma warning restore
	#endregion

	public void CheckPlayer()
	{
		if(GameManager.Instance.playerObject)
		{
			float distance = Vector3.Distance(gameObject.transform.position, GameManager.Instance.playerObject.transform.position);
			float cellSize = gameObject.transform.localScale.x;
			if(distance <= (cellSize * 2) && status != CellStatus.active)
			{
				Activate();
				status = CellStatus.active;
			}
			else if(distance > (cellSize * 2) && status != CellStatus.standby)
			{
				status = CellStatus.standby;
				Deactivate();
			}
		}
	}
        private Board ConvertWorkingSetIntoBoard(CellStatus[,] workingSet)
        {
            var generated = new Board(_gameConfiguration);

            workingSet.Foreach((row, column) =>
            {
                if (workingSet[row, column] == CellStatus.ShipPart)
                    generated.BoardRepresentation.Add(new BoardCoordinate(row, column));
            });

            string validationError = generated.Validate();
            if (validationError != null)
            {
                Debug.Print(validationError);
                Debug.Print(generated.PresentBoardGraphically());
                throw new Exception("Generated board is invalid!");
            }

            return generated;
        }
示例#48
0
        public bool GetCellInfo(Bitmap data, out CellStatus status, out int n)
        {
            status = CellStatus.Undef;
            n = -3;
            BitmapWrapper bw = new BitmapWrapper(data);

            Color t = bw.AvgColor;
            double d = bw.Factor;
            Console.WriteLine(t);
            Console.WriteLine(d);
            Console.WriteLine("Byway");
            //data.Save("d:\\gc.png");

            foreach (var item in IdentifyData.IdentifierList)
                if (item.Deal(bw, out status, out n)) return true;

            status = CellStatus.Undef;
            n = -3;

            return false;;
        }
示例#49
0
        public void UpdateStatus(Cell[,] currentWorld)
        {
            int liveNeighbourCount = 0;

            for (var r = Row - 1; r <= Row + 1; r++)
            {
                for (var c = Column - 1; c <= Column + 1; c++)
                {
                    if (r >= 0 && r < currentWorld.GetLength(0)
                        && c >= 0 && c < currentWorld.GetLength(1)
                        && currentWorld[r, c].Status == CellStatus.Alive)
                    {
                        if (r == Row && c == Column)
                            continue;

                        liveNeighbourCount++;
                    }
                }
            }

            //if (liveNeighbourCount < 2 || liveNeighbourCount > 3)
            //{
            //    Status = CellStatus.Dead;
            //}

            if (liveNeighbourCount == 3)
            {
                Status = CellStatus.Alive;
            }
            else if (liveNeighbourCount == 2)
            {
                Status = currentWorld[Row, Column].Status;
            }
            else
            {
                Status = CellStatus.Dead;
            }

            // if 2, nothing changes. Lived keeps alive
        }
示例#50
0
        public int Move(CellStatus[,] status)
        {
            
            int col;

            while (true)
            {
                Console.WriteLine("Insert column index");

                bool isValid = int.TryParse(Console.ReadLine(), out col);

                if (!isValid)
                {
                    Console.WriteLine("Insert valid column index!");
                    continue;
                }

                break;
            }

            return col;

        }
 //The ToColor method from GameField
 public static ConsoleColor CellColor(CellStatus status)
 {
     if (status.Equals(CellStatus.Empty))
     {
         return ConsoleColor.Black;
     }
     else if (status.Equals(CellStatus.Filled))
     {
         return ConsoleColor.Cyan;
     }
     else if (status.Equals(CellStatus.Head))
     {
         return ConsoleColor.White;
     }
     else if (status.Equals(CellStatus.Trail))
     {
         return ConsoleColor.Cyan;
     }
     else if (status.Equals(CellStatus.Ball))
     {
         //return ConsoleColor.; <--- Ball color
     }
     return ConsoleColor.Gray;
 }
 ///<summary>
 ///    Iterate over the grid, finding the polygons built of
 ///    cells with the given status.  This is called twice; once
 ///    for status = OverCV, and once for status = OverTerrain
 ///</summary>
 internal List<GridPolygon> DiscoverPolygonsOfStatus(CellStatus status)
 {
     List<GridPolygon> polygons = new List<GridPolygon>();
     MarkAllCellsUnused();
     for (int i=0; i<xCount - 1; i++) {
         for (int j=0; j<zCount - 1; j++) {
             List<GridCell> cells = grid[i,j];
             foreach(GridCell cell in cells) {
                 if (cell.status == status && !cell.used) {
                     GridPolygon r = FindMaximumPolygon(cell);
                     r.index = polygonIndex;
                     polygonIndex++;
                     polygons.Add(r);
                 }
             }
         }
     }
     if (status == CellStatus.OverCV)
         DumpGrid("CV Polygons", GridDumpKind.CVPolygons, true, polygons.Count);
     else
         DumpGrid("Terrain Polygons", GridDumpKind.TerrainPolygons, true, polygons.Count);
     return polygons;
 }
 ///<summary>
 ///    Discover the neighbors of all the cells in the grid
 ///    that have the given status.  This is called twice; once
 ///    for status = OverCV, and once for status = OverTerrain
 ///</summary>
 internal void DiscoverNeighbors(CellStatus status)
 {
     for (int i=0; i<xCount; i++) {
         for (int j=0; j<zCount; j++) {
             List<GridCell> cells = grid[i,j];
             foreach(GridCell cell in cells) {
                 // Ignore cells it has the right status
                 if (cell.status != status)
                     continue;
                 // Check the +x direction
                 GridCell next = FindCellAtHeight(i + 1, j, cell.loc.height);
                 if (next != null && next.status == status) {
                     // Make the bi-directional neighbor connection
                     cell.neighbors[(int)GridDirection.PlusX] = next;
                     next.neighbors[(int)GridDirection.MinusX] = cell;
                 }
                 // Check the +z direction
                 next = FindCellAtHeight(i, j + 1, cell.loc.height);
                 if (next != null && next.status == status) {
                     // Make the bi-directional neighbor connection
                     cell.neighbors[(int)GridDirection.PlusZ] = next;
                     next.neighbors[(int)GridDirection.MinusZ] = cell;
                 }
             }
         }
     }
 }
 internal GridPolygon(CellStatus status, GridCell[] corners, Vector3[] cornerLocs)
 {
     this.status = status;
     this.corners = corners;
     this.cornerLocs = cornerLocs;
 }
 internal GridPolygon(CellStatus status, GridCell c1, GridCell c2, GridCell c3, GridCell c4,
                      Vector3 c1Loc, Vector3 c2Loc, Vector3 c3Loc, Vector3 c4Loc)
 {
     this.status = status;
     corners = new GridCell[] { c1, c2, c3, c4 };
     cornerLocs = new Vector3[] { c1Loc, c2Loc, c3Loc, c4Loc };
 }
 ///<summary>
 ///    Find the arcs that connect polygons of the given type
 ///</summary>
 protected void FindPolygonArcsOfType(List<PolygonArc> arcs, List<GridPolygon> polygons, CellStatus status)
 {
     foreach (GridPolygon r in polygons) {
         if (r.status != status)
             continue;
         // Circumnavigate the perimeter looking for other
         // polygons
         ArcKind arcKind = (status == CellStatus.OverCV ? ArcKind.CVToCV : ArcKind.TerrainToTerrain);
         for (int corner=0; corner<4; corner++) {
             GridCell c = r.corners[corner];
             int sideLength = CellDistance(c, r.corners[corner == 3 ? 0 : corner+1]);
             GridDirection outside = outsideDirection[corner];
             GridDirection forward = perimeterDirection[corner];
             bool inEdge = false;
             GridCell start = null;
             GridCell lastC = null;
             GridPolygon lastPolygon = null;
             for (int j=0; j<sideLength; j++) {
                 if (c == null)
                     break;
                 GridCell n = FindCellAtHeight(c.loc.xCell + XIncrement[(int)outside],
                                               c.loc.zCell + ZIncrement[(int)outside],
                                               c.loc.height);
                 if (inEdge && (n == null || n.polygon != lastPolygon)) {
                     arcs.Add(new PolygonArc(arcKind, lastPolygon.index, r.index, MakeGridEdge(start, lastC, forward, outside)));
                     inEdge = false;
                 }
                 if (!inEdge && n != null && n.polygon != null && n.polygon.status == status) {
                     start = c;
                     lastC = c;
                     lastPolygon = n.polygon;
                     inEdge = true;
                 }
                 lastC = c;
                 c = NthNeighborOrNull(c, forward, 1);
             }
             if (inEdge && !findArc(arcs, r.index, lastPolygon.index))
                 arcs.Add(new PolygonArc(arcKind, lastPolygon.index, r.index, MakeGridEdge(start, lastC, forward, outside)));
         }
     }
     PostProcessArcs(arcs);
 }
 ///<summary>
 ///    Create a grid edge, given the starting and ending cell,
 ///    and the outside direction.  Note bene: The order of the
 ///    corners is important.  c1 is lower left; c2 is lower
 ///    right; c3 is upper right; c4 is upper left.
 ///</summary>
 internal GridPolygon MakeGridPolygon(CellStatus status, GridCell c1, GridCell c2, GridCell c3, GridCell c4)
 {
     return new GridPolygon(status, c1, c2, c3, c4,
         CoordinatesOfCell(c1, -1, -1),
         CoordinatesOfCell(c2, 1, -1),
         CoordinatesOfCell(c3, 1, 1),
         CoordinatesOfCell(c4, -1, 1));
 }
 public Board GenerateBoard(ShipPositioningParameters[] shipPositioningParameters)
 {
     var workingSet = new CellStatus[_gameConfiguration.BoardSize, _gameConfiguration.BoardSize];
     PlaceShips(workingSet, shipPositioningParameters);
     return ConvertWorkingSetIntoBoard(workingSet);
 }
        private string RepresentWorkingSet(CellStatus[,] workingSet)
        {
            var sb = new StringBuilder();

            for (var i = 0; i < workingSet.GetLength(0); i++)
            {
                for (var j = 0; j < workingSet.GetLength(1); j++)
                {
                    switch (workingSet[i, j])
                    {
                        case CellStatus.Free:
                            sb.Append("_");
                            break;
                        case CellStatus.NotAvailableForPlacement:
                            sb.Append("0");
                            break;
                        case CellStatus.ShipPart:
                            sb.Append("X");
                            break;
                    }
                }
                sb.Append(Environment.NewLine);
            }

            return sb.ToString();
        }
        private void PlaceShips(CellStatus[,] workingSet, ShipPositioningParameters[] shipPositioningParameters)
        {
            var shipsPositionedSoFar = _shipPositioningParametersPerShipLevel.Count;

            Logger.Log("PlaceShips called with {0} ships positioned so far. (Thread {1})", shipsPositionedSoFar, Thread.CurrentThread.ManagedThreadId);

            if (shipsPositionedSoFar == _gameConfiguration.ShipCount)
            {
                return;
            }

            var lengthOfNextShipToPosition = _gameConfiguration.ShipLengths[shipsPositionedSoFar];
            var directionOfPositioning = shipPositioningParameters[shipsPositionedSoFar].ShipDirection;
            var startingCoordinate = shipPositioningParameters[shipsPositionedSoFar].ShipCoordinate;

            var position = FindNextFreeSpace(workingSet, startingCoordinate, directionOfPositioning,
                                                 lengthOfNextShipToPosition);

            while (!position.HasValue)
            {
                position = FindNextFreeSpace(workingSet, BoardCoordinate.GetRandomCoordinateInFirstQuadrant(), directionOfPositioning,
                                             lengthOfNextShipToPosition);
            }

            // actual positioning of the ship
            PlaceShipOnMap(workingSet, lengthOfNextShipToPosition, directionOfPositioning, position.Value);
            PlaceShips(workingSet, shipPositioningParameters);
        }