Ejemplo n.º 1
0
    public void LoadTiles(string path)
    {
        List <string> textLines  = new List <string>();
        StreamReader  fileReader = new StreamReader(path);
        string        line       = fileReader.ReadLine();
        int           width      = line.Length;

        while (line != null)
        {
            textLines.Add(line);
            line = fileReader.ReadLine();
        }
        TileField      tiles     = new TileField(textLines.Count - 1, width, 1, "tiles");
        int            height    = textLines.Count - 1;
        GameObjectList hintField = new GameObjectList(100);

        Add(hintField);
        string           hint      = textLines[textLines.Count - 2];
        SpriteGameObject hintFrame = new LockedSpriteGameObject("Overlays/spr_frame_hint", 1);

        hintField.Position = new Vector2((GameEnvironment.Screen.X - hintFrame.Width) / 2, 10);
        hintField.Add(hintFrame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2);

        hintText.Text     = textLines[textLines.Count - 2];
        hintText.Position = new Vector2(120, 25);
        hintText.Color    = Color.Black;
        hintField.Add(hintText);
        int timerTime = int.Parse(textLines[textLines.Count - 1]);

        timer.SetTime = timerTime;
        VisibilityTimer hintTimer = new VisibilityTimer(hintField, 1, "hintTimer");

        Add(hintTimer);

        Add(tiles);
        tiles.CellWidth  = 72;
        tiles.CellHeight = 55;
        this.width       = width * tiles.CellWidth;
        this.height      = height * tiles.CellHeight;
        for (int x = 0; x < width; x++)
        {
            Tile t = new Tile();
            tiles.Add(t, x, 0);
        }
        for (int x = 0; x < width; ++x)
        {
            for (int y = 1; y < textLines.Count - 1; ++y)
            {
                Tile t = LoadTile(textLines[y - 1][x], x, y);
                tiles.Add(t, x, y);
            }
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Pick a random starting point. Add the start tile to the TileField and as entry point for the main algorithm.
 /// </summary>
 private void InitialiseStart()
 {
     start = new Point(random.Next(tiles.Columns / 2 - 1) * 2 + 1, random.Next(tiles.Rows / 2 - 1) * 2 + 1);
     nodesToDo.Add(start);
     tiles.Add(new StartTile(0, "playerstart"), start.X, start.Y);
     bestExit = start;
 }
    /// <summary>Load the level.</summary>
    public void LoadTiles(string path)
    {
        this.path = path;
        List <string> textlines  = new List <string>();
        StreamReader  fileReader = new StreamReader(path);
        string        line       = fileReader.ReadLine(); // first row of the level

        width = line.Length;                              // calculated level width
        while (line != null)
        {
            // read all lines
            textlines.Add(line);
            line = fileReader.ReadLine();
        }
        height = textlines.Count - 2;

        // add the hint
        GameObjectList hintfield = new GameObjectList(100);

        Add(hintfield);
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1); // hint background

        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); // hint text

        hintText.Text     = textlines[textlines.Count - 2];                // last line in the level descriptor
        hintText.Position = new Vector2(120, 25);
        hintText.Color    = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); // timeout

        Add(hintTimer);

        TimerGameObject timer = new TimerGameObject(101, "timer");

        timer.Position = new Vector2(25, 30);
        timer.TimeLeft = TimeSpan.FromSeconds(double.Parse(textlines[textlines.Count - 1]));
        Add(timer);

        // construct the level
        TileField tiles = new TileField(height, width, 1, "tiles");

        Add(tiles);
        // tile dimentions
        tiles.CellWidth = 72;
        cellWidth       = 72;

        tiles.CellHeight = 55;
        cellHeight       = 55;

        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }
        }
    }
Ejemplo n.º 4
0
    public void LoadTiles(string path)
    {
        //Haalt de tekst uit tekstfile
        int width;
        List<string> textlines = new List<string>();
        StreamReader fileReader = new StreamReader(path);
        string line = fileReader.ReadLine();
        width = line.Length;
        while (line != null)
        {
            textlines.Add(line);
            line = fileReader.ReadLine();
        }

        //Tijdslimiet i wordt afgelezen uit tekstfile
        int i = int.Parse(textlines[textlines.Count - 1]);
        SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100, "timerBackground");
        timerBackground.Position = new Vector2(10, 10);
        this.Add(timerBackground);
        TimerGameObject timer = new TimerGameObject(i, 101, "timer");
        timer.Position = new Vector2(25, 30);
        this.Add(timer);

        int height = textlines.Count - 2;

        //Creëert het speelveld
        TileField tiles = new TileField(textlines.Count - 2, width, 1, "tiles");

        //Plaatst de hintbutton
        GameObjectList hintfield = new GameObjectList(100, "hintfield");
        this.Add(hintfield);
        string hint = textlines[textlines.Count - 2];
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1, "hint_frame");
        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2, "hintText");
        hintText.Text = hint;
        hintText.Position = new Vector2(120, 25);
        hintText.Color = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer");
        this.Add(hintTimer);

        //Vult het speelveld met de goede tiles
        this.Add(tiles);
        tiles.CellWidth = 72;
        tiles.CellHeight = 55;
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < textlines.Count - 2; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }

        levelwidth = width * tiles.CellWidth;
        levelheight = height * tiles.CellHeight;
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a tilefield filled with walls.
        /// </summary>
        private void InitialiseTileField()
        {
            ValidateDimensions();

            tiles = new TileField(numRows, numCols);
            for (int y = 0; y < tiles.Rows; y++)
            {
                for (int x = 0; x < tiles.Columns; x++)
                {
                    tiles.Add(new WallTile(), x, y);
                }
            }
        }
    /// <summary>Load the level.</summary>
    public void LoadTiles(string path)
    {
        this.path = path;
        List<string> textlines = new List<string>();
        StreamReader fileReader = new StreamReader(path);
        string line = fileReader.ReadLine(); // first row of the level
        width = line.Length; // calculated level width
        while (line != null)
        {
            // read all lines
            textlines.Add(line);
            line = fileReader.ReadLine();
        }
        height = textlines.Count - 2;

        // add the hint
        GameObjectList hintfield = new GameObjectList(100);
        Add(hintfield);
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1); // hint background
        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); // hint text
        hintText.Text = textlines[textlines.Count - 2]; // last line in the level descriptor
        hintText.Position = new Vector2(120, 25);
        hintText.Color = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); // timeout
        Add(hintTimer);

        TimerGameObject timer = new TimerGameObject(101, "timer");
        timer.Position = new Vector2(25, 30);
        timer.TimeLeft = TimeSpan.FromSeconds(double.Parse(textlines[textlines.Count - 1]));
        Add(timer);

        // construct the level
        TileField tiles = new TileField(height, width, 1, "tiles");
        Add(tiles);
        // tile dimentions
        tiles.CellWidth = 72;
        cellWidth = 72;

        tiles.CellHeight = 55;
        cellHeight = 55;
        
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < height; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }
    }
Ejemplo n.º 7
0
    public void LoadTiles(string path)
    {
        int width;
        List<string> textlines = new List<string>();
        StreamReader fileReader = new StreamReader(path);
        string line = fileReader.ReadLine();
        width = line.Length;
        while (line != null)
        {
            textlines.Add(line);
            line = fileReader.ReadLine();
        }
        TileField tiles = new TileField(textlines.Count - 2, width, 1, "tiles");

        GameObjectList hintfield = new GameObjectList(100);
        this.Add(hintfield);
        string hint = textlines[textlines.Count - 1];
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1);
        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hint_frame.Meebewegen();
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2);
        hintText.Text = textlines[textlines.Count - 2];
        hintText.Position = new Vector2(120, 25);
        hintText.Color = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer");
        this.Add(hintTimer);

        GameObject.lvltimer = Convert.ToDouble(textlines[textlines.Count - 1]); // de laatste lijn in de textfile heeft de tijd

        this.Add(tiles);
        tiles.CellWidth = 72;
        tiles.CellHeight = 55;
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < textlines.Count - 2; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }
    }
Ejemplo n.º 8
0
    public void LoadTiles(string path)
    {
        List <string> textLines  = new List <string>();
        StreamReader  fileReader = new StreamReader(path);
        string        line       = fileReader.ReadLine();
        int           width      = line.Length;

        while (line != null)
        {
            textLines.Add(line);
            line = fileReader.ReadLine();
        }
        TileField tiles = new TileField(textLines.Count - 2, width, 10, "tiles");

        //Store the size of the game
        int height = textLines.Count - 2;

        levelSize = new Vector2(width, height);
        //--------------------------

        GameObjectList hintField = new GameObjectList(100);

        Add(hintField);

        //Plit last textline at "=" and store the time
        string timeLine = textLines[textLines.Count - 1];

        string[] timeStuff = timeLine.Split('=');
        time = double.Parse(timeStuff[1]);
        //--------------------------------------------

        SpriteGameObject hintFrame = new SpriteGameObject("Overlays/spr_frame_hint", 0);

        hintField.Position = new Vector2((GameEnvironment.Screen.X - hintFrame.Width) / 2, 10);
        hintField.Add(hintFrame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 0);

        hintText.Text = textLines[textLines.Count - 2];

        hintText.Position = new Vector2(120, 25);
        hintText.Color    = Color.Black;
        hintField.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintField, 0, "hintTimer"); // Here

        Add(hintTimer);

        //Assign camera
        camera = new Camera(levelSize);

        Add(tiles);
        tiles.CellWidth  = 72;
        tiles.CellHeight = 55;
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < textLines.Count - 2; ++y)
            {
                Tile t = LoadTile(textLines[y][x], x, y);
                tiles.Add(t, x, y);
            }
        }
    }