コード例 #1
0
        public void UpdateBoard(Model.GameBoard game)
        {
            Console.Clear();
            int nRows = game.Height;
            int nCols = game.Width;

            Model.Tile current        = game.Origin;
            Model.Tile neighbourBelow = current.TileBelow;

            for (int r = 0; r < nRows; r++)
            {
                for (int c = 0; c < nCols; c++)
                {
                    Console.Write(current.ToChar());
                    current = current.TileToRight;
                }
                current = neighbourBelow;
                if (neighbourBelow != null)
                {
                    neighbourBelow = current.TileBelow;
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine("------------------------------------------");
            Console.WriteLine("------- gebruik de toetsen 1 t/m 5 -------");
            Console.WriteLine("----------- Jouw score:    " + game.TotalScore.ToString() + "   -----------");
        }
コード例 #2
0
        public Vector2 GetWorldPos(Model.Tile tile)
        {
            if (tile == null)
            {
                throw new System.ArgumentNullException(nameof(tile));
            }

            return(_Tiles.Single(t => t.ModelTile == tile).transform.position);
        }
コード例 #3
0
 public void PrintMaze(Model.Tile first)
 {
     Console.WriteLine();
     Model.Tile horizontal = first;
     Model.Tile vertical   = first;
     while (vertical != null)
     {
         while (horizontal != null)
         {
             Console.Write(horizontal.Symbol);
             horizontal = horizontal.Right;
         }
         Console.WriteLine();
         vertical   = vertical.Below;
         horizontal = vertical;
     }
 }
コード例 #4
0
        private TileType Convert(Model.Tile value)
        {
            switch (value)
            {
            case Model.Tile.Empty: return(TileType.Empty);

            case Model.Tile.Wall: return(TileType.Wall);

            case Model.Tile.Platform: return(TileType.Platform);

            case Model.Tile.Ladder: return(TileType.Ladder);

            case Model.Tile.JumpPad: return(TileType.JumpPad);

            default: throw new System.ArgumentOutOfRangeException(nameof(value));
            }
        }
コード例 #5
0
ファイル: GameView.cs プロジェクト: hk222gn/1DV437-labbar
        private void DrawTile(float a_x, float a_y, float a_scale, Model.Tile a_tile, SpriteBatch a_spriteBatch)
        {
            //Get the source rectangle (pixels on the texture) for the tile type
            Rectangle sourceRectangle = new Rectangle(0, 0, m_textureTileSize, m_textureTileSize);

            //Destination rectangle in windows coordinates only scaling
            Rectangle destRect = new Rectangle((int)a_x, (int)a_y, (int)(m_textureTileSize), (int)(m_textureTileSize));

            Texture2D textureToRender;

            switch (a_tile.GetTileType())
            {
            case TileType.EMPTY:
                textureToRender = m_emptyTexture;
                break;

            case TileType.BLOCKED:
                textureToRender = m_blockedTexture;
                break;

            case TileType.LETHAL:
                textureToRender = m_lethalTexture;
                break;

            case TileType.FAKE:
                //It's rendered as a normal block, but it really aint.
                textureToRender = m_blockedTexture;
                break;

            case TileType.PORTAL:
                textureToRender = m_portalTexture;
                break;

            default:
                textureToRender = m_emptyTexture;
                break;
            }
            a_spriteBatch.Draw(textureToRender, destRect, sourceRectangle, Color.White);
        }
コード例 #6
0
        public void MoveArrows()
        {
            inputView.AskForArrowInput();

            while (Maze.AmountOfChests != Maze.AmountOfChestsOnDestination)
            {
                ConsoleKey key         = inputView.RetrieveConsoleKey();
                Model.Tile currentTile = Maze.CurrentForkLift;
                if (key == ConsoleKey.UpArrow || key == ConsoleKey.DownArrow || key == ConsoleKey.LeftArrow || key == ConsoleKey.RightArrow)
                {
                    switch (key)
                    {
                    case ConsoleKey.UpArrow:
                        if (currentTile.Above.Above == null)
                        {
                            break;
                        }
                        if (Maze.CurrentForkLift.Above.PutEntityOnThisField(Maze, Maze.CurrentForkLift, Maze.CurrentForkLift.Above.Above))
                        {
                            Maze.CurrentForkLift = Maze.CurrentForkLift.Above;
                        }
                        break;

                    case ConsoleKey.DownArrow:
                        if (currentTile.Below.Below == null)
                        {
                            break;
                        }
                        if (Maze.CurrentForkLift.Below.PutEntityOnThisField(Maze, Maze.CurrentForkLift, Maze.CurrentForkLift.Below.Below))
                        {
                            Maze.CurrentForkLift = Maze.CurrentForkLift.Below;
                        }
                        break;

                    case ConsoleKey.LeftArrow:
                        if (currentTile.Left.Left == null)
                        {
                            break;
                        }
                        if (Maze.CurrentForkLift.Left.PutEntityOnThisField(Maze, Maze.CurrentForkLift, Maze.CurrentForkLift.Left.Left))
                        {
                            Maze.CurrentForkLift = Maze.CurrentForkLift.Left;
                        }
                        break;

                    case ConsoleKey.RightArrow:
                        if (currentTile.Right.Right == null)
                        {
                            break;
                        }
                        if (Maze.CurrentForkLift.Right.PutEntityOnThisField(Maze, Maze.CurrentForkLift, Maze.CurrentForkLift.Right.Right))
                        {
                            Maze.CurrentForkLift = Maze.CurrentForkLift.Right;
                        }
                        break;
                    }
                    if (Maze.CurrentWorker != null)
                    {
                        Maze.CurrentWorker.Entity.Move(Maze);
                    }
                    outputView.PrintMaze(Maze.First);
                }
                else
                {
                    inputView.InvalidInputMessage();
                }
            }
            outputView.LevelCompletedMessage();
        }
コード例 #7
0
 public void Initialize(Model.Tile tile, UIManager uiManager)
 {
     ModelTile  = tile ?? throw new System.ArgumentNullException(nameof(tile));
     _UIManager = uiManager != null ? uiManager : throw new System.ArgumentNullException(nameof(uiManager));
 }
コード例 #8
0
 public void DebugSpawnUnit(Unit unitInstance, Model.Tile tile, Faction faction)
 {
     _Map.ModelMap.Spawn(unitInstance, tile, faction, false);
 }
コード例 #9
0
        public void BuildMaze(int maze Number)
        {
            string _filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);

            _filePath  = Directory.GetParent(_filePath).FullName;
            _filePath  = Directory.GetParent(Directory.GetParent(_filePath).FullName).FullName;
            _filePath += @"\Sokoban M3\Mazes\doolhof" + mazeNumber + ".txt";
            TextReader tr = new StreamReader(_filePath);

            string        line;
            List <string> list = new List <string>();

            while ((line = tr.ReadLine()) != null)
            {
                list.Add(line);
            }

            char[] characters = list[0].ToArray();
            Maze = new Maze();
            Model.Tile[,] tiles = new Model.Tile[list.Count, characters.Length];
            for (int i = 0; i < list.Count; i++)
            {
                characters = list[i].ToArray();
                for (int j = 0; j < characters.Length; j++)
                {
                    switch (characters[j])
                    {
                    case ' ':
                        tiles[i, j] = new EmptyTile();
                        break;

                    case '.':
                        tiles[i, j] = new Floor();
                        break;

                    case '#':
                        tiles[i, j] = new Wall();
                        break;

                    case '@':
                        tiles[i, j]          = new Floor();
                        tiles[i, j].Entity   = new Model.Forklift();
                        Maze.CurrentForkLift = tiles[i, j];
                        break;

                    case 'x':
                        tiles[i, j] = new Destination();
                        break;

                    case 'o':
                        tiles[i, j]        = new Floor();
                        tiles[i, j].Entity = new Chest();
                        Maze.AmountOfChests++;
                        break;

                    case '~':
                        tiles[i, j] = new Pitfall();
                        break;

                    case '$':
                        tiles[i, j]        = new Floor();
                        tiles[i, j].Entity = new Worker();
                        Maze.CurrentWorker = tiles[i, j];
                        break;
                    }
                    if (Maze.First == null)
                    {
                        Maze.First = tiles[i, j];
                    }
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                for (int j = 0; j < characters.Length; j++)
                {
                    if (i - 1 > -1)
                    {
                        tiles[i, j].Above = tiles[i - 1, j];
                    }
                    if (i + 1 < list.Count)
                    {
                        tiles[i, j].Below = tiles[i + 1, j];
                    }
                    if (j - 1 > -1)
                    {
                        tiles[i, j].Left = tiles[i, j - 1];
                    }
                    if (j + 1 < characters.Length)
                    {
                        tiles[i, j].Right = tiles[i, j + 1];
                    }
                }
            }
        }