Example #1
0
        public static Position FindObjectWithSameChar(IBoardObject[,] board, IBoardObject obj)
        {
            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    if (board[i, j].CharToDraw == (obj).CharToDraw)
                    {
                        return(new Position(i, j));
                    }
                }
            }

            return(new Position());
        }
Example #2
0
        public static Position FindObject(IBoardObject[,] board, IBoardObject obj)
        {
            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    if (board[i, j].Equals(obj))
                    {
                        return(new Position(i, j));
                    }
                }
            }

            return(new Position());
        }
Example #3
0
        public static IBoardObject[,] CreateBoard(string board, ref Position winPoint, string separator = "\r\n")
        {
            var rows = board.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries);

            if (rows.Select(z => z.Length).Distinct().Count() != 1)
            {
                throw new Exception($"Wrong test map '{board}'");
            }
            var result = new IBoardObject[rows[0].Length, rows.Length];

            for (var x = 0; x < rows[0].Length; x++)
            {
                for (var y = 0; y < rows.Length; y++)
                {
                    result[x, y] = ParseBySymbol(rows[x][y], x, y, ref winPoint);
                }
            }
            return(result);
        }
Example #4
0
        public static IBoardObject[,] Generate(int columns, int rows, List <Player> players, int numberOfPlayers)
        {
            IBoardObject[,] gameBoard = new IBoardObject[columns, rows];

            for (int i = 0; i < gameBoard.GetLength(0); i++) // Kanske göra detta till en metod eller för enhetstest eller populera arrayen någon annanstans
            {
                for (int j = 0; j < gameBoard.GetLength(1); j++)
                {
                    gameBoard[i, j] = new Path();
                }
            }

            gameBoard = PopulateWithNests(gameBoard, players); // Ytterligare en metod för population?
            gameBoard = PopulateWithEmptySpaces(gameBoard);
            //gameBoard = PopulateWithDoorWays(gameBoard, players);
            gameBoard = PopulateWithInnerPath(gameBoard, players, numberOfPlayers);
            gameBoard = PopulateWithGoal(gameBoard);


            return(gameBoard);
        }
Example #5
0
		void AddDisplayElement(IBoardObject boardElement)
		{
			var displayElement = CreateDisplayElement(boardElement);
			var element = new BoardDisplayElement();
			element.boardElement = boardElement;
			element.displayElement = displayElement;
			boardDispalyElements.Add(element);
			Grid.SetColumn(displayElement, boardElement.position.X);
			Grid.SetRow(displayElement, boardElement.position.Y);
			GameGrid.Children.Add(displayElement);
		}
Example #6
0
		UIElement CreateDisplayElement(IBoardObject boardElement)
		{
			var typeName = boardElement.GetType().Name;
			if (displayElementFactoryMap.ContainsKey(typeName))
				return displayElementFactoryMap[typeName](boardElement);

			throw new ApplicationException(string.Format("No display element defined for {0}", boardElement.GetType().ToString()));
		}
Example #7
0
 private void CreateBoardObj(Image img, IBoardObject obj, Position pos)
 {
     obj.Position        = new Position(pos.I, pos.J);
     Board[pos.I, pos.J] = obj;
     DrawBoardObject(img, pos.I, pos.J);
 }