Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Now what I want to do is Draw a small area on the screen with the items sprite and the total number of that item that I have collected. I am not really interested in the Drawing aspect is more of the extraction of the data in/out of the inventory.</p> </blockquote> <p>Sound like you want to use a linq count.</p> <pre><code>InventoryObjects.Count(inventoryObject =&gt; inventoryObject.Type == ObjectTypes.Asteroid); WorldObjects.Count(worldObject =&gt; worldObject.Type == ObjectTypes.Asteroid); </code></pre> <p>You can think of this like SQL</p> <p>SELECT COUNT([dbo].[World Objects].[Object]) WHERE [dbo].[World Objects].[Type]='Asteroid'</p> <p>However, if you are looking to extract an item and add it to another list, you should take the advice of Reed Copsey.</p> <hr> <p><strong>Edit</strong></p> <p>So assuming that you have a <code>Player</code> Class then perhaps it structure like so,</p> <pre><code>Public Class Player { public List&lt;GamePlayObject&gt; Inventory {get; set;} } </code></pre> <p>You also have a <code>World</code> Class and perhaps it has similar,</p> <pre><code>Public Class World { public List&lt;GamePlayObject&gt; Objects {get; set;} } </code></pre> <p>Your <code>GamePlayObject</code> may look like so,</p> <pre><code>Public Class GamePlayObject { public ObjectType Type {get; set;} } </code></pre> <p>So assuming you've initialized your world and it has several objects, and you know which object you wanted to remove from said World. This is certainly not be the best approach in terms of resources and optimization, (This would be where Reed Copsey's answer would come in handy) but, you could...</p> <pre><code>var targetObject = World.Where(gamePlayObject =&gt; (DesiredConditions)) World.Objects.Remove(targetObject); Player.Inventory.Add(targetObject); </code></pre> <p>Where <code>DesiredConditions</code> would maybe be something like <code>gamePlayObject.IsCollidedWith</code></p> <p>Once you've done this you can query the <code>Player</code>'s inventory.</p> <pre><code>var IronCount = Player.Inventory.Count(gamePlayObject =&gt; gamePlayObject.Type == ObjectType.Iron); </code></pre> <p>Hope this clears things up.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload