コード例 #1
0
 public void MoveToCell(Cell toGo)
 {
     if (this.CurrentCell != null)
     {
         this.CurrentCell.RemovePawn();
     }
     this.CurrentCell = toGo;
     toGo.Pawn = this;
 }
コード例 #2
0
 public void MoveToCell(Cell toGo)
 {
     if (this.CurrentCell != null)
     {
         this.CurrentCell.RemoveBarricade();
     }
     this.CurrentCell = toGo;
     toGo.Barricade = this;
 }
コード例 #3
0
 public CellViewModel(Cell associatedCell)
 {
     _associatedCell = associatedCell;
     associatedCell.CellStateChanged += associatedCell_CellStateChanged;
     if (associatedCell is FinishCell)
     {
         FinishCell temp = (FinishCell)associatedCell;
         temp.GameWon += associatedCell_GameWon;
     }
     UpdateCellView();
 }
        public static List<CellViewModel> ConvertToCellViewModels(Cell[,] cells)
        {
            List<CellViewModel> temp = new List<CellViewModel>();
            //double[] tmp = new double[cells.GetLength(0) * cells.GetLength(1)];
            //Buffer.BlockCopy(cells, 0, tmp, 0, tmp.Length * sizeof(double));
            //List<Cell> list = new List<double>(tmp);

            foreach (Cell c in cells)
            {
                if (c != null)
                    temp.Add(new CellViewModel(c));
            }
            return temp;
        }
コード例 #5
0
        public void ParseBarFile()
        {
            string[] file = File.ReadAllLines(fileNamePath);

            StateManager = new GameStateManager();
            Map = new Cell[20, 17];

            var getX = new Func<int, int>(x => (x - 3) / 3);
            var getY = new Func<int, int>(y => (int)Math.Ceiling(((decimal)(y - 0 + 1) / 2)) - 1);

            for (var i = 0; i < file.Length; i++)
            {
                if (file[i].Length < 2) continue;

                var line = file[i];

                var isVillage = line.Substring(0, 2).Contains("1");
                var isProtected = line.Substring(0, 2).Contains("N");

                for (var j = 3; j < line.Length; j++)
                {
                    var letter = line[j];
                    if (new[] { '<', '(', '[', '{', '|' }.Contains(letter))
                    {
                        string letters;
                        if (letter == '|')
                            letters = line.Substring(j - 1, 3);
                        else
                            letters = line.Substring(j, 3);

                        int y = i;
                        int x = getX(j + 1);

                        Cell temp = ParseCell(letters, isProtected, isVillage);
                        temp.Location = new Point(x, y);
                        Map[y, x] = temp;

                        j += 2;
                    }
                }
            }
            LinkCells(Map);

            StateManager.Players = players;
            StateManager.StartingCells = startingCells;
        }
コード例 #6
0
 public async void getAllPosibilitiesAsync(Cell c)
 {
     await Task.Run(() => getAllPosibilities(c,Depth,null));
     foreach (Cell n in PossibleCells)
     {
         n.OnCellStateChanged(EventArgs.Empty);
     }
     foreach (Pawn p in currentPlayer.Pawns)
     {
         p.CurrentCell.OnCellStateChanged(EventArgs.Empty);
     }
 }
コード例 #7
0
        internal void SecondCellSelected(Cell cell)
        {
            if (SelectedBarricade != null)
            {
                SelectedBarricade.MoveToCell(cell);
                SelectedBarricade = null;
                SelectedCell.isSelected = false;
                cell.isSelected = false;
                Cell t = SelectedCell;
                SelectedCell = null;
                t.OnCellStateChanged(EventArgs.Empty);
                OnGameStateChanged(EventArgs.Empty);
                List<Pawn> oldpawns = currentPlayer.Pawns;
                toNextPlayer();

                foreach (Pawn p in oldpawns)
                {
                    p.CurrentCell.OnCellStateChanged(EventArgs.Empty);
                }
                foreach (Pawn p in currentPlayer.Pawns)
                {
                    p.CurrentCell.OnCellStateChanged(EventArgs.Empty);
                }
                DiceThrown = false;
                OnDiceCanBeThrown(EventArgs.Empty);
            }
            else if (cell.Barricade != null)
            {
                SelectedCell.Pawn.MoveToCell(cell);
                SelectedCell.isSelected = false;
                cell.isSelected = true;

                Cell t = SelectedCell;
                SelectedCell = cell;
                SelectedBarricade = cell.Barricade;
                t.OnCellStateChanged(EventArgs.Empty);
                cell.OnCellStateChanged(EventArgs.Empty);
                ClearPossiblities();
                OnGameStateChanged(EventArgs.Empty);
            }
            else
            {
                SelectedCell.Pawn.MoveToCell(cell);
                SelectedCell.isSelected = false;
                cell.isSelected = false;

                Cell t = SelectedCell;
                SelectedCell = null;
                t.OnCellStateChanged(EventArgs.Empty);
                cell.OnCellStateChanged(EventArgs.Empty);
                ClearPossiblities();
                List<Pawn> oldpawns = currentPlayer.Pawns;
                toNextPlayer();

                foreach (Pawn p in oldpawns)
                {
                    p.CurrentCell.OnCellStateChanged(EventArgs.Empty);
                }
                foreach (Pawn p in currentPlayer.Pawns)
                {
                    p.CurrentCell.OnCellStateChanged(EventArgs.Empty);
                }
                DiceThrown = false;
                OnDiceCanBeThrown(EventArgs.Empty);
            }
        }
コード例 #8
0
        private void getAllPosibilities(Cell c, int depth, Cell previousField)
        {
            if (depth == 0)
            {
                if (c.CanEntityOnMeGetHit && !PossibleCells.Contains(c))
                {
                        PossibleCells.Add(c);
                }
                return;
            }

            foreach (Direction index in Enum.GetValues(typeof(Direction)))
            {
                if (c[index] != null && previousField != c[index] && c[index].IsOccupiableByPawn && !c.IsOccupiedByBarricade)
                {
                    this.getAllPosibilities(c[index], depth - 1, c);
                }
            }
        }
コード例 #9
0
 void associatedCell_CellStateChanged(Cell sender, EventArgs e)
 {
     UpdateCellView();
 }
コード例 #10
0
 private Cell ParseCell(string letters, bool isProtected, bool isVillage)
 {
     Cell cell;
     if (letters[0] == '(' && letters[2] == ')')
     {
         cell = new Cell(StateManager);
         if (new[] { 'R', 'G', 'Y', 'B' }.Contains(letters[1]))
         {
             cell.Pawn = getPlayer(letters[1].ToString().ToUpper()).AddPawn();
             cell.Pawn.CurrentCell = cell;
         }
         if (new[] { '*' }.Contains(letters[1]))
             cell.Barricade = new Model.MovableEntities.Barricade(cell);
     }
     else if (letters[0] == '[' && letters[2] == ']')
     {
         cell = new BarricadeCell(StateManager);
         if (new[] { 'R', 'G', 'Y', 'B' }.Contains(letters[1]))
         {
             cell.Pawn = getPlayer(letters[1].ToString().ToUpper()).AddPawn();
             cell.Pawn.CurrentCell = cell;
         }
         if (letters[1] == '*')
         {
             Barricade b = new Barricade(cell);
             cell.Barricade = b;
         }
     }
     else if (letters[0] == '{' && letters[2] == '}')
     {
         cell = new RestingCell(StateManager);
         if (new[] { 'R', 'G', 'Y', 'B' }.Contains(letters[1]))
         {
             cell.Pawn = getPlayer(letters[1].ToString().ToUpper()).AddPawn();
             cell.Pawn.CurrentCell = cell;
         }
     }
     else if (letters[0] == '<' && letters[2] == '>')
     {
         if (letters[1] == ' ')
             cell = new FinishCell(StateManager);
         else if (new[] { 'R', 'G', 'Y', 'B', 'r', 'g', 'y', 'b' }.Contains(letters[1]))
         {
             cell = new StartingCell(StateManager,getPlayer(letters[1].ToString().ToUpper()));
             List<Cell> startCells = GetStartingCellsForPlayer(getPlayer(letters[1].ToString().ToUpper()));
             startCells.Add(cell);
             if (new[] { 'R', 'G', 'Y', 'B' }.Contains(letters[1]))
             {
                 cell.Pawn = getPlayer(letters[1].ToString().ToUpper()).AddPawn();
                 cell.Pawn.CurrentCell = cell;
             }
         }
         else
             cell = new Cell(StateManager);
     }
     else if (letters[1] == '|')
     {
         cell = new ConnectionCell(StateManager);
     }
     //temp
     else
     {
         cell = new Cell(StateManager);
     }
     cell.IsOccupiableByBarricade = !isProtected;
     cell.ShouldEntityMoveToForestWhenHit = isVillage;
     return cell;
 }
コード例 #11
0
 private void LinkCells(Cell[,] Map)
 {
     for (int i = 0; i < Map.GetLength(0); i++)
     {
         for (int j = 0; j < Map.GetLength(1); j++)
         {
             var field = Map[i, j];
             if (field != null)
             {
                 if (j > 0)
                 {
                     Cell v = Map[i, j - 1];
                     field[Direction.WEST] = v;
                 }
                 if (j < Map.GetLength(1) - 1)
                 {
                     Cell v2 = Map[i, j + 1];
                     field[Direction.EAST] = v2;
                 }
                 if (i > 0)
                 {
                     Cell field2 = Map[i - 1, j];
                     if(field2 is StartingCell)
                     {
                         int temp = i;
                         while (field2 is StartingCell)
                         {
                             field2 = Map[temp - 1, j];
                             temp--;
                         }
                         field[Direction.NORTH] = field2;
                     }
                     else if (field2 is ConnectionCell)
                         field[Direction.NORTH] = Map[i - 2, j];
                     else
                         field[Direction.NORTH] = field2;
                 }
                 if (i < Map.GetLength(0) - 1)
                 {
                     Cell field3 = Map[i + 1, j];
                     if (field3 is ConnectionCell)
                         field[Direction.SOUTH] = Map[i + 2, j];
                     else
                         field[Direction.SOUTH] = field3;
                 }
             }
         }
     }
 }
コード例 #12
0
 public Barricade(Cell cell)
 {
     CurrentCell = cell;
 }