Ejemplo n.º 1
0
        private static bool HandleEndFieldsFromStartField(StartField startField, int fieldCount)
        {
            if (startField == null)
            {
                return(false);
            }
            fieldCount = Math.Abs(fieldCount);
            EndField endField = startField.EndFieldEntry;

            fieldCount--;
            for (int j = fieldCount; j > 0; j--)
            {
                endField = (EndField)endField.Next;
                if (endField == null)
                {
                    return(false);
                }
                if (endField.CurrentMeeple != null)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void TestChangeMeepleNegativeStartField()
        {
            GameTable       gameTable  = _hub.GetGeneratedGameTable(TableId);
            PlayerFieldArea greenArea  = gameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Green);
            PlayerFieldArea blueArea   = gameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue);
            StandardField   startField = greenArea.Fields[10] as StandardField;
            StartField      endField   = greenArea.Fields.Find(field => field.FieldType.Contains("StartField")) as StartField;
            Meeple          meeple1    = greenArea.Meeples[0];
            Meeple          meeple2    = blueArea.Meeples[0];

            meeple2.IsStartFieldBlocked = true;
            startField.CurrentMeeple    = meeple1;
            endField.CurrentMeeple      = meeple2;
            MeepleMove meepleMove = new MeepleMove()
            {
                Meeple          = meeple1,
                MoveDestination = endField
            };
            CardMove cardMove = new CardMove()
            {
                Card = _cardChange,
                SelectedAttribute = CardAttributeChangePlace
            };

            Assert.AreEqual(false, Validation.ValidateMove(meepleMove, cardMove));
        }
Ejemplo n.º 3
0
        public IField GetField(String type)
        {
            IField field;

            switch (type)
            {
            case "startfield":
                field = new StartField();
                break;

            case "field":
                field = new Field();
                break;

            case "forestfield":
                field = new ForestField();
                break;

            case "restfield":
                field = new RestField();
                break;

            case "finishfield":
                field = new FinishField();
                break;

            default:
                field = new Field();
                break;
            }
            return(field);
        }
Ejemplo n.º 4
0
 public IField GetField(String type)
 {
     IField field;
     switch (type)
     {
         case "startfield":
             field = new StartField();
             break;
         case "field":
             field = new Field();
             break;
         case "forestfield":
             field = new ForestField();
             break;
         case "restfield":
             field = new RestField();
             break;
         case "finishfield":
             field = new FinishField();
             break;
         default:
             field = new Field();
             break;
     }
     return field;
 }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedIndices.Count < 1)
            {
                AddOneRandomBrush();
            }
            else
            {
                brushesToSend.Clear();
                foreach (int index in checkedListBox1.CheckedIndices)
                {
                    brushesToSend.Add(brushes[index]);
                }
            }

            StartField startField = new StartField
                                    (
                starAmountToSend,
                changeSpeedToSend,
                brushesToSend.ToArray()
                                    );

            brushesToSend.Clear();
            startField.Show();
        }
Ejemplo n.º 6
0
        public void StartField_AddMoneyForStaty()
        {
            var startField = new StartField();
            var player     = new Player(1, "", "kamil", 1000, new Pawn("Red", 1, 0));

            startField.AddMoneyForStaty(player);
            Assert.AreEqual(player.Money, 2000);
        }
Ejemplo n.º 7
0
 public void InitPath()
 {
     StartField.InitPath();
     Path = StartField.Path;
     foreach (var move in Path)
     {
         move.Transfer();
     }
 }
 private void StartButton_Click(object sender, RoutedEventArgs e)
 {
     StartField.InitPath();
     _bfs.Path = StartField.Path;
     _bfs.InitPath();
     _bfs.Step();
     StartField.InitStartFieldCells();
     MessageBox.Show("Шлях був знайдений. Довжина=" + _bfs.Path.Count);
 }
Ejemplo n.º 9
0
 private void StartButton_Click(object sender, RoutedEventArgs e)
 {
     StartField.InitPath();
     _dfs.Path = StartField.Path;
     _dfs.InitPath();
     _dfs.Step();
     StartField.InitStartFieldCells();
     MessageBox.Show("Path was founded. Length=" + _dfs.Path.Count);
 }
Ejemplo n.º 10
0
        public void EnableTextField(bool enable)
        {
            StartField.UserInteractionEnabled = EndField.UserInteractionEnabled = enable;

            if (enable)
            {
                StartField.BecomeFirstResponder();
            }
        }
 private void ClearButton_Click(object sender, RoutedEventArgs e)
 {
     StartField.InitStartFieldCells();
     _bfs.StartField = StartField;
     _bfs.PathHistory.Clear();
     CheckerGrid.DataContext = null;
     CheckerGrid.DataContext = StartField;
     ResultRichTextBox.Document.Blocks.Clear();
 }
Ejemplo n.º 12
0
        public static bool IsValidStartField(MoveDestinationField field)
        {
            StartField startField = field as StartField;

            if (startField?.CurrentMeeple != null)
            {
                return(!startField.CurrentMeeple.IsStartFieldBlocked);
            }
            return(startField != null && startField.CurrentMeeple == null);
        }
Ejemplo n.º 13
0
        public void TestProveLeaveKennelEmptyDestinationField()
        {
            Meeple meeple  = new Meeple(new KennelField(1), ColorCode.Blue);
            Meeple meeple2 = new Meeple(new KennelField(2), ColorCode.Green);

            meeple.CurrentPosition = new KennelField(2);
            StartField field2 = new StartField(3, ColorCode.Blue);

            Assert.AreEqual(true, Validation.ProveLeaveKennel(meeple, field2));
        }
 public void InitPath()
 {
     //StartField = new CheckerField();
     StartField.InitStartFieldCells();
     //StartField.InitPath();
     //Path = StartField.Path;
     foreach (var move in Path)
     {
         move.Transfer();
     }
 }
Ejemplo n.º 15
0
        public void TestHasBlockedFieldBackwardsFromStart()
        {
            GameTable table = MakeInitialGameTable;
            //Meeple meeple = new Meeple(new KennelField(1), ColorCode.Blue);
            Meeple meeple2 = new Meeple(new KennelField(2), ColorCode.Blue)
            {
                IsStartFieldBlocked = true
            };
            StartField startField = (StartField)table.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue).Fields.Find(field => field.FieldType.Contains("StartField"));

            startField.CurrentMeeple = meeple2;
            Assert.AreEqual(false, Validation.HasBlockedField(startField, -4));
        }
Ejemplo n.º 16
0
        public void TestProveLeaveKennelNotSameColor()
        {
            Meeple meeple  = new Meeple(new KennelField(1), ColorCode.Red);
            Meeple meeple2 = new Meeple(new KennelField(2), ColorCode.Green);

            meeple.CurrentPosition = new KennelField(2);
            StartField field2 = new StartField(3, ColorCode.Blue)
            {
                CurrentMeeple = meeple2
            };

            Assert.AreEqual(false, Validation.ProveLeaveKennel(meeple, field2));
        }
Ejemplo n.º 17
0
        public void TestProveValueCardStandardFieldOverStartNotBlocked()
        {
            GameTable table   = MakeInitialGameTable;
            Meeple    meeple  = new Meeple(new KennelField(1), ColorCode.Blue);
            Meeple    meeple2 = new Meeple(new KennelField(2), ColorCode.Blue)
            {
                IsStartFieldBlocked = false
            };
            StartField startField = (StartField)table.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue).Fields.Find(field => field.FieldType.Contains("StartField"));

            startField.CurrentMeeple = meeple2;
            StandardField standardField = (StandardField)table.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue).Fields.Find(field => field.FieldType.Contains("StandardField"));

            standardField.CurrentMeeple = meeple;
            Assert.AreEqual(true, Validation.ProveValueCard(meeple, (StartField)table.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue).Fields[4], 4));
        }
Ejemplo n.º 18
0
        public void TestProveLeaveKennelBlockedStartField()
        {
            Meeple meeple  = new Meeple(new KennelField(1), ColorCode.Red);
            Meeple meeple2 = new Meeple(new KennelField(2), ColorCode.Green)
            {
                IsStartFieldBlocked = true
            };

            meeple.CurrentPosition = new KennelField(2);
            StartField field2 = new StartField(3, ColorCode.Red)
            {
                CurrentMeeple = meeple2
            };

            Assert.AreEqual(false, Validation.ProveLeaveKennel(meeple, field2));
        }
Ejemplo n.º 19
0
        public void TestProveChangePlaceStandardFieldAndStartField()
        {
            Meeple meeple  = new Meeple(new KennelField(1), ColorCode.Blue);
            Meeple meeple2 = new Meeple(new KennelField(2), ColorCode.Green)
            {
                IsStartFieldBlocked = false
            };

            meeple.CurrentPosition = new StandardField(2);
            StartField field2 = new StartField(3, ColorCode.Blue)
            {
                CurrentMeeple = meeple2
            };

            Assert.AreEqual(true, Validation.ProveChangePlace(meeple, field2));
        }
Ejemplo n.º 20
0
        public void TestCanNotMoveToEndFields()
        {
            GameTable table   = MakeInitialGameTable;
            Meeple    meeple  = new Meeple(new KennelField(1), ColorCode.Blue);
            Meeple    meeple2 = new Meeple(new KennelField(2), ColorCode.Blue)
            {
                IsStartFieldBlocked = true
            };
            StartField startField = (StartField)table.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue).Fields.Find(field => field.FieldType.Contains("StartField"));

            startField.CurrentMeeple = meeple2;
            StandardField standardField =
                (StandardField)table.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue).Fields[7];

            standardField.CurrentMeeple = meeple;
            Assert.AreEqual(false, Validation.CanMoveToEndFields(standardField, 8, meeple.ColorCode));
        }
Ejemplo n.º 21
0
        public static bool ProveLeaveKennel(Meeple moveMeeple, MoveDestinationField destinationField)
        {
            if (!moveMeeple.CurrentPosition.FieldType.Contains("KennelField"))
            {
                return(false);
            }
            if (!destinationField.FieldType.Contains("StartField"))
            {
                return(false);
            }
            StartField startField = destinationField as StartField;

            if (startField != null && !IsSameColorCode(startField.ColorCode, moveMeeple.ColorCode))
            {
                return(false);
            }
            return(destinationField.CurrentMeeple == null || IsValidStartField(destinationField));
        }
Ejemplo n.º 22
0
        public static bool HasBlockedField(MoveDestinationField startCountField, int countFields)
        {
            if (startCountField == null)
            {
                return(true);
            }
            if (startCountField.FieldType.Contains("StartField"))
            {
                return(false);
            }
            int fieldCounter = Math.Abs(countFields);

            for (int i = 0; i < fieldCounter; i++)
            {
                if (startCountField == null)
                {
                    return(false);
                }
                while (startCountField.FieldType.Contains("EndField"))
                {
                    startCountField = countFields > 0 ? startCountField.Next : startCountField.Previous;
                    fieldCounter--;
                    if (startCountField == null)
                    {
                        return(fieldCounter == i);
                    }
                    if (startCountField.FieldType.Contains("EndField"))
                    {
                        return(startCountField.CurrentMeeple != null);
                    }
                }

                StartField startField = startCountField as StartField;
                if (startField != null)
                {
                    return(startField.CurrentMeeple != null && startField.CurrentMeeple.IsStartFieldBlocked);
                }

                startCountField = countFields > 0 ? startCountField.Next : startCountField.Previous;
            }
            return(false);
        }
        public void Step()
        {
            //if (StartField.Equals(FinalField)) return;
            Cell        freeCell       = StartField.Cells.First(x => x.Content == null);
            List <Move> availableMoves = StartField.Moves.Where(x => x.HasCell(freeCell)).ToList();

            AllPathes = availableMoves.Select(x => new List <Move> {
                x
            }).ToList();

            while (AllPathes.Count > 0)
            {
                Path = AllPathes[0];
                AllPathes.RemoveAt(0);
                InitPath();
                if (StartField.Equals(FinalField))
                {
                    return;
                }
                freeCell       = StartField.Cells.First(x => x.Content == null);
                availableMoves = StartField.Moves.Where(x => x.HasCell(freeCell)).ToList();
                var moves = new List <Move>();
                foreach (var move in availableMoves)
                {
                    if (move.Checker.Moves.Exists(x => x.Equals(move)))
                    {
                        continue;
                    }
                    moves.Add(move);
                }
                availableMoves = moves;
                AllPathes.AddRange(availableMoves.Select(x =>
                {
                    var path = Path.ToList();
                    path.Add(x);
                    return(path);
                }).ToList());
            }

            Path.Clear();
            AllPathes.Clear();
        }
Ejemplo n.º 24
0
        public void TestProveChangePlaceStartfFieldBlocked()
        {
            Meeple meeple = new Meeple(new KennelField(1), ColorCode.Green)
            {
                IsStartFieldBlocked = true
            };
            Meeple meeple2 = new Meeple(new KennelField(2), ColorCode.Blue)
            {
                IsStartFieldBlocked = false
            };
            StartField field = new StartField(1, ColorCode.Green)
            {
                CurrentMeeple = meeple
            };
            StartField field2 = new StartField(2, ColorCode.Blue)
            {
                CurrentMeeple = meeple2
            };

            Assert.AreEqual(false, Validation.ProveChangePlace(meeple, field2));
        }
Ejemplo n.º 25
0
        public void TestLeaveKennel()
        {
            GameTable       gameTable   = _hub.GetGeneratedGameTable(TableId);
            PlayerFieldArea greenArea   = gameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Green);
            KennelField     kennelField = greenArea.KennelFields[0] as KennelField;
            StartField      endField    = greenArea.Fields.Find(field => field.FieldType.Contains("StartField")) as StartField;
            Meeple          meeple      = greenArea.Meeples[0];

            meeple.CurrentPosition = kennelField;
            MeepleMove meepleMove = new MeepleMove()
            {
                Meeple          = meeple,
                MoveDestination = endField
            };
            CardMove cardMove = new CardMove()
            {
                Card = _card11,
                SelectedAttribute = CardAttributeLeaveKennel
            };

            Assert.AreEqual(true, Validation.ValidateMove(meepleMove, cardMove));
        }
Ejemplo n.º 26
0
        public void Step()
        {
            if (StartField.Equals(FinalField))
            {
                return;
            }
            Cell        freeCell       = StartField.Cells.First(x => x.Content == null);
            List <Move> availableMoves = StartField.Moves.Where(x => x.HasCell(freeCell)).ToList();

            foreach (var move in availableMoves)
            {
                if (move.Checker.Moves.Exists(x => x.Equals(move)))
                {
                    continue;
                }
                Path.Add(move);
                move.Transfer();

                if (StartField.Equals(FinalField))
                {
                    return;
                }
                #region Rollback
                if (Path.Count > 15)
                {
                    Path.RemoveAt(Path.Count - 1);
                    move.RollBack();
                    return;
                }
                #endregion
                Step();
                if (StartField.Equals(FinalField))
                {
                    return;
                }
                Path.RemoveAt(Path.Count - 1);
                move.RollBack();
            }
        }
Ejemplo n.º 27
0
        public static bool CanMoveToEndFields(MoveDestinationField startCountField, int fieldDistanceCount, ColorCode meepleColorCode)
        {
            if (startCountField.FieldType.Contains("EndField"))
            {
                return(HandleEndFieldsFromEndField((EndField)startCountField, fieldDistanceCount));
            }
            if (HasBlockedField(startCountField, fieldDistanceCount))
            {
                return(false);
            }
            if (startCountField.FieldType.Contains("StartField") &&
                !startCountField.CurrentMeeple.IsStartFieldBlocked)
            {
                return(false);
            }
            int fieldCount = Math.Abs(fieldDistanceCount);

            for (int i = 0; i < fieldCount; i++)
            {
                if (startCountField == null)
                {
                    return(false);
                }
                startCountField = fieldDistanceCount > 0 ? startCountField.Next : startCountField.Previous;

                StartField startField = startCountField as StartField;
                if (startField == null)
                {
                    continue;
                }
                if (HandleEndFieldsFromStartField(startField, fieldCount - i - 1))
                {
                    return(startField.ColorCode == meepleColorCode);
                }
                return(false);
            }
            return(false);
        }
Ejemplo n.º 28
0
        public void CreateStartField()
        {
            var expected = new StartField();

            Assert.IsNotNull(expected);
        }
 public StartControl(StartField startField)
 {
     this.InitializeComponent();
     this.DataContext = startField;
 }
Ejemplo n.º 30
0
 protected Ship(OrientationType orientation, GameField startField)
 {
     Orientation = orientation;
     StartField  = startField ?? throw new ArgumentNullException(nameof(startField));
     Fields      = StartField.Expand(Orientation, Size);
 }
Ejemplo n.º 31
0
 protected override void init()
 {
     instance = this;
 }