<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[frage zum ifstream]]></title><description><![CDATA[<p>hab eine quellcode gefunden verstehen aber eine funktion nicht<br />
<a href="http://lazyfoo.net/SDL_tutorials/lesson29/index.php" rel="nofollow">http://lazyfoo.net/SDL_tutorials/lesson29/index.php</a></p>
<pre><code class="language-cpp">bool set_tiles( Tile *tiles[] )
{
    //The tile offsets
    int x = 0, y = 0;

    //Open the map
    std::ifstream map( &quot;lazy.map&quot; );

    //If the map couldn't be loaded
    if( map == NULL )
    {
        return false;    
    }

    //Initialize the tiles
    for( int t = 0; t &lt; TOTAL_TILES; t++ )
    {
        //Determines what kind of tile will be made
        int tileType = -1;

        //Read tile from map file
        map &gt;&gt; tileType;

        //If the was a problem in reading the map
        if( map.fail() == true )
        {
            //Stop loading map
            map.close();
            return false;
        }

        //If the number is a valid tile number
        if( ( tileType &gt;= 0 ) &amp;&amp; ( tileType &lt; TILE_SPRITES ) )
        {
            tiles[ t ] = new Tile( x, y, tileType );    
        }
        //If we don't recognize the tile type
        else 
        {
            //Stop loading map
            map.close();
            return false;
        }

        //Move to next tile spot
        x += TILE_WIDTH;

        //If we've gone too far
        if( x &gt;= LEVEL_WIDTH )
        {
            //Move back
            x = 0;

            //Move to the next row
            y += TILE_HEIGHT;    
        }
    }

    //Close the file
    map.close();

    //If the map was loaded fine
    return true;
}
</code></pre>
<p>wie werden den die tiletypen gesetzt in dieser funktion<br />
denn die map datei enthält viele zahlen(als txt datei) und das ganze würd zu einen int(tileType) übertragen</p>
<p>oder sehe ich das falsch</p>
<p>aber bei<br />
for( int t = 0; t &lt; TOTAL_TILES; t++ ){<br />
......<br />
.....<br />
tiles[ t ] = new Tile( x, y, tileType );<br />
...<br />
..<br />
}<br />
würd nur eine zahl übertragen (unzwar die erste zahl in der map datei,und dann die zweite..usw)</p>
<p>wie funktionirt das jetzt</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/197762/frage-zum-ifstream</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 12:14:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/197762.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Nov 2007 15:03:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to frage zum ifstream on Wed, 14 Nov 2007 15:03:08 GMT]]></title><description><![CDATA[<p>hab eine quellcode gefunden verstehen aber eine funktion nicht<br />
<a href="http://lazyfoo.net/SDL_tutorials/lesson29/index.php" rel="nofollow">http://lazyfoo.net/SDL_tutorials/lesson29/index.php</a></p>
<pre><code class="language-cpp">bool set_tiles( Tile *tiles[] )
{
    //The tile offsets
    int x = 0, y = 0;

    //Open the map
    std::ifstream map( &quot;lazy.map&quot; );

    //If the map couldn't be loaded
    if( map == NULL )
    {
        return false;    
    }

    //Initialize the tiles
    for( int t = 0; t &lt; TOTAL_TILES; t++ )
    {
        //Determines what kind of tile will be made
        int tileType = -1;

        //Read tile from map file
        map &gt;&gt; tileType;

        //If the was a problem in reading the map
        if( map.fail() == true )
        {
            //Stop loading map
            map.close();
            return false;
        }

        //If the number is a valid tile number
        if( ( tileType &gt;= 0 ) &amp;&amp; ( tileType &lt; TILE_SPRITES ) )
        {
            tiles[ t ] = new Tile( x, y, tileType );    
        }
        //If we don't recognize the tile type
        else 
        {
            //Stop loading map
            map.close();
            return false;
        }

        //Move to next tile spot
        x += TILE_WIDTH;

        //If we've gone too far
        if( x &gt;= LEVEL_WIDTH )
        {
            //Move back
            x = 0;

            //Move to the next row
            y += TILE_HEIGHT;    
        }
    }

    //Close the file
    map.close();

    //If the map was loaded fine
    return true;
}
</code></pre>
<p>wie werden den die tiletypen gesetzt in dieser funktion<br />
denn die map datei enthält viele zahlen(als txt datei) und das ganze würd zu einen int(tileType) übertragen</p>
<p>oder sehe ich das falsch</p>
<p>aber bei<br />
for( int t = 0; t &lt; TOTAL_TILES; t++ ){<br />
......<br />
.....<br />
tiles[ t ] = new Tile( x, y, tileType );<br />
...<br />
..<br />
}<br />
würd nur eine zahl übertragen (unzwar die erste zahl in der map datei,und dann die zweite..usw)</p>
<p>wie funktionirt das jetzt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1403149</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1403149</guid><dc:creator><![CDATA[kiba91]]></dc:creator><pubDate>Wed, 14 Nov 2007 15:03:08 GMT</pubDate></item><item><title><![CDATA[Reply to frage zum ifstream on Wed, 14 Nov 2007 15:07:30 GMT]]></title><description><![CDATA[<p>Die x- und y-Koordinaten der Teile werden von 0 an hochgezählt, den zugehörigen Teil-Typ liest du in Zeile 22 aus (ja, da steht nur eine Zahl in der Datei - die einzelnen Werte werden zeilenweise den Tile's zugeordnet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1403154</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1403154</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 14 Nov 2007 15:07:30 GMT</pubDate></item></channel></rss>