Skip to main content

Game engine API · Lesson 7

Game Catalog

Compare OyunMotoru.oyunlar(), Oyunlar2D.oyunlar() and Oyun3D.oyunlar(). List the 8 2D games and 8 3D scenes from runtime data.

The catalog is not a fixed array; it is derived from the registry. Registering a new game updates the list automatically.

What you will learn

  • The oyunlar() return shape
  • Separating 2D games from 3D scenes
  • Fetching one record with oyunBilgi(ad)

API signatures

CallResult
oyunlar()list of registered games/scenes
oyunBilgi(ad)one record or null
kayitliModuller()array of module names

Three lists, three scopes

Oyunlar2D.oyunlar() returns only the 2D games: labirent, yakalama, blok-kirna, sayi-yakalama, kelime-eslestirme, renk-siralama, hafiza, zamanlayici.

Oyun3D.oyunlar() returns eight scenes: geometri, renkler, gunes-sistemi, sekiller, molecule (molekul), colour cube (renk-kupu), spectrum (tayf), cell (hucre). The engine oyunlar() merges both lists with a mod field; with both modules registered there are 16 records.

Query the catalog

var M = window.OyunMotoru;
console.log(M.kayitliModuller()); // ['2d','3d']
console.log(M.oyunlar().length);  // 16

var oyun2d = M.oyunlar().filter(function (k) {
  return k.mod === '2d';
});
console.log(oyun2d.length); // 8
console.log(window.Oyunlar2D.oyunlar().map(function (o) {
  return o.id;
}));

What happens in this code? Each record carries mod, id, ad and aciklama. A broken module cannot break the list; modules that throw while being read are skipped.

Fetching a single record

oyunBilgi(ad) searches the catalog by id and returns null when nothing matches. Ids are case-sensitive; use the lowercase form shown below.

Use the game information

var M = window.OyunMotoru;
var bilgi = M.oyunBilgi('hafiza');
if (bilgi) {
  console.log(bilgi.ad, bilgi.aciklama);
  M.basla('2d', {
    kok: document.getElementById('oyunAlani2D'),
    oyun: bilgi.id
  });
}
console.log(M.oyunBilgi('yok-boyle-oyun')); // null

What happens in this code? Generating cards from this list means a newly registered game appears in the UI without touching the markup.

Common mistakes

Wrong approachResultCorrect approach
Expecting 8 but seeing 16The 3D scenes are includedFilter by the mod field
Writing a fixed arrayNew games stay invisibleUse oyunlar()
Skipping the null checkProperty access failsGuard with if (bilgi)
Passing ad instead of idUnknown game errorUse the lowercase id

Try it yourself

Group the oyunlar() result by mod and print the 2D and 3D counts separately. Confirm that the total is 16.