public void LabyrinthMoveUpTest()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            string[] rawData = new string[Labyrinth.LabyrinthSize]
            {
                "XXXXXXX",
                "X-X---X",
                "X---X-X",
                "X--*--X",
                "X-X----",
                "X-----X",
                "XXXXXXX"
            };
            Cell[,] board = LabyrinthDataFromStringArray(rawData);
            Labyrinth labyrinth = new Labyrinth(startPosition, board);
            var privateObject = new PrivateObject(labyrinth);
            privateObject.Invoke("ProcessMoveUp", 3, 3);
            string result =
                @"X X X X X X X 
X - X - - - X 
X - - * X - X 
X - - - - - X 
X - X - - - - 
X - - - - - X 
X X X X X X X 
";
            string expected = labyrinth.ToString();

            Assert.AreEqual(expected, result);                       
        }
Ejemplo n.º 2
0
        public void IsWonWithEscapeFalse()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);

            string[] rawData = new string[Labyrinth.LabyrinthSize]
            {
                "XXXXXXX",
                "X-X---X",
                "X---X-X",
                "X--*--X",
                "X-X---X",
                "X-----X",
                "XXXXXXX"
            };

            Cell[,] board = LabyrinthDataFromStringArray(rawData);

            Labyrinth labyrinth = new Labyrinth(startPosition, board);



            var result = labyrinth.IsWonWithEscape;

            Assert.AreEqual(false, result);
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            // We are given a matrix of passable and non-passable cells.
            // Write a recursive program for finding all paths between two cells in the matrix.

            // Modify the above program to check whether a path exists between two cells without finding all possible paths.
            // Test it over an empty 100 x 100 matrix.
            char[,] matrix =
            {
                { ' ', ' ', ' ', '*', ' ', ' ', ' ' },
                { '*', '*', ' ', '*', ' ', '*', ' ' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { ' ', '*', '*', '*', '*', '*', ' ' },
                { ' ', ' ', ' ', ' ', ' ', ' ', 'e' },
            };

            char[,] matrix1 =
            {
                { ' ', ' ', ' ' },
                { ' ', ' ', ' ' },
                { ' ', ' ', 'e' },
            };

            char[,] matrix2 = new char[100, 100];
            matrix2[99, 99] = 'e';

            var lab = new Labyrinth(matrix2);

            lab.FindPaths(0, 0, 'S');
        }
Ejemplo n.º 4
0
        protected void right()
        {
            int bInf;
            int car;

            // on essai d'aller a DROITE
            if (moved || (ghost.getOldDirection().isLeft() && !ghost.State.isHouse()))
            {
                return;
            }
            if (xLabyGhost >= 27)
            {
                car = 0;
            }
            else
            {
                car = Labyrinth.getCurrent().get(xLabyGhost + 1, yLabyGhost);
            }
            bInf = 3 + ((ghost.State.isEye() || ghost.State.isHouse()) ? 1 : 0);
            if (car < bInf)
            {
                newDirection = Direction.Right;
                moved        = true;
            }
        }
        public static void Main()
        {
            char[,] matrix =
            {
                { ' ', ' ', ' ', '*', ' ', ' ', ' ' },
                { '*', '*', ' ', '*', ' ', '*', ' ' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { ' ', '*', '*', '*', '*', '*', ' ' },
                { ' ', ' ', ' ', ' ', ' ', ' ', 'e' },
            };

            char[,] matrix1 =
            {
                { ' ', ' ', ' ' },
                { ' ', ' ', ' ' },
                { ' ', ' ', 'e' },
            };

            char[,] matrix2 = new char[100, 100];
            matrix2[99, 99] = 'e';

            var lab = new Labyrinth(matrix2);

            lab.FindPaths(0, 0, 'S');
        }
Ejemplo n.º 6
0
        public void GenerateObjectsNew(Labyrinth labyrinth)
        {
            for (int i = 0; i < labyrinth.Rows; i++)
            {
                for (int j = 0; j < labyrinth.Columns; j++)
                {
                    int         randomNumber = this.randomGenerator.Next(2);
                    IGameObject currentObject;

                    if (randomNumber == 1)
                    {
                        currentObject = labyrinth.ObjectFactory.GetObstacle();
                    }
                    else
                    {
                        currentObject = labyrinth.ObjectFactory.GetFreeSpace();
                    }

                    labyrinth[i, j] = currentObject;
                }
            }

            labyrinth[labyrinth.StartPosition] = labyrinth.ObjectFactory.GetPlayerCell();



            // bool thereIsWayOut = labyrinth.SolutionChecker(this.StartPosition);

            //if (!thereIsWayOut)
            //{
            //    ObstaclesGenerator(labyrinth);
            //}
        }
Ejemplo n.º 7
0
        public void Move(Directions direction, Labyrinth labyrinth)
        {
            Coords newPosition = this.Position;

            switch (direction)
            {
            case Directions.Up:
                newPosition.Y--;
                break;

            case Directions.Down:
                newPosition.Y++;
                break;

            case Directions.Left:
                newPosition.X--;
                break;

            case Directions.Right:
                newPosition.X++;
                break;
            }

            this.CheckPosition(newPosition, labyrinth);
        }
Ejemplo n.º 8
0
        //Methods
        private static void UniteCells(ref Labyrinth labyrinth, CellPoint first, CellPoint second, ref int NextId)
        {
            int Id1 = labyrinth[first.Row, first.Col].Id;
            int Id2 = labyrinth[second.Row, second.Col].Id;

            if (Id1 != 0 && Id2 != 0)
            {
                for (int i = 0; i < labyrinth.Rows; ++i)
                {
                    for (int j = 0; j < labyrinth.Columns; ++j)
                    {
                        if (labyrinth[i, j].Id == Id2)
                        {
                            labyrinth[i, j].Id = Id1;
                        }
                    }
                }
            }

            if (Id1 == 0 && Id2 == 0)
            {
                labyrinth[first.Row, first.Col].Id   = NextId;
                labyrinth[second.Row, second.Col].Id = NextId;
                ++NextId;
            }
            else if (Id1 == 0)
            {
                labyrinth[first.Row, first.Col].Id = Id2;
            }
            else if (Id2 == 0)
            {
                labyrinth[second.Row, second.Col].Id = Id1;
            }
        }
Ejemplo n.º 9
0
        public void Position_NullValue()
        {
            PlayerPosition startPosition = new PlayerPosition();

            startPosition = null;
            Labyrinth labyrinth = new Labyrinth(startPosition);
        }
Ejemplo n.º 10
0
        public void DisplayLabyrinth(Labyrinth labyrinth, int visibleAreaX, int visibleAreaY)
        {
            Console.ForegroundColor = ConsoleColor.White;
            StringBuilder sb = new StringBuilder();

            for (int row = 0; row < labyrinth.Field.GetLength(0); row++)
            {
                if (!(row >= visibleAreaY - radius && row <= visibleAreaY + radius))
                {
                    continue;
                }

                for (int col = 0; col < labyrinth.Field.GetLength(1); col++)
                {
                    if (col >= (visibleAreaX - radius) && col <= (visibleAreaX + radius))
                    {
                        char charToDraw = '#';
                        if (labyrinth.Field[row, col] != CellsEnum.Wall)
                        {
                            charToDraw = ' ';
                        }

                        sb.Append(charToDraw);
                    }
                }
                Console.SetCursorPosition(visibleAreaX - radius < 0 ? 0 : visibleAreaX - radius, row);
                Console.Write(sb);
                sb.Clear();
            }


            // Console.WriteLine(sb);
        }
Ejemplo n.º 11
0
 void _CurrentGame_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "CurrentLabyrinth")
     {
         if (_Labyrinth != null)
         {
             _Labyrinth.PillEated   -= new PillEatedDelegate(_Labyrinth_PillEated);
             _Labyrinth.PillUpdated -= new PillEatedDelegate(_Labyrinth_PillUpdated);
         }
         _Labyrinth = _CurrentGame.CurrentLabyrinth;
         if (_Labyrinth != null)
         {
             _Labyrinth.PillEated   += new PillEatedDelegate(_Labyrinth_PillEated);
             _Labyrinth.PillUpdated += new PillEatedDelegate(_Labyrinth_PillUpdated);
         }
         ConstructWallAndPills(_CurrentGame.CurrentLabyrinth);
     }
     else if (e.PropertyName == "Status")
     {
         NotifyPropertyChanged("IsReady");
         NotifyPropertyChanged("IsGameOver");
     }
     else if (e.PropertyName == "userTypeSpeed")
     {
         if ((_CurrentGame.freqList.freqsSum == 0) && (_CurrentGame.userTypeSpeed > CurrentGame.userMinTypeSpeed))
         {
             _CurrentGame.taskBox.tskProvider.incTskCount();
             _CurrentGame.setGhostsState(GhostState.REST);
             _CurrentGame.Audio.PlayGhostScared();
         }
     }
 }
Ejemplo n.º 12
0
        static public void Main()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            Labyrinth      labyrinth     = new Labyrinth(startPosition);

            labyrinth.StartGame();
        }
Ejemplo n.º 13
0
        public void LabyrinthValidCellTest()
        {
            const int height    = 3;
            const int width     = 6;
            var       labyrinth = new Labyrinth(height, width);

            for (var i = 0; i < height; i++)
            {
                for (var j = 0; j < width; j++)
                {
                    Assert.IsTrue(labyrinth.IsValidCell(i, j));
                }
            }

            for (var i = 0; i < height; i++)
            {
                Assert.IsFalse(labyrinth.IsValidCell(i, -1));
                Assert.IsFalse(labyrinth.IsValidCell(i, width));
            }

            for (var j = 0; j < width; j++)
            {
                Assert.IsFalse(labyrinth.IsValidCell(-1, j));
                Assert.IsFalse(labyrinth.IsValidCell(height, j));
            }
        }
Ejemplo n.º 14
0
        protected override void GeneralSetup(LabyrinthControl lc)
        {
            Labyrinth lab = new Labyrinth(size, size, size / 2 - 1, size / 2 - 1, 2);

            SearchView search = new SearchView()
            {
                Labyrinth          = lab,
                Start              = Block.Origin,
                IsLabyrinthTarget  = true,
                IsVisible          = true,
                SearchType         = SearchType.BruteForce,
                IsDistancesVisable = false,
                IsCountsVisable    = false,
                IsLengthVisable    = false,
                InterpreterType    = RelationInterpreterType.Actual
            };

            ClearSearches(lc);
            lc.Robot     = null;
            lc.Labyrinth = lab;
            lc.Searches.Add(search);

            lc.IsViewActual  = true;
            lc.IsViewRobot   = false;
            lc.IsViewVirtual = false;
        }
Ejemplo n.º 15
0
    // Use this for initialization

    //public override void OnStartServer()
    private void Start()
    {
        //    DontDestroyOnLoad(gameObject);

        labyrinth = new Labyrinth(seed, width, height, inNr, outNr, staticNr, dynamicNr, keyNr, density);
        Create();
    }
Ejemplo n.º 16
0
        public void GenerateObjectsNew(Labyrinth labyrinth)
        {
            for (int i = 0; i < labyrinth.Rows; i++)
            {
                for (int j = 0; j < labyrinth.Columns; j++)
                {
                    int randomNumber = this.randomGenerator.Next(2);
                    IGameObject currentObject;

                    if (randomNumber == 1)
                    {
                        currentObject = labyrinth.ObjectFactory.GetObstacle();
                    }
                    else
                    {
                        currentObject = labyrinth.ObjectFactory.GetFreeSpace();
                    }

                    labyrinth[i, j] = currentObject;
                }
            }

            labyrinth[labyrinth.StartPosition] = labyrinth.ObjectFactory.GetPlayerCell();

            // bool thereIsWayOut = labyrinth.SolutionChecker(this.StartPosition);

            //if (!thereIsWayOut)
            //{
            //    ObstaclesGenerator(labyrinth);
            //}
        }
Ejemplo n.º 17
0
        protected void left()
        {
            int bInf;
            int car;

            // on essai d'aller a dGauche
            if (moved || (ghost.getOldDirection().isRight() && !ghost.State.isHouse()))
            {
                return;
            }
            if (xLabyGhost < 0)
            {
                car = 0;
            }
            else
            {
                car = Labyrinth.getCurrent().get(xLabyGhost - 1, yLabyGhost);
            }
            bInf = 4 + ((ghost.State.isEye() || ghost.State.isHouse()) ? 1 : 0);
            if (car < bInf)
            {
                newDirection = Direction.Left;
                moved        = true;
            }
        }
Ejemplo n.º 18
0
        public void InitGame()
        {
            //var game = Control.Instance;

            //this.visualization.PrintStartMessage();

            //var labyrinth = game.Setup.SetupNewLabyrinth();
            //game.State.IsInitialized = true;

            IObjectFactory       instanceFactory = new ObjectFactory();
            Labyrinth            labyrinth       = new Labyrinth(LabyrinthSize, LabyrinthSize, instanceFactory);
            GameObjectsGenerator generator       = new GameObjectsGenerator();

            generator.GenerateObjectsNew(labyrinth);

            this.visualization.PrintMessage("Labyrinth is Ready");


            this.visualization.DrawLabyrinth(labyrinth);
            MovesFactory movesFactory = new MovesFactory(labyrinth);

            while (!labyrinth.State.IsFinished)
            {
                IMoves move = this.visualization.GetUserCommand(movesFactory);
                move.Move();
                this.visualization.DrawLabyrinth(labyrinth);
            }
        }
Ejemplo n.º 19
0
        static int Main(string[] args)
        {
            // For Recodex
            foreach (string arg in args)
            {
                if (arg == "--dev")
                {
                    printToConsole = true;
                }
            }

            // Beast in a labyrinth
            const int TICKS = 20;

            Labyrinth labyrinth = new Labyrinth(
                reader.ReadInt(),
                reader.ReadInt(),
                reader.ReadRest().Replace("\n", "")
                );

            if (MainClass.printToConsole)
            {
                labyrinth.Print();
            }

            for (int i = 0; i < TICKS; i++)
            {
                labyrinth.NextTick();
                labyrinth.Print();
            }

            return(0);
        }
Ejemplo n.º 20
0
        //Create Labyrinth
        public static void SetLabyrinth(DataGridView Grid, Labyrinth labyrinth)
        {
            for (int row = 1; row < Grid.RowCount; row += 2)
            {
                for (int col = 1; col < Grid.ColumnCount; col += 2)
                {
                    Grid.Rows[row].Cells[col].Style.BackColor = Color.White;
                }
            }

            for (int row = 1, Row = 0; row < Grid.RowCount - 1; row += 2, ++Row)
            {
                for (int col = 2, Col = 0; col < Grid.ColumnCount; col += 2, ++Col)
                {
                    if (!labyrinth[Row, Col].Right && col < Grid.ColumnCount - 1)
                    {
                        Grid.Rows[row].Cells[col].Style.BackColor = Color.White;
                    }
                    if (!labyrinth[Row, Col].Down && row != Grid.RowCount - 2)
                    {
                        Grid.Rows[row + 1].Cells[col - 1].Style.BackColor = Color.White;
                    }
                }
            }
        }
Ejemplo n.º 21
0
 public void Play(int sizeX, int sizeZ)
 {
     menuInstance.HideMenu();
     labyrinthInstance      = Instantiate(labyrinthPref) as Labyrinth;
     labyrinthInstance.name = "Labyrinth";
     labyrinthInstance.CreateLabyrinth(sizeX, sizeZ);
 }
Ejemplo n.º 22
0
        public static void Main()
        {
            // We are given a matrix of passable and non-passable cells.
            // Write a recursive program for finding all paths between two cells in the matrix.

            // Modify the above program to check whether a path exists between two cells without finding all possible paths.
            // Test it over an empty 100 x 100 matrix.
            char[,] matrix =
               {
                {' ', ' ', ' ', '*', ' ', ' ', ' '},
                {'*', '*', ' ', '*', ' ', '*', ' '},
                {' ', ' ', ' ', ' ', ' ', ' ', ' '},
                {' ', '*', '*', '*', '*', '*', ' '},
                {' ', ' ', ' ', ' ', ' ', ' ', 'e'},
            };

            char[,] matrix1 =
            {
                {' ', ' ', ' '},
                {' ', ' ', ' '},
                {' ', ' ', 'e'},
            };

            char[,] matrix2 = new char[100, 100];
            matrix2[99, 99] = 'e';

            var lab = new Labyrinth(matrix2);
            lab.FindPaths(0, 0, 'S');
        }
Ejemplo n.º 23
0
        public void LabyrinthMoveUpTest()
        {
            string[] rawData = new string[Labyrinth.LabyrinthSize]
            {
                "XXXXXXX",
                "X-X---X",
                "X---X-X",
                "X--*--X",
                "X-X----",
                "X-----X",
                "XXXXXXX"
            };
            Cell[,] board = LabyrinthDataFromStringArray(rawData);
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            Labyrinth      labyrinth     = new Labyrinth(startPosition, board);
            var            privateObject = new PrivateObject(labyrinth);

            privateObject.Invoke("ProcessMoveUp", 3, 3);

            string actual   = labyrinth.ToString();
            string expected =
                @"X X X X X X X 
X - X - - - X 
X - - * X - X 
X - - - - - X 
X - X - - - - 
X - - - - - X 
X X X X X X X 
";

            Assert.AreEqual(actual, expected);
        }
Ejemplo n.º 24
0
    private void Start()
    {
        // CREAMOS AL JUGADOR
        Weapon weapon = new Weapon("A spoon.", 10);
        Shield shield = new Shield("Frying pan", 10);

        m_player = new Player(20, 5, 100, 100, 20, weapon, shield);

        // CREAMOS EL LABERINTO QUE CONTIENE LAS HABITACIONES
        m_labyrinth = new Labyrinth(m_player);

        // SE AÑADEN LAS HABITACIONES
        Enemy enemy = new Enemy(m_player, "Rat kid", 5, 5, 120, 60, 10, 10, 1, 20);
        Room  room  = new Room(Room.RoomType.ENEMY, enemy);

        m_labyrinth.AddRoom(room);

        Item item = new Item("Dark Matter", -5, 10, 10, 10, 0, -5);

        room = new Room(Room.RoomType.ITEM, item);
        m_labyrinth.AddRoom(room);

        Trap trap = new Trap("Existential crysis", -10, -10);

        room = new Room(Room.RoomType.TRAP, trap);
        m_labyrinth.AddRoom(room);

        enemy = new Enemy(m_player, "GabeN", 5, 5, 120, 60, 10, 10, 1, 20);
        room  = new Room(Room.RoomType.ENEMY, enemy);
        m_labyrinth.AddRoom(room);

        // ARRANCA EL LABERINTO
        m_labyrinth.ChangeRoom();
    }
Ejemplo n.º 25
0
        public void PlayerCommandExit()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);

            string[] rawData = new string[Labyrinth.LabyrinthSize]
            {
                "XXXXXXX",
                "X-X---X",
                "X---X-X",
                "X--*--X",
                "X-X----",
                "X-----X",
                "XXXXXXX"
            };

            Cell[,] board = LabyrinthDataFromStringArray(rawData);

            Labyrinth labyrinth = new Labyrinth(startPosition, board);

            var privateObject = new PrivateObject(labyrinth);
            int x             = 3;
            int y             = 3;

            privateObject.Invoke("ProcessMove", "exit", x, y);

            Assert.AreEqual(false, labyrinth.IsRunning);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// construct geometry of wall and pills for a specific level
        /// </summary>
        /// <param name="newValue"></param>

        private void ConstructWallAndPills(Labyrinth newValue)
        {
            this.Wall.Children.Clear();
            this.Pills.Children.Clear();
            CurrentGame._pillCoord.Clear();
            if (newValue == null)
            {
                return;
            }
            TPillGame.RemainingPills = 0;
            for (int xx = 0; xx < Labyrinth.WIDTH; xx++)
            {
                for (int yy = 0; yy < Labyrinth.HEIGHT; yy++)
                {
                    UInt16 b = newValue[xx, yy];
                    if (b == 0)
                    {
                        continue;
                    }
                    double x, y;
                    newValue.GetScreenCoord(xx, yy, out x, out y);
                    switch (b)
                    {
                    case 1:                            //pill
                    case 2:
                        TPillGame pill = new TPillGame(this);
                        this.Pills.Children.Add(pill);
                        CurrentGame._pillCoord.Add(new Point(xx, yy), pill);
                        pill.Width  = Constants.GRID_WIDTH * 1.5;
                        pill.Height = Constants.GRID_HEIGHT * 1.5;
                        pill.tsk    = newValue.chars[xx, yy];
                        pill.center = new Point(x + Constants.GRID_WIDTH_2, y + Constants.GRID_HEIGHT_2);
                        pill.init();
                        pill.isBig = (b == 2);
                        break;

                    case 4:                             //gate of ghost's house
                        break;

                    case 5:                            //wall
                        Geometry current = GetGeometry(xx, yy, (int)x, (int)y, newValue);
                        //if (current == null)
                        //{
                        //    RectangleGeometry r = new RectangleGeometry();
                        //    //if (i == 0)
                        //    //    r.Rect = new Rect(x + Constants.GRID_WIDTH_2, y, Constants.GRID_WIDTH_2, Constants.GRID_HEIGHT);
                        //    //else
                        //    r.Rect = new Rect(x, y, Constants.GRID_WIDTH, Constants.GRID_HEIGHT);
                        //    current = r;
                        //}
                        if (current != null)
                        {
                            this.Wall.Children.Add(current);
                        }
                        break;
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            var labyrinth = new Labyrinth(SeedLabyrinth());

            labyrinth.CalculateDistance();

            labyrinth.PrintResult();
        }
        static void Main(string[] args)
        {
            var labyrinth = new Labyrinth(SeedLabyrinth());

            labyrinth.CalculateDistance();

            labyrinth.PrintResult();
        }
Ejemplo n.º 29
0
 private void _destory_labyrinth()
 {
     foreach (GameObject g in instantiatedPrefabs)
     {
         Destroy(g);
     }
     labyrinth = null;
 }
        public static void Main()
        {
            var secondMatrix = new char[100, 100];
            secondMatrix[99, 99] = 'e';

            var lab = new Labyrinth(secondMatrix);
            lab.FindPaths(0, 0, 'S');
        }
        public void IsGameWonTestFalse()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            Labyrinth labyrinth = new Labyrinth(startPosition);
            var privateObject = new PrivateObject(labyrinth);
            var actual = privateObject.Invoke("IsGameWon", 3, 3);

            Assert.AreEqual(false, actual);
        }
Ejemplo n.º 32
0
        public void IsOnBoarderTest()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            Labyrinth      labyrinth     = new Labyrinth(startPosition);
            var            privateObject = new PrivateObject(labyrinth);
            var            actual        = privateObject.Invoke("IsOnBorder", 6, 6);

            Assert.AreEqual(true, actual);
        }
Ejemplo n.º 33
0
        public void IsGameWonTestFalse()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            Labyrinth      labyrinth     = new Labyrinth(startPosition);
            var            privateObject = new PrivateObject(labyrinth);
            var            actual        = privateObject.Invoke("IsGameWon", 3, 3);

            Assert.AreEqual(false, actual);
        }
        public void IsOnBoarderTest()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            Labyrinth labyrinth = new Labyrinth(startPosition);
            var privateObject = new PrivateObject(labyrinth);
            var actual = privateObject.Invoke("IsOnBorder", 6, 6);

            Assert.AreEqual(true, actual);
        }
Ejemplo n.º 35
0
 void InitializeLevel()
 {
     timer     = 0f;
     player    = GameObject.Find("Player");
     lab       = gameObject.GetComponent <Labyrinth>();
     vertices  = lab.sa.vertices;
     coinCount = 0;
     StartCoroutine("GenerateCoin", lab);
 }
Ejemplo n.º 36
0
        public void LabTest()
        {
            IField lab = new Labyrinth(7);

            var expected = 7;
            var actual   = lab.Size;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 37
0
        /// <summary>Строит и возвращает построенный лабиринт.</summary>
        /// <returns>Построенный лабиринт.</returns>
        public override ILabyrinth CreateLabyrinth()
        {
            // Создаем пустой лабиринт размером 10 x 10 клеток
            var labyrinth = new Labyrinth<MyFreeCell, MyWall>(10, 10);

            // Устанавливаем стену в клетку с координатами (3, 4)
            labyrinth.SetWall(3, 4);

            return labyrinth;
        }
Ejemplo n.º 38
0
        public ActionResult <Labyrinth> Create(Labyrinth labyrinth)
        {
            if (IsValidLabyrinth(labyrinth))                                                  // Check om labyrinten er gyldig
            {
                _labyrinthService.Create(labyrinth);                                          // Opret labyrinten

                return(CreatedAtRoute("GetLabyrinth", new { id = labyrinth.Id }, labyrinth)); // Hvis labyrinten blev oprettet så send en HTTP 201 med labyrinten i
            }
            return(BadRequest());                                                             // Hvis labyrinten ikke er gyldig så send en HTTP 400
        }
        private Mine InitializeMine(Labyrinth labyrinth)
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            int x = random.Next(labyrinth.Width);
            int y = random.Next(labyrinth.Height);

            var labyrinthUnit = labyrinth[x, y];

            Mine mine = new Mine(_game, labyrinthUnit.TopLeftPosition, x, y);
            _game.Components.Add(mine);
            _game.Services.AddService(typeof(Mine), mine);

            return mine;
        }
        public static void Main()
        {
            var matrix = new[,]
            {
                { "0", "0", "0", "x", "0", "x" },
                { "0", "x", "0", "x", "0", "x" },
                { "0", "*", "x", "0", "x", "0" },
                { "0", "x", "0", "0", "0", "0" },
                { "0", "0", "0", "x", "x", "0" },
                { "0", "0", "0", "x", "0", "x" }
            };

            var labyrinth = new Labyrinth(matrix);
            labyrinth.Print();
        }
Ejemplo n.º 41
0
        public static void Main()
        {
            char[,] matrix = new char[,]
            {
                { '-', '-', '-', 'x', '-', '-' },
                { '-', 'x', '-', 'x', '-', 'x' },
                { '-', 'x', '-', '-', 'x', '-' },
                { '-', 'x', '-', '-', '-', '-' },
                { '-', '-', 'x', 'x', '-', '-' },
                { '-', '-', '-', 'x', '-', 'x' }
            };

            Labyrinth labyrinth = new Labyrinth(matrix);
            labyrinth.FindPath(0, 0, 2, 5);
        }
Ejemplo n.º 42
0
        public static void Main()
        {
            // We are given a matrix of passable and non-passable cells.
            // Write a recursive program for finding all paths between two cells in the matrix.

            char[,] matrix =
               {
                {' ', ' ', ' ', '*', ' ', ' ', ' '},
                {'*', '*', ' ', '*', ' ', '*', ' '},
                {' ', ' ', ' ', ' ', ' ', ' ', ' '},
                {' ', '*', '*', '*', '*', '*', ' '},
                {' ', ' ', ' ', ' ', ' ', ' ', 'e'},
            };

            var lab = new Labyrinth(matrix);
            lab.FindPaths(0, 0);
        }
        static void Main()
        {
            int[,] input = new int[,]
                {
                    { 0, 0, 0, -1, 0, -1 },
                    { 0, -1, 0, -1, 0, -1 },
                    { 0, 0, -1, 0, -1, 0 },
                    { 0, -1, 0, 0, 0, 0 },
                    { 0, 0, 0, -1, -1, 0 },
                    { 0, 0, 0, -1, 0, -1 },
                };

            var labyrinth = new Labyrinth(input);
            labyrinth.PrintStringifiedPathData(2, 1);


        }
Ejemplo n.º 44
0
        public static void Main()
        {
            char[,] field = {
                {'s', ' ', ' ', ' ', ' ', ' '},
                {' ', '*', '*', ' ', '*', ' '},
                {' ', '*', '*', ' ', '*', ' '},
                {' ', '*', 'e', ' ', ' ', ' '},
                {' ', ' ', ' ', '*', ' ', ' '}};

            //char[,] field = {
            //    {'s', ' ', ' ', ' '},
            //    {' ', '*', '*', ' '},
            //    {' ', '*', '*', ' '},
            //    {' ', '*', 'e', ' '},
            //    {' ', ' ', ' ', ' '}};

            var labyrinth = new Labyrinth(field);
            labyrinth.PrintPaths();
        }
Ejemplo n.º 45
0
        /// <summary>Строит и возвращает простой лабиринт.</summary>
        /// <returns>Построенный лабиринт.</returns>
        public override ILabyrinth CreateLabyrinth()
        {
            // Создаем лабиринт размером 10x10 и со свободными клетками класса UglyFreeCell
            int rowsCount = 10; // Число строк в лабиринте
            int colsCount = 10; // Число столбцов в лабиринте
            var labyrinth = new Labyrinth<UglyFreeCell, UglyWall>(rowsCount, colsCount);

            // Расставляем стены
            labyrinth.SetWall(3, 4);
            labyrinth.SetWall(3, 5);
            labyrinth.SetWall(3, 6);
            labyrinth.SetWall(4, 7);
            labyrinth.SetWall(2, 4);
            labyrinth.SetWall(9, 9);
            labyrinth.SetWall(1, 1);
            labyrinth.SetWall(1, 2);
            labyrinth.SetWall(1, 3);

            return labyrinth;
        }
Ejemplo n.º 46
0
        public void GenerateObjects(Labyrinth labyrinth, Obstacle obstacle, FreeSpace freeSpace)
        {
            for (int i = 0; i < labyrinth.Columns; i++)
            {
                for (int j = 0; j < labyrinth.Rows; j++)
                {
                    int randomNumber = this.randomGenerator.Next(2);
                    IGameObject currentObject;

                    if (randomNumber == 1)
                    {
                        currentObject = (Obstacle)obstacle.Clone();
                    }
                    else
                    {
                        currentObject = (FreeSpace)freeSpace.Clone();
                    }

                    labyrinth[i, j] = currentObject;
                }
            }
        }
        internal static void MakeSureMineHasAccessToVillage(Labyrinth labyrinth, Mine mine, Village village)
        {
            int xFrom, yFrom, xTo, yTo;

            if (mine.LabyrinthCorX >= village.LabyrinthCorX)
            {
                xFrom = village.LabyrinthCorX;
                xTo = mine.LabyrinthCorX;
            }
            else
            {
                xFrom = mine.LabyrinthCorX;
                xTo = village.LabyrinthCorX;
            }

            if (mine.LabyrinthCorY >= village.LabyrinthCorY)
            {
                yFrom = village.LabyrinthCorY;
                yTo = mine.LabyrinthCorY;
            }
            else
            {
                yFrom = mine.LabyrinthCorY;
                yTo = village.LabyrinthCorY;
            }

            for (int i = xFrom; i <= xTo; i++)
            {
                labyrinth.Remove(i, yFrom);
                labyrinth.Remove(i, yTo);
            }

            for (int k = yFrom; k <= yTo; k++)
            {
                labyrinth.Remove(xTo, k);
                labyrinth.Remove(xFrom, k);
            }
        }
Ejemplo n.º 48
0
 public MoveLeft(Labyrinth labyrinth)
     : base(labyrinth)
 {
 }
Ejemplo n.º 49
0
 public MoveDown(Labyrinth labyrinth)
     : base(labyrinth)
 {
 }
        private Village InitializeVillage(Labyrinth labyrinth)
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            int x = random.Next(labyrinth.Width);
            int y = random.Next(labyrinth.Height);

            var labyrinthUnit = labyrinth[x, y];

            Village village = new Village(_game, labyrinthUnit.TopLeftPosition, x, y);
            _game.Components.Add(village);
            _game.Services.AddService(typeof(Village), village);

            return village;
        }
        private Miner[] InitializeMiners(Labyrinth labyrinth, Village village, Mine mine)
        {
            Miner[] miners = new Miner[MinerCount];

            for (int i = 0; i < MinerCount; i++)
            {
                miners[i] = new Miner(_game, village.StartPosition, village.LabyrinthCorX, village.LabyrinthCorY, mine.LabyrinthCorX, mine.LabyrinthCorY, new TimeSpan(0, 0, i * 10));
                _game.Components.Add(miners[i]);
            }

            _game.Services.AddService(typeof(Miner [] ), miners);

            return miners;
        }
Ejemplo n.º 52
0
 public Moves(Labyrinth labyrinth)
 {
     this.labyrinth = labyrinth;
     this.CurrentPosition = labyrinth.StartPosition;
 }
Ejemplo n.º 53
0
 public MoveRight(Labyrinth labyrinth)
     : base(labyrinth)
 {
 }
 static public void Main()
 {
     PlayerPosition startPosition = new PlayerPosition(3, 3);
     Labyrinth labyrinth = new Labyrinth(startPosition);
     labyrinth.StartGame();
 }
Ejemplo n.º 55
0
 public EndState(Labyrinth labyrinth)
     : base(labyrinth)
 {
 }
Ejemplo n.º 56
0
 public MoveUp(Labyrinth labyrinth)
     : base(labyrinth)
 {
 }
Ejemplo n.º 57
0
 public ICell[,] GeneratePlayField(Labyrinth.Common.Contracts.IRandomNumberGenerator rand)
 {
     for (int i = 0; i < this.cells.GetLength(0); i++)
     {
         for (int j = 0; j < this.cells.GetLength(1); j++)
         {
             this.cells[i, j] = new Cell(new Position(i, j), '-');
         }
     }
     return this.cells;
 }
Ejemplo n.º 58
0
 protected State(Labyrinth labyrinth)
 {
     this.Labyrinth = labyrinth;
 }
        public ICell[,] GeneratePlayField(Labyrinth.Common.Contracts.IRandomNumberGenerator rand)
        {
            for (int i = 0; i < this.cells.GetLength(0); i++)
            {
                for (int j = 0; j < this.cells.GetLength(1); j++)
                {
                    this.cells[i, j] = new Cell(new Position(i, j), Constants.StandardGameCellEmptyValue);
                }
            }

            this.cells[this.playerPosition.Row, this.playerPosition.Column].ValueChar = Constants.StandardGamePlayerChar;
            return this.cells;
        }
Ejemplo n.º 60
0
 public ActiveState(Labyrinth labyrinth)
     : base(labyrinth)
 {
 }