Example #1
0
        // Recursive solution to go through grid and reveal open neighbors.
        public bool showNeighbors(GameBoardModel grid, int x, int y)
        {
            CellModel cell = grid.Cells[x, y];

            cell.IsVisited = true;

            if (cell.LiveNeighbors > 0)
            {
                return(false);
            }

            if (cell.Column - 1 >= 0)
            {
                var westLocation = grid.Cells[cell.Column - 1, cell.Row];

                if (!westLocation.IsLive && !westLocation.IsVisited)
                {
                    if (westLocation.LiveNeighbors == 0)
                    {
                        showNeighbors(grid, westLocation.Column, westLocation.Row);
                    }
                    else
                    {
                        westLocation.IsVisited = true;
                    }
                }
            }

            if (cell.Row - 1 >= 0)
            {
                var northLocation = grid.Cells[cell.Column, cell.Row - 1];

                if (!northLocation.IsLive && !northLocation.IsVisited)
                {
                    if (northLocation.LiveNeighbors == 0)
                    {
                        showNeighbors(grid, northLocation.Column, northLocation.Row);
                    }
                    else
                    {
                        northLocation.IsVisited = true;
                    }
                }
            }

            if (cell.Row + 1 < grid.Cols)
            {
                var southLocation = grid.Cells[cell.Column, cell.Row + 1];

                if (!southLocation.IsLive && !southLocation.IsVisited)
                {
                    if (southLocation.LiveNeighbors == 0)
                    {
                        showNeighbors(grid, southLocation.Column, southLocation.Row);
                    }
                    else
                    {
                        southLocation.IsVisited = true;
                    }
                }
            }

            if (cell.Column + 1 < grid.Rows)
            {
                var eastLocation = grid.Cells[cell.Column + 1, cell.Row];

                if (!eastLocation.IsLive && !eastLocation.IsVisited)
                {
                    if (eastLocation.LiveNeighbors == 0)
                    {
                        showNeighbors(grid, eastLocation.Column, eastLocation.Row);
                    }
                    else
                    {
                        eastLocation.IsVisited = true;
                    }
                }
            }

            return(false);
        }
Example #2
0
        public void TestLetters()
        {
            var letters = new GridModel(3, 3)
            {
                WordLengths = new List <int> {
                    3, 6
                }
            };

            letters[0, 0] = new CellModel(letters, 0, 0)
            {
                Value = "t"
            };
            letters[0, 1] = new CellModel(letters, 0, 1)
            {
                Value = "h"
            };
            letters[0, 2] = new CellModel(letters, 0, 2)
            {
                Value = "e"
            };
            letters[1, 0] = new CellModel(letters, 1, 0)
            {
                Value = "d"
            };
            letters[1, 1] = new CellModel(letters, 1, 1)
            {
                Value = "e"
            };
            letters[1, 2] = new CellModel(letters, 1, 2)
            {
                Value = "a"
            };
            letters[2, 0] = new CellModel(letters, 2, 0)
            {
                Value = "s"
            };
            letters[2, 1] = new CellModel(letters, 2, 1)
            {
                Value = "h"
            };
            letters[2, 2] = new CellModel(letters, 2, 2)
            {
                Value = "t"
            };

            var service = new WordsService();
            var combos  = service.GetLettersMinusWords(letters, new List <string> {
                "the"
            });

            var results = new HashSet <string>();

            foreach (var combo in combos)
            {
                var result = service.GetAllCandidateWords(combo, 1);
                if (result.Children.Any())
                {
                    foreach (var word in result.Children)
                    {
                        results.Add(word);
                    }
                }
            }

            Assert.IsTrue(results.Count > 0);
        }
Example #3
0
 private int HeuristicDistance(CellModel point, CellModel goal)
 {
     return((int)Vector3Int.Distance(point.Position, goal.Position));
 }
Example #4
0
 public CellMove(CellModel cell) : base(cell)
 {
     Value = cell.Value;
 }
Example #5
0
        public ActionResult Index()
        {
            var model = CellModel.GetCells();

            return(View(model));
        }
Example #6
0
 public void ColumnChanged(int index, CellModel cellModel, ColumnModel columnModel)
 {
     ColumnDeleted(index);
     ColumnAdded(index, cellModel, columnModel);
 }
 public PieceBaseModel(PieceColor color, CellModel cell)
 {
     Color   = color;
     Cell    = cell;
     IsMoved = false;
 }
Example #8
0
        /// <summary>
        ///		Añade una pieza
        /// </summary>
        public void Add(PieceBaseModel.PieceType piece, PieceBaseModel.PieceColor color, CellModel cell)
        {
            switch (piece)
            {
            case PieceBaseModel.PieceType.Pawn:
                Add(new PieceWithCellModel(new PawnModel(color), cell));
                break;

            case PieceBaseModel.PieceType.Rook:
                Add(new PieceWithCellModel(new RookModel(color), cell));
                break;

            case PieceBaseModel.PieceType.Knight:
                Add(new PieceWithCellModel(new KnightModel(color), cell));
                break;

            case PieceBaseModel.PieceType.Bishop:
                Add(new PieceWithCellModel(new BishopModel(color), cell));
                break;

            case PieceBaseModel.PieceType.Queen:
                Add(new PieceWithCellModel(new QueenModel(color), cell));
                break;

            case PieceBaseModel.PieceType.King:
                Add(new PieceWithCellModel(new KingModel(color), cell));
                break;
            }
        }
Example #9
0
    private void GenerateLine()
    {
        #region  择开始点

        if (_startY >= CellHeight - 1)
        {
            return;
        }
        while (cells[_startX, _startY].BlockType != BlockTypeEnum.Unused)
        {
            _startX += 2;
            if (_startX >= CellWidth - 1)
            {
                _startX  = 1;
                _startY += 2;

                // Stop if we've scanned the whole dungeon.
                if (_startY >= CellHeight - 1)
                {
                    return;
                }
            }
        }
        SetType(_startX, _startY, BlockTypeEnum.Floor, FloorColor);
        _startList.Add(new CellModel()
        {
            X = _startX, Y = _startY
        });
        #endregion

        while (_startList.Count > 0)
        {
            CellModel cell = _startList.Last();

            // See which adjacent cells are open.
            List <Dir> openDirs = new List <Dir>();

            //左
            if (InBounds(cell.X - 3, cell.Y))
            {
                if (cells[cell.X - 2, cell.Y].BlockType == BlockTypeEnum.Unused)
                {
                    openDirs.Add(Dir.Left);
                }
            }
            //右
            if (InBounds(cell.X + 3, cell.Y))
            {
                if (cells[cell.X + 2, cell.Y].BlockType == BlockTypeEnum.Unused)
                {
                    openDirs.Add(Dir.Right);
                }
            }
            //上
            if (InBounds(cell.X, cell.Y + 3))
            {
                if (cells[cell.X, cell.Y + 2].BlockType == BlockTypeEnum.Unused)
                {
                    openDirs.Add(Dir.Up);
                }
            }
            //下
            if (InBounds(cell.X, cell.Y - 3))
            {
                if (cells[cell.X, cell.Y - 2].BlockType == BlockTypeEnum.Unused)
                {
                    openDirs.Add(Dir.Down);
                }
            }
            if (openDirs.Count <= 0)
            {
                // No adjacent uncarved cells.
                _startList.Remove(cell);
                continue;
            }
            int rand = UnityEngine.Random.Range(0, 100);

            Dir dir = Dir.None;
            if (openDirs.Contains(_lastMazeDir) && rand > WIGGLE_PERCENT)
            {
                dir = _lastMazeDir;
            }
            else
            {
                int index = rand % openDirs.Count;
                dir = openDirs[index];
            }
            _lastMazeDir = dir;
            switch (dir)
            {
            case Dir.Up:
                _startList.Add(new CellModel()
                {
                    X = cell.X, Y = cell.Y + 2
                });
                SetType(cell.X, cell.Y + 1, BlockTypeEnum.Floor, FloorColor);
                SetType(cell.X, cell.Y + 2, BlockTypeEnum.Floor, FloorColor);
                break;

            case Dir.Down:
                _startList.Add(new CellModel()
                {
                    X = cell.X, Y = cell.Y - 2
                });
                SetType(cell.X, cell.Y - 1, BlockTypeEnum.Floor, FloorColor);
                SetType(cell.X, cell.Y - 2, BlockTypeEnum.Floor, FloorColor);
                break;

            case Dir.Left:
                _startList.Add(new CellModel()
                {
                    X = cell.X - 2, Y = cell.Y
                });
                SetType(cell.X - 1, cell.Y, BlockTypeEnum.Floor, FloorColor);
                SetType(cell.X - 2, cell.Y, BlockTypeEnum.Floor, FloorColor);
                break;

            case Dir.Right:
                _startList.Add(new CellModel()
                {
                    X = cell.X + 2, Y = cell.Y
                });
                SetType(cell.X + 1, cell.Y, BlockTypeEnum.Floor, FloorColor);
                SetType(cell.X + 2, cell.Y, BlockTypeEnum.Floor, FloorColor);
                break;
            }
        }
        GenerateLine();
        //FloodFill(1, 1, Dir.None);

        //for (int x = 0; x < CellWidth; x++)
        //{
        //    for (int y = 0; y < CellHeight; y++)
        //    {
        //        if (InBounds(x, y))
        //        {
        //            continue;
        //        }

        //    }
        //}
    }
Example #10
0
        public override void SetData(byte[] data)
        {
            try
            {
                if (data == null)
                {
                    return;
                }
                if (data[0] != Definitions.Device.Bqms.Head)
                {
                    return;
                }
                if (data[1] != Definitions.Device.Bqms.Id[0] || data[2] != Definitions.Device.Bqms.Id[1])
                {
                    return;
                }

                var canId = (Definitions.Device.Bqms.CanId)BitConverter.ToInt32(data, 3);
                switch (canId)
                {
                case Definitions.Device.Bqms.CanId.StringVCT:
                    Voltage = BitConverter.ToInt16(data, 7) * 0.1;
                    Current = (double)ExBitConverter.ToInt24(data, 9) * 0.1;
                    if (data[12] == 0)
                    {
                        var temperature = BitConverter.ToInt16(data, 13);
                        if (temperature == 0x7fff)
                        {
                            AmbientTemperature = null;
                        }
                        else
                        {
                            AmbientTemperature = temperature * 0.1;
                        }
                    }
                    else
                    {
                        RippleCurrent = BitConverter.ToInt16(data, 13) * 0.1;
                    }
                    return;

                case Definitions.Device.Bqms.CanId.StringGain:
                    VoltageGain   = data[8];
                    CurrentGain   = data[9];
                    CurrentOffset = (sbyte)data[10] * 0.1;
                    break;

                case Definitions.Device.Bqms.CanId.StartMeasureResistance:
                    IsMeasuring = true;
                    return;

                case Definitions.Device.Bqms.CanId.EndMeasureResistance:
                    IsMeasuring = false;
                    return;

                case Definitions.Device.Bqms.CanId.Version:
                    Version = $"{(int)data[7]}.{(int)data[8]}";
                    return;

                case Definitions.Device.Bqms.CanId.CellVoltagePeriod:
                    CellVoltagePeriod = BitConverter.ToInt16(data, 8);
                    return;

                case Definitions.Device.Bqms.CanId.CellResistancePeriod:
                    CellResistancePeriod = BitConverter.ToInt16(data, 8);
                    return;

                case Definitions.Device.Bqms.CanId.Discharge:
                    DisChargeCurrentDetect  = (double)ExBitConverter.ToInt24(data, 8) * 0.1;
                    DisChargeCurrentRelease = (double)ExBitConverter.ToInt24(data, 11) * 0.1;
                    return;

                case Definitions.Device.Bqms.CanId.UnitMax:
                    UnitMax = (int)data[8];
                    return;

                case Definitions.Device.Bqms.CanId.Deadband:
                    VoltageDeadband        = (double)data[8] * 0.1;
                    CurrentDeadband        = (double)data[9] * 0.1;
                    TemperatureDeadband    = (double)data[10] * 0.1;
                    RippleCurrentDeadband  = (double)data[11] * 0.1;
                    CellVoltageDeadband    = (double)data[12] * 0.01;
                    CellResistanceDeadband = (double)data[13] * 0.01;
                    break;

                case Definitions.Device.Bqms.CanId.OutContract:
                    var dryContactBitArray = new BitArray(new byte[2] {
                        data[7], data[8]
                    });
                    for (int i = 0; i < DryContact.Count(); i++)
                    {
                        if (dryContactBitArray.Count <= i)
                        {
                            DryContact[i] = false;
                        }
                        else
                        {
                            DryContact[i] = dryContactBitArray[i];
                        }
                    }

                    var inputSignalBitArray = new BitArray(new byte[1] {
                        data[9]
                    });
                    for (int i = 0; i < InputSignal.Count(); i++)
                    {
                        if (inputSignalBitArray.Count <= i)
                        {
                            InputSignal[i] = false;
                        }
                        else
                        {
                            InputSignal[i] = inputSignalBitArray[i];
                        }
                    }
                    var ledBitArray = new BitArray(new byte[1] {
                        data[10]
                    });
                    for (int i = 0; i < Led.Count(); i++)
                    {
                        if (ledBitArray.Count <= i)
                        {
                            Led[i] = false;
                        }
                        else
                        {
                            Led[i] = ledBitArray[i];
                        }
                    }
                    break;

                default:
                    break;
                }

                canId = (Definitions.Device.Bqms.CanId)(BitConverter.ToInt32(data, 3) & 0xFFFFFF00);

                int moduleNumber = data[3];
                if (moduleNumber < 1)
                {
                    return;
                }
                CellModel cell = null;

                switch (canId)
                {
                case Definitions.Device.Bqms.CanId.ChannelCount:
                    var channelModule = Modules.SingleOrDefault(r => r.Id == moduleNumber);
                    if (channelModule != null)
                    {
                        channelModule.ChannelCount = data[7];
                    }
                    break;

                case Definitions.Device.Bqms.CanId.VoltagePhaseCompensation:
                    var module            = Modules.SingleOrDefault(r => r.Id == moduleNumber);
                    var voltageOffset     = BitConverter.ToInt16(data, 8) * 0.001;
                    var phaseCompensation = ExBitConverter.ToInt24(data, 10) * 0.001;
                    if (module == null)
                    {
                        module = new ModuleModel
                        {
                            Id                = moduleNumber,
                            BankId            = Id,
                            VoltageOffset     = voltageOffset,
                            PhaseCompensation = phaseCompensation,
                            UpdateTime        = DateTime.Now
                        };
                        AddModule(module);
                    }
                    else
                    {
                        module.VoltageOffset     = voltageOffset;
                        module.PhaseCompensation = phaseCompensation;
                        module.UpdateTime        = DateTime.Now;
                    }
                    return;

                case Definitions.Device.Bqms.CanId.CellVoltage:
                    for (int i = 0; i < 4; i++)
                    {
                        var voltage = BitConverter.ToInt16(data, i * 2 + 7) * 0.001;
                        cell = Cells.SingleOrDefault(r => r.ModuleNumber == moduleNumber && r.Channel == i + 1);
                        if (cell == null)
                        {
                            cell = new CellModel
                            {
                                ModuleNumber = moduleNumber,
                                Channel      = i + 1,
                                Voltage      = voltage,
                                UpdateTime   = DateTime.Now
                            };
                            AddCell(cell);
                        }
                        else
                        {
                            cell.Voltage    = voltage;
                            cell.UpdateTime = DateTime.Now;
                        }

                        var tempModule = Modules.SingleOrDefault(r => r.Id == moduleNumber);
                        if (tempModule != null)
                        {
                            tempModule.Voltages[i] = voltage;
                        }
                    }
                    return;

                case Definitions.Device.Bqms.CanId.CellTemperature:
                    for (int i = 0; i < 4; i++)
                    {
                        double?temperature = BitConverter.ToInt16(data, i * 2 + 7);
                        if (temperature == 0x7FFF)
                        {
                            temperature = null;
                        }
                        else
                        {
                            temperature *= 0.1;
                        }
                        cell = Cells.SingleOrDefault(r => r.ModuleNumber == moduleNumber && r.Channel == i + 1);
                        if (cell == null)
                        {
                            AddCell(new CellModel
                            {
                                ModuleNumber = moduleNumber,
                                Channel      = i + 1,
                                Temperature  = temperature,
                                UpdateTime   = DateTime.Now
                            });
                        }
                        else
                        {
                            cell.Temperature = temperature;
                            cell.UpdateTime  = DateTime.Now;
                        }
                    }
                    return;

                case Definitions.Device.Bqms.CanId.CellResistance:
                    var    channel    = data[7];
                    double?resistance = ExBitConverter.ToInt24(data, 8);

                    if (resistance == 0x7FFFFF)
                    {
                        resistance = null;
                    }
                    else
                    {
                        resistance *= 0.001;
                    }
                    double resistanceOffset = BitConverter.ToInt16(data, 11) * 0.01;
                    cell = Cells.SingleOrDefault(r => r.ModuleNumber == moduleNumber && r.Channel == channel);
                    if (cell == null)
                    {
                        AddCell(new CellModel
                        {
                            ModuleNumber                = moduleNumber,
                            Channel                     = channel,
                            Resistance                  = resistance,
                            ResistanceOffset            = resistanceOffset,
                            MeasureResistanceUpdateTime = DateTime.Now,
                            UpdateTime                  = DateTime.Now
                        });
                    }
                    else
                    {
                        cell.Resistance                  = resistance;
                        cell.ResistanceOffset            = resistanceOffset;
                        cell.MeasureResistanceUpdateTime = DateTime.Now;
                        cell.UpdateTime                  = DateTime.Now;
                    }
                    return;

                case Definitions.Device.Bqms.CanId.ResistanceOffset:
                    for (int i = 0; i < 4; i++)
                    {
                        var offset = BitConverter.ToInt16(data, i * 2 + 7) * 0.01;
                        cell = Cells.SingleOrDefault(r => r.ModuleNumber == moduleNumber && r.Channel == i + 1);
                        if (cell == null)
                        {
                            cell = new CellModel
                            {
                                ModuleNumber     = moduleNumber,
                                Channel          = i + 1,
                                ResistanceOffset = offset,
                                UpdateTime       = DateTime.Now
                            };
                            AddCell(cell);
                        }
                        else
                        {
                            cell.ResistanceOffset = offset;
                            cell.UpdateTime       = DateTime.Now;
                        }
                    }
                    return;

                case Definitions.Device.Bqms.CanId.TestMeasure:
                    var receiveChannel = (byte)((data[8] >> 4) & 0x0F);
                    cell = Cells.SingleOrDefault(r => r.ModuleNumber == moduleNumber && r.Channel == receiveChannel);
                    var receiveGain = (byte)(data[8] & 0x0F);
                    if (cell == null)
                    {
                        cell = new CellModel
                        {
                            ModuleNumber = moduleNumber,
                            Channel      = receiveChannel,
                            Gain         = receiveGain,
                            UpdateTime   = DateTime.Now,
                            TestMeasureResistanceUpdateTime = DateTime.Now
                        };

                        if (data[7] == 0x01)
                        {
                            cell.ImpedanceVoltage = (double)ExBitConverter.ToInt24(data, 9) * 0.001;
                            cell.impedanceCurrent = (double)ExBitConverter.ToInt24(data, 12) * 0.001;
                        }
                        else
                        {
                            cell.Phase      = (double)ExBitConverter.ToInt24(data, 9) * 0.001;
                            cell.Resistance = (double)ExBitConverter.ToInt24(data, 12) * 0.001;
                        }
                        AddCell(cell);
                    }
                    else
                    {
                        cell.Gain = receiveGain;
                        if (data[7] == 0x01)
                        {
                            cell.ImpedanceVoltage = (double)ExBitConverter.ToInt24(data, 9) * 0.001;
                            cell.impedanceCurrent = (double)ExBitConverter.ToInt24(data, 12) * 0.001;
                        }
                        else
                        {
                            cell.Phase      = (double)ExBitConverter.ToInt24(data, 9) * 0.001;
                            cell.Resistance = (double)ExBitConverter.ToInt24(data, 12) * 0.001;
                        }
                        cell.UpdateTime = DateTime.Now;
                        cell.TestMeasureResistanceUpdateTime = DateTime.Now;
                    }
                    return;

                default:
                    break;
                }

                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Example #11
0
 internal void MoveUpdate(CellModel cellData)
 {
     Jump(cellData);
     //Animate()
 }
Example #12
0
        void montaGrid(Page page, int mes)
        {
            var Meses       = CurrentMes.AddMonths(-1);
            var mesAnterior = montaCalendario(Convert.ToInt32(Meses.Month)).Length;

            //MainPage para usar elementos do xaml sem usar Mensageria
            parent = page;
            //monta o vetor com quantos dias tem no mes.
            var a = montaCalendario(mes);
            //exibe o nome completo do mes atual
            var nomeMes = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(mes));

            TextoMes = nomeMes + " " + CurrentMes.Year;
            CalendarioGridModel.Clear();
            //Pega o dia da semana que começa o mes
            Days diaCOmecaMes = DiaSemanaComecaMes(mes);
            int  b = 1;
            int  i = 0, contCasasMesAnterior = 0, colunaMesAnterior = 0, controlador = 0;

            for (int linhas = 0; linhas < 6; linhas++)
            {
                for (int colunas = 0; colunas < 7; colunas++)
                {
                    if (i < a.Length)
                    {
                        CellModel dia = new CellModel()
                        {
                            Coluna = colunas,
                            Linha  = linhas,
                            Dia    = new DateTime(CurrentMes.Year, CurrentMes.Month, a[i]),
                            dados  = new DadosDia()
                            {
                                DiaValor    = a[i].ToString(),
                                DiaDaSemana = verificadia(colunas)
                            },
                            BackgroundColor = Color.DeepSkyBlue,
                            TextColor       = Color.White
                        };
                        //nomeMes + " " + CurrentMes.Year
                        dia.TapCommand = new Command(() => { TextoMes = nomeMes + " " + CurrentMes.Year; });
                        //Monta a primeira linha do grid
                        if (linhas == 0)
                        {
                            //Verifica se o dia 1 é igual ao dia que começa o mes
                            //Coluna 1 = Segunda, diaCOmecaMes se for terça é = 2 então ñ entrara na condição
                            if (dia.dados.DiaDaSemana >= diaCOmecaMes)
                            {
                                //Tirando sabado e domingo
                                if (dia.dados.DiaDaSemana != Days.Domingo && dia.dados.DiaDaSemana != Days.Sabado)
                                {
                                    CalendarioGridModel.Add(dia);
                                    i++;
                                }
                                else
                                {
                                    //Sabado e domingo
                                    CalendarioGridModel.Add(new CellModel()
                                    {
                                        Coluna = colunas,
                                        Linha  = linhas,
                                        Dia    = new DateTime(CurrentMes.Year, CurrentMes.Month, CurrentMes.Day)
                                        {
                                        },
                                        dados = new DadosDia()
                                        {
                                            DiaValor = a[i].ToString()
                                        },
                                        BackgroundColor = Color.White,
                                        TextColor       = Color.Black,
                                        TapCommand      = new Command(() => { TextoMes = nomeMes + " " + CurrentMes.Year; })
                                    });
                                    i++;
                                }
                            }
                            else
                            {
                                /******* MES ANTERIOR *****/
                                contCasasMesAnterior += 1;
                                colunaMesAnterior    += 1;
                                controlador          += 1;
                            }
                            if (linhas == 0 && dia.dados.DiaDaSemana >= diaCOmecaMes && controlador != 0)
                            {
                                var teste = contCasasMesAnterior;
                                /*Primeira Linha mes anterior */
                                for (int casasEmBranco = 0; casasEmBranco < teste; casasEmBranco++)
                                {
                                    CalendarioGridModel.Add(new CellModel()
                                    {
                                        Coluna = (teste - 1) - casasEmBranco,
                                        Linha  = 0,
                                        Dia    = new DateTime(CurrentMes.Year, CurrentMes.Month, CurrentMes.Day),
                                        dados  = new DadosDia()
                                        {
                                            DiaValor = mesAnterior.ToString()
                                        },
                                        BackgroundColor = Color.White,
                                        TextColor       = Color.Gray,
                                        TapCommand      = new Command(() =>
                                        {
                                            TextoMes   = nomeMes + " " + CurrentMes.Year;
                                            CurrentMes = CurrentMes.AddMonths(-1);
                                            montaGrid(page, CurrentMes.Month);
                                        })
                                    });
                                    colunaMesAnterior--;
                                    mesAnterior--;
                                    controlador--;
                                }
                            }
                        }
                        else
                        {
                            /**Talvez precisa tirar a lógica de sabado e domingo porque a cor da celular é de acordo se o médico tem plantão ou não
                             * BackGround Azul é escala e Amarelo é plantão */
                            //Restante do calendario apos a primeira linha do grid.
                            if (dia.dados.DiaDaSemana != Days.Domingo && dia.dados.DiaDaSemana != Days.Sabado)
                            {
                                //Dias tirando sabado e domingo
                                CalendarioGridModel.Add(dia);
                                i++;
                            }
                            else
                            {
                                //Sabado e domingo
                                CalendarioGridModel.Add(new CellModel()
                                {
                                    Coluna = colunas,
                                    Linha  = linhas,
                                    Dia    = new DateTime(CurrentMes.Year, CurrentMes.Month, CurrentMes.Day)
                                    {
                                    },
                                    dados = new DadosDia()
                                    {
                                        DiaValor = a[i].ToString()
                                    },
                                    BackgroundColor = Color.White,
                                    TextColor       = Color.Black,
                                    TapCommand      = new Command(() => { TextoMes = nomeMes + " " + CurrentMes.Year; })
                                });
                                i++;
                            }
                        }
                    }
                    else
                    {
                        /********** MES SEGUINTE **********/
                        CellModel dia = new CellModel()
                        {
                            Coluna = colunas,
                            Linha  = linhas,
                            Dia    = new DateTime(CurrentMes.Year, CurrentMes.Month, CurrentMes.Day),
                            dados  = new DadosDia()
                            {
                                DiaValor    = b.ToString(),
                                DiaDaSemana = verificadia(colunas)
                            },
                            TextColor = Color.Gray
                        };


                        dia.TapCommand = new Command(async() =>
                        {
                            CurrentMes = CurrentMes.AddMonths(1);
                            TextoMes   = nomeMes + " " + CurrentMes.Year;
                            montaGrid(page, CurrentMes.Month);
                            //dia.dados.DiaValor.ToString() + "/" + CurrentMes.Month.ToString() + "/" + CurrentMes.Year.ToString();
                        });
                        CalendarioGridModel.Add(dia);
                        b++;
                    }
                }
            }
        }
Example #13
0
 public QueenModel(PieceColor color, CellModel cell) : base(color, cell)
 {
 }
 public CellController(CellModel cell)
 {
     _cell = cell;
 }
 /// <summary>
 ///		Comprueba si la pieza se puede mover a una fila / columna
 /// </summary>
 public abstract bool CanMoveTo(GameBoardModel board, CellModel target, Movements.MovementFigureModel.MovementType type);
 public bool Init(CellModel cellModel)
 {
     this._clsCellModel = cellModel;
     this.SetStartPassedState(cellModel);
     return(true);
 }
        /// <summary>
        ///		Comprueba si es legal un movimiento a una posición: si está vacío o si puede capturar
        /// </summary>
        internal bool IsLegal(GameBoardModel board, CellModel target, Movements.MovementFigureModel.MovementType type)
        {
            PieceBaseModel piece = board.Pieces.GetPiece(target);

            return(piece == null || (type == Movements.MovementFigureModel.MovementType.Capture && piece != null && piece.Color != Color));
        }
Example #18
0
 /// <summary>
 ///		Comprueba si está vacía una celda
 /// </summary>
 public bool IsEmpty(CellModel cell)
 {
     return(GetPiece(cell) == null);
 }
Example #19
0
        private CellModel PrepareCellModel(TreeNode tNode)
        {
            var cell = new CellModel {
            };

            try
            {
                var contM = (tNode.Tag as ControlPropertyModel);
                switch (contM.ControlType.ToUpper())
                {
                case "LABEL":
                    var objlbl      = contM.Properties as LabelCellGridClass;
                    var parentLabel = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new LabelCell {
                        Text = objlbl.Name,
                        Font = new FontModel {
                            FontFamily = objlbl.LabelFont.FontFamily.Name, FontSize = objlbl.LabelFont.Size
                        },
                        Color = new ColorModel {
                            Type = "RGB", Blue = objlbl.LabelColor.B, Green = objlbl.LabelColor.G, Red = objlbl.LabelColor.R
                        },
                        ColSpan       = parentLabel.ColSpan,
                        RowSpan       = parentLabel.RowSpan,
                        PTop          = parentLabel.PTop,
                        PBottom       = parentLabel.PBottom,
                        PLeft         = parentLabel.PLeft,
                        PRight        = parentLabel.PRight,
                        BorderPattren = parentLabel.BorderPattren.ToString().Replace("_", ","),
                        ContentType   = "LABEL",
                        HAlign        = Master.Master.GetAlignmentNumber(parentLabel.HAlign),
                        VAlign        = Master.Master.GetAlignmentNumber(parentLabel.VAlign),
                        Height        = objlbl.Height
                    };

                    break;

                case "FIELD":
                    var objfld      = contM.Properties as FieldCellGridClass;
                    var parentField = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new FieldCell
                    {
                        DataFieldName = objfld.Name,
                        ModelName     = objfld.FieldModel,
                        Font          = new FontModel {
                            FontFamily = objfld.FieldFont.FontFamily.Name, FontSize = objfld.FieldFont.Size
                        },
                        Color = new ColorModel {
                            Type = "RGB", Blue = objfld.FieldColor.B, Green = objfld.FieldColor.G, Red = objfld.FieldColor.R
                        },
                        ColSpan       = parentField.ColSpan,
                        RowSpan       = parentField.RowSpan,
                        PTop          = parentField.PTop,
                        PBottom       = parentField.PBottom,
                        PLeft         = parentField.PLeft,
                        PRight        = parentField.PRight,
                        BorderPattren = parentField.BorderPattren.ToString().Replace("_", ","),
                        ContentType   = "FIELD",
                        HAlign        = Master.Master.GetAlignmentNumber(parentField.HAlign),
                        VAlign        = Master.Master.GetAlignmentNumber(parentField.VAlign),
                        Height        = objfld.Height
                    };
                    break;

                case "EMPTY":
                    var objempty    = contM.Properties as EmptyCellGridClass;
                    var parentEmpty = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new EmptyCell
                    {
                        Text          = objempty.Name,
                        ColSpan       = parentEmpty.ColSpan,
                        RowSpan       = parentEmpty.RowSpan,
                        PTop          = parentEmpty.PTop,
                        PBottom       = parentEmpty.PBottom,
                        PLeft         = parentEmpty.PLeft,
                        PRight        = parentEmpty.PRight,
                        BorderPattren = parentEmpty.BorderPattren.ToString().Replace("_", ","),
                        ContentType   = "EMPTYCELL",
                        HAlign        = Master.Master.GetAlignmentNumber(parentEmpty.HAlign),
                        VAlign        = Master.Master.GetAlignmentNumber(parentEmpty.VAlign)
                    };
                    break;

                case "TABLE":
                    var objtbl      = contM.Properties as TableGridClass;
                    var parentTable = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new TableCell {
                        ColSpan       = parentTable.ColSpan,
                        RowSpan       = parentTable.RowSpan,
                        PTop          = parentTable.PTop,
                        PBottom       = parentTable.PBottom,
                        PLeft         = parentTable.PLeft,
                        PRight        = parentTable.PRight,
                        BorderPattren = parentTable.BorderPattren.ToString().Replace("_", ","),
                        ContentType   = "TABLECELL",
                        TableHAlient  = Master.Master.GetAlignmentNumber(parentTable.HAlign),
                        TableVAlient  = Master.Master.GetAlignmentNumber(parentTable.VAlign),
                        tableModel    = PrepareMainTable(tNode)
                    };
                    break;

                case "IMAGEURL":
                    var objimgUrl = contM.Properties as ImageUrlCellGridClass;
                    var parentIU  = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new ImageUrlCell
                    {
                        Src           = objimgUrl.Src,
                        Scale         = objimgUrl.Scale,
                        ColSpan       = parentIU.ColSpan,
                        RowSpan       = parentIU.RowSpan,
                        PTop          = parentIU.PTop,
                        PBottom       = parentIU.PBottom,
                        PLeft         = parentIU.PLeft,
                        PRight        = parentIU.PRight,
                        BorderPattren = parentIU.BorderPattren.ToString().Replace("_", ","),
                        ContentType   = "IMAGEURL",
                        HAlign        = Master.Master.GetAlignmentNumber(parentIU.HAlign),
                        VAlign        = Master.Master.GetAlignmentNumber(parentIU.VAlign),
                        Height        = objimgUrl.Height
                    };
                    break;

                case "IMAGEBYTE":
                    var objImgByte = contM.Properties as ImageByteCellGridClass;
                    var parentIB   = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new ImageByteCell
                    {
                        ImageFieldName = objImgByte.Name,
                        ModelName      = objImgByte.ImageFieldModel,
                        Scale          = objImgByte.Scale,
                        ColSpan        = parentIB.ColSpan,
                        RowSpan        = parentIB.RowSpan,
                        PTop           = parentIB.PTop,
                        PBottom        = parentIB.PBottom,
                        PLeft          = parentIB.PLeft,
                        PRight         = parentIB.PRight,
                        BorderPattren  = parentIB.BorderPattren.ToString().Replace("_", ","),
                        ContentType    = "IMAGEBYTE",
                        HAlign         = Master.Master.GetAlignmentNumber(parentIB.HAlign),
                        VAlign         = Master.Master.GetAlignmentNumber(parentIB.VAlign),
                        Height         = objImgByte.Height
                    };
                    break;

                case "IMAGESUBURL":
                    var objImgSubUrl = contM.Properties as ImageSubUrlCellGridClass;
                    var parentISU    = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new ImageUrlSubHeaderCell
                    {
                        Src           = objImgSubUrl.Src,
                        Scale         = objImgSubUrl.Scale,
                        ColSpan       = parentISU.ColSpan,
                        RowSpan       = parentISU.RowSpan,
                        PTop          = parentISU.PTop,
                        PBottom       = parentISU.PBottom,
                        PLeft         = parentISU.PLeft,
                        PRight        = parentISU.PRight,
                        BorderPattren = parentISU.BorderPattren.ToString().Replace("_", ","),
                        ContentType   = "IMAGEURLSUB",
                        HAlign        = Master.Master.GetAlignmentNumber(parentISU.HAlign),
                        VAlign        = Master.Master.GetAlignmentNumber(parentISU.VAlign),
                        Height        = objImgSubUrl.Height
                    };
                    break;

                case "IMAGESUBBYTE":
                    var objImgSubByte = contM.Properties as ImageSubByteCellGridClass;
                    var parentISB     = (tNode.Parent.Tag as ControlPropertyModel).Properties as CellGridCalss;
                    cell = new ImageByteSubHeaderCell
                    {
                        ImageFieldName = objImgSubByte.Name,
                        ModelName      = objImgSubByte.ImageFieldModel,
                        Scale          = objImgSubByte.Scale,
                        ColSpan        = parentISB.ColSpan,
                        RowSpan        = parentISB.RowSpan,
                        PTop           = parentISB.PTop,
                        PBottom        = parentISB.PBottom,
                        PLeft          = parentISB.PLeft,
                        PRight         = parentISB.PRight,
                        BorderPattren  = parentISB.BorderPattren.ToString().Replace("_", ","),
                        ContentType    = "IMAGEBYTESUB",
                        HAlign         = Master.Master.GetAlignmentNumber(parentISB.HAlign),
                        VAlign         = Master.Master.GetAlignmentNumber(parentISB.VAlign),
                        Height         = objImgSubByte.Height
                    };
                    break;
                }
            }
            catch (Exception ex)
            {
            }
            return(cell);
        }
Example #20
0
        public ActionResult Create()
        {
            var model = new CellModel();

            return(View(model));
        }
Example #21
0
    public void SaveUserDataFile()
    {
        FlatBufferBuilder  fbb            = new FlatBufferBuilder(1024);
        Offset <PlayModel> playModeOffset = new Offset <PlayModel>();

        if (UserData.PlayData != null)
        {
            //lastParts
            int[] lastPartsCells = UserData.PlayData.LastParts.Cells;
            LastPartsModel.StartCellPartsArrayVector(fbb, lastPartsCells.Length);
            for (int i = lastPartsCells.Length - 1; i >= 0; i--)
            {
                fbb.AddInt(lastPartsCells[i]);
            }
            VectorOffset lastPartsCellsOffset = fbb.EndVector();

            LastPartsModel.StartLastPartsModel(fbb);
            LastPartsModel.AddAngleValue(fbb, UserData.PlayData.LastParts.AngleValue);
            LastPartsModel.AddCellPartsArray(fbb, lastPartsCellsOffset);
            Offset <LastPartsModel> lastPartsOffset = LastPartsModel.EndLastPartsModel(fbb);

            //cells
            Offset <int>[] cells = new Offset <int> [UserData.PlayData.LastParts.Cells.Length];

            Offset <CellModel>[] offsetCellModes = new Offset <CellModel> [GameConstants.CELL_ARRAY_SIZE * GameConstants.CELL_ARRAY_SIZE];
            int index = 0;
            for (int i = 0; i < GameConstants.CELL_ARRAY_SIZE; i++)
            {
                for (int j = 0; j < GameConstants.CELL_ARRAY_SIZE; j++)
                {
                    offsetCellModes[index] = CellModel.CreateCellModel(fbb, (short)i, (short)j, UserData.PlayData.Cells[i, j]);
                    index++;
                }
            }

            VectorOffset cellsVectorOffset = PlayModel.CreateCellArrayVector(fbb, offsetCellModes);

            //ItemUserCountArray
            int[] itemUseCountArray = UserData.PlayData.ItemUseCountInfo.ItemUseCountArray;
            PlayModel.StartItemUseCountArrayVector(fbb, itemUseCountArray.Length);
            for (int i = itemUseCountArray.Length - 1; i >= 0; i--)
            {
                Debug.Log((ItemType)i + " - " + itemUseCountArray[i]);
                fbb.AddInt(itemUseCountArray[i]);
            }
            VectorOffset itemUserCountArrayOffset = fbb.EndVector();

            //playmode
            PlayModel.StartPlayModel(fbb);
            PlayModel.AddScore(fbb, UserData.PlayData.Score);
            PlayModel.AddCoin(fbb, UserData.PlayData.Coin);
            PlayModel.AddAdContinueWatchCount(fbb, UserData.PlayData.AdContinueWatchCount);
            PlayModel.AddCellArray(fbb, cellsVectorOffset);
            PlayModel.AddLastPartsData(fbb, lastPartsOffset);
            PlayModel.AddItemUseCountArray(fbb, itemUserCountArrayOffset);
            playModeOffset = PlayModel.EndPlayModel(fbb);
        }

        StringOffset dailyRewardDayOffset   = fbb.CreateString(UserData.UserRewardInfo.DailyRewardDay);
        StringOffset coinBoxRewardDayoffset = fbb.CreateString(UserData.UserRewardInfo.CoinBoxRewardDay);

        UserModel.StartUserModel(fbb);
        UserModel.AddScore(fbb, UserData.Score);
        UserModel.AddCoin(fbb, UserData.Coin);
        UserModel.AddDailyRewardDay(fbb, dailyRewardDayOffset);
        UserModel.AddCoinBoxRewardDay(fbb, coinBoxRewardDayoffset);
        UserModel.AddCointBoxRewardCount(fbb, UserData.UserRewardInfo.CoinBoxRewardCount);
        UserModel.AddCointBoxRewardTimeStamp(fbb, UserData.UserRewardInfo.CointBoxRewardTimeStamp);
        UserModel.AddPlayData(fbb, playModeOffset);
        Offset <UserModel> userModelOffset = UserModel.EndUserModel(fbb);

        fbb.Finish(userModelOffset.Value);

        using (var ms = new MemoryStream(fbb.SizedByteArray()))
        {
            File.WriteAllBytes(GameConstants.SAVEFILE_PATH, ms.ToArray());

            Debug.Log("SaveUserDataFile File Write end ");
        }
    }
 public ActionPromoteModel(Pieces.PieceBaseModel.PieceType type, Pieces.PieceBaseModel.PieceColor color,
                           CellModel to) : base(type, color)
 {
     To = to;
 }
Example #23
0
        private void ButtonSteps_OnClick(object sender, RoutedEventArgs e)
        {
            DataContext          dataContext     = new DataContext(connectionString);
            Table <CellModel>    tableCellModels = dataContext.GetTable <CellModel>();
            Table <NumberOfGame> numberOfGames   = dataContext.GetTable <NumberOfGame>();
            var listNumber = numberOfGames.ToList();
            int ab         = listNumber.Count();

            var listNeedCell = tableCellModels.ToList();

            var number   = (from t in listNeedCell where t.NumberOfGame == ab select t).ToList <CellModel>();
            var donumber = (from t in listNeedCell where t.NumberOfGame == ab select t).ToList <CellModel>();

            //проходимся по всем строкам
            //foreach (DataRow row in dtdt.Rows)
            //{
            //    // получаем все ячейки строки
            //    foreach (DataRow rowrow in dtdt.Rows)
            //    {
            //        // получаем все ячейки строки
            //        var cells = row.ItemArray;

            //        foreach (object cell in cells)

            //    }

            //}



            foreach (var item in number)
            {
                var forcolumn = item.Column;
                var forrow    = item.Row;
                var fornumber = item.NumberOfGame;

                //циклы проверки соседей
                //var testColumn1 = p.Column - 1;
                //var testRow1 = p.Row - 1;
                //var testCR = dtdt.Rows[testColumn1][testRow1];



                var testColumn_1 = forcolumn - 1;
                var testRow_1    = forrow - 1;

                var testColumn__1 = forcolumn + 1;
                var testRow__1    = forrow + 1;

                //для ячейки: колонка 0 строка 0, проверка соседей
                if (testColumn_1 < 0 && testRow_1 < 0)
                {
                    //колонка та же, строка +
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }

                    //колонка +, строка +
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //колонка +, строка та же
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                // нулевая колонка, но не нулевая строка, при этом не крайняя колонка или не крайняя строка
                if (testColumn_1 < 0 && testRow_1 >= 0 && testRow__1 <= _qrow)
                {
                    //колонка та же, строка -     1
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //колонка та же, строка +             2
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //колонка +, строка-                3
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +                 4
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка +              5
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                // строка нулевая, при этом колонка не нулевая, но и не крайняя колонка
                if (testRow_1 < 0 && testColumn_1 >= 0 && testColumn__1 <= _column)
                {
                    //строка та же, колонка -              1
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -                     2
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка та же                3
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка +                    4
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +                 5
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //крайняя строка, крайняя колонка
                if (testRow__1 > _qrow && testColumn__1 > _column)
                {
                    //строка та же, колонка -
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка -
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка та же
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                // крайняя строка, но не крайняя колонка и не нулевая колонка
                if (testRow__1 > _qrow && testColumn__1 <= _column && testColumn_1 >= 0)
                {
                    //строка та же, колонка -         1
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка -               2
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка та же            3
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка +                 4
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +                5
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //нулевая колонка, крайняя строка
                if (testColumn_1 < 0 && testRow__1 > _qrow)
                {
                    //строка -, колонка та же
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }

                    //строка -, колонка +
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //крайняя колонка, нулевая строка
                if (testColumn__1 > _column && testRow_1 < 0)
                {
                    //строка та же, колонка -
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка та же
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                //крайняя колонка но не нулевая строка и не крайняя строка
                if (testColumn__1 > _column && testRow_1 >= 0 && testRow__1 <= _qrow)
                {
                    //строка -, колонка та же            1
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка -                   2
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка -                  3
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -                     4
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    // строка +, колонка та же                        5
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }
                if (testColumn_1 >= 0 && testRow_1 >= 0 && testColumn__1 <= _column && testRow__1 <= _qrow)
                {
                    //строка -, колонка -
                    var testCR_1_1 = dtdt.Rows[forrow - 1][forcolumn - 1];
                    if (testCR_1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка та же
                    var testCR_11 = dtdt.Rows[forrow - 1][forcolumn];
                    if (testCR_11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка -, колонка +
                    var testCR_1__1 = dtdt.Rows[forrow - 1][forcolumn + 1];
                    if (testCR_1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка -
                    var testCR1_1 = dtdt.Rows[forrow][forcolumn - 1];
                    if (testCR1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка та же, колонка +
                    var testCR1__1 = dtdt.Rows[forrow][forcolumn + 1];
                    if (testCR1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка -
                    var testCR__1_1 = dtdt.Rows[forrow + 1][forcolumn - 1];
                    if (testCR__1_1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка та же
                    var testCR__11 = dtdt.Rows[forrow + 1][forcolumn];
                    if (testCR__11.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                    //строка +, колонка +
                    var testCR__1__1 = dtdt.Rows[forrow + 1][forcolumn + 1];
                    if (testCR__1__1.ToString() != "")
                    {
                        item.Sosedi = item.Sosedi + 1;
                        CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                        cell1.Sosedi = item.Sosedi;
                        dataContext.SubmitChanges();
                    }
                }


                ////////////////////////////////////////////////////////////
                //////////////////////////////////////////
                ////////////////////////////
            }
            var numberfor = (from t in listNeedCell where t.NumberOfGame == ab select t).ToList <CellModel>();

            foreach (var item in numberfor)
            {
                //var itemstring = item.ValueOfCell.ToString();
                if (item.ValueOfCell == 0 && item.Sosedi == 3)
                {
                    dtdt.Rows[item.Row][item.Column] = "1";
                    item.ValueOfCell = 1;
                    CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                    cell1.ValueOfCell = item.ValueOfCell;
                    dataContext.SubmitChanges();
                }
                if (item.ValueOfCell != 0 && (item.Sosedi < 2 || item.Sosedi > 3))
                {
                    dtdt.Rows[item.Row][item.Column] = "";
                    item.ValueOfCell = 0;
                    CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Id == item.Id);
                    cell1.ValueOfCell = item.ValueOfCell;
                    dataContext.SubmitChanges();
                }
            }


            DataTable booksTable = new DataTable();

            //DataContext db = new DataContext(connectionString);
            //Table<CellModel> cellModelTable = db.GetTable<CellModel>();

            //booksTable = cellModelTable;
            //// NavigationService.Navigate(new CustomPlace(column, qrow));
            //CellModel cell = new CellModel();
            //p.ValueOfCell = 1;
            booksTable = dtdt;

            gridEmployees.DataContext = booksTable.DefaultView;
            var list = booksTable.Select().SelectMany(row => row.ItemArray).Select(x => (string)x).ToList();

            dtdt = booksTable;
            var qrowsindtdt  = dtdt.Rows.Count;
            var columnindtdt = dtdt.Columns.Count;

            for (int i = 0; i < qrowsindtdt; i++)
            {
                for (int b = 0; b < columnindtdt; b++)
                {
                    //dtdt.Rows[b][i] = "";

                    CellModel cell1 = dataContext.GetTable <CellModel>().FirstOrDefault(p => p.Column == b && p.Row == i && p.NumberOfGame == ab);

                    cell1.Sosedi = 0;

                    dataContext.SubmitChanges();
                }
            }
        }
Example #24
0
 public Move(CellModel cell)
 {
     Cell = cell;
 }
Example #25
0
        /// <summary>
        /// Gets a list of valid words of the specified length from the supplied <see cref="startCell"/>
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="startCell"></param>
        /// <param name="wordIndex"></param>
        /// <returns></returns>
        public List <CandidateWordModel> GetValidWords(GridModel grid, CellModel startCell, int wordIndex = 0)
        {
            var doneList    = new Dictionary <int, HashSet <CellModel> >();
            var currentCell = startCell;
            var words       = new List <CandidateWordModel>();
            var currentList = new List <CellModel> {
                currentCell
            };
            var completedCells = new List <CellModel>();

            var currentString = currentCell.Value;

            for (var i = 1; i < grid.WordLengths[wordIndex] - 1; i++)
            {
                if (!doneList.ContainsKey(i))
                {
                    doneList.Add(i, new HashSet <CellModel>());
                }
                var nextCell = currentCell.GetNextCell(currentList.Concat(completedCells).ToList());
                if (string.IsNullOrEmpty(nextCell?.Value))
                {
                    var done = false;
                    var last = currentList.Last();
                    currentList.Remove(last);
                    completedCells = new List <CellModel>();
                    doneList[i].Add(last);
                    if (currentList.Count == 0)
                    {
                        continue;
                    }
                    currentCell = currentList.Last().GetNextCell(doneList[i].Concat(currentList).ToList());
                    var n = i;
                    while (currentCell == null)
                    {
                        n--;
                        doneList[n].Add(currentList.Last());
                        for (var x = n + 1; x <= doneList.Count; x++)
                        {
                            doneList[x] = new HashSet <CellModel>();
                        }
                        currentList.Remove(currentList.Last());
                        if (!currentList.Any())
                        {
                            done = true;
                            break;
                        }
                        currentCell = currentList.Last().GetNextCell(doneList[n].Concat(currentList).ToList());
                    }
                    if (done)
                    {
                        break;
                    }
                    currentString = string.Concat(currentList.Select(c => c.Value));
                    i             = currentString.Length;
                    nextCell      = currentCell;
                }
                if (i == grid.WordLengths[wordIndex] - 2)
                {
                    foreach (var combo in nextCell.GetCombos(currentList))
                    {
                        var candidate = $"{currentString}{combo.Key}";
                        if (IsValidWord(candidate))
                        {
                            words.Add(new CandidateWordModel {
                                Candidate = candidate, Cells = currentList.Concat(combo.Value).ToList()
                            });
                        }
                    }
                    i = currentString.Length - 1;
                    completedCells.Add(nextCell);
                    currentCell = currentList.Last();
                }
                else
                {
                    currentString += nextCell.Value;
                    currentList.Add(nextCell);
                    currentCell = nextCell;
                }
            }


            return(words);
        }
Example #26
0
 public NoteMove(CellModel cell) : base(cell)
 {
     Value = cell.Notes.ToArray();
 }
Example #27
0
 public PieceWithCellModel(PieceBaseModel piece, CellModel cell)
 {
     Piece = piece;
     Cell  = cell;
 }