Exemplo n.º 1
0
        public void startLevel(string level)
        {
            levelModel.StartupLevel = level;

            levelReader.readMapString();
            levelReader.readMapObject();
            levelModel.LevelStarted = true;

            //Change the width and height and the title of the window
            this.Width = 16 + (levelModel.ColumnLenght * levelModel.CellSize) + levelModel.InfoGridWidth;
            this.Height = 39 + (levelModel.RowLenght * levelModel.CellSize);
            this.MinHeight = 39 + (8 * levelModel.CellSize);
            this.Title = "Sokoban: " + levelModel.StartupLevel;

            colInfoGrid.Width = new GridLength(levelModel.InfoGridWidth);

            if (board != null)
            {
                board.Visibility = Visibility.Collapsed;
                infoGrid.Visibility = Visibility.Collapsed;
            }

            board = new Board(this.levelModel);
            board.SetValue(Grid.ColumnProperty, 0);
            board.SetValue(Grid.RowProperty, 0);
            gameGrid.Children.Add(board);

            scoreModel = new ModelScore();

            infoGrid = new InfoGrid(this, this.levelModel, scoreModel, highScore);
            infoGrid.SetValue(Grid.ColumnProperty, 1);
            infoGrid.SetValue(Grid.RowProperty, 0);
            gameGrid.Children.Add(infoGrid);

            player = new Player(board, levelModel, scoreModel, this);

            mainGrid.Visibility = Visibility.Collapsed;
            gameGrid.Visibility = Visibility.Visible;
        }
Exemplo n.º 2
0
        public void fillBord(String filepath)
        {
            try {
                using (StreamReader sr = new StreamReader(filepath)) {
                    rows = 0;
                    cols = 0;
                    List<String> regels = new List<String>();
                    while (sr.ReadLine() != null) {
                        rows++;
                    }

                    sr.BaseStream.Position = 0;
                    sr.DiscardBufferedData();

                    cols = sr.ReadLine().ToCharArray().Length;

                    sr.BaseStream.Position = 0;
                    sr.DiscardBufferedData();

                    bordje = new char[rows, cols];
                    bord = new Hokje[rows, cols];

                   int rownumber = 0;
                    while (!sr.EndOfStream && rownumber < rows) {
                        String currentLine = sr.ReadLine();
                        char[] characters = currentLine.ToCharArray();

                        for (int i = 0; i < cols; i++) {
                            bordje[rownumber, i] = characters[i];
                        }
                        rownumber++;
                    }
                }
            }
            catch (Exception e) {
                MessageBox.Show("File could not be read");
                MessageBox.Show(e.Message);
            }

            for (int j = 0; j < rows; j++) {
                for (int i = 0; i < cols; i++) {
                    switch (bordje[j, i]) {
                        case '#':
                            bord[j, i] = new Wall();
                            break;
                        case 'o':
                            bord[j, i] = new Box();
                            break;
                        case 'x':
                            bord[j, i] = new Destination();
                            break;
                        case ' ':
                            bord[j, i] = new Empty();
                            break;
                        case '@':
                            bord[j, i] = new Player();
                            break;
                    }
                    Console.Write(bordje[j, i]);
                }
                Console.Write("\n");
            }
        }