Basit bir HTML oyun tasarım / mimarlık önerileri arıyor

2 Cevap php

Imagine that HTML page is a game surface (see picture).
User can have n number of boards (blue divs) on his page. Each board can be moved, re-sized, relabeled, created new and removed.

Inside each board there are m number of figures (purple divs). Each of these user can move inside the board or to another board, re-size, change color and label, delete, add new.
The goal of the game is not important, but let's say it is to rearrange figures in a certain way so that they disappear.

Ama the goal programcı sitenin her kullanıcı için veritabanında to save tüm oyun yüzeyi, ve to load daha sonra döndüğünde.

Yani, nasıl istemci ve veritabanı arasında veri alışverişi hakkında nasıl gidiyor?

alt text

Here's how I think it can be, but maybe there is a better way.
In the database I think of creating tables users, boards and figures.

Sonra bir kullanıcıya ait olduğu tüm SELECT ve onun HTML sayfası (yüzey) oluşturabilirsiniz.

Ama sonra, kullanıcı bu panoları ve figürlerin özellikleri ve I don't know how to track those changes and how to save them back to the database tüm değiştirmek mümkün olacak. Bu JSON kullanılması gereken bir durum var mı?

2 Cevap

I'm assuming this is mostly going on with javascript when they're playing and that you already know how to do that. Well, each figure has propertes, like this: -board (the one it's in) -id -label -width -height -color -x position (relative to board) -y position (relative to board)

So each of those properties will be held in a javascript variable or array while playing. Likewise, the boards also have properties: -id -label -width -height -color -x position (relative to page) -y position (relative to page) So you will hold these in javascript variables as well.

Kaydetmek zaman sadece sunucu üzerinden bu değişkenlerin tüm geçmesi gerekiyor. Yani JSON dize ile xhr olun. Sunucu geri değişkenleri içine JSON çevirmek isteği alır kez veritabanında sopa olabilir. Eğer veritabanı planlıyorsanız yolu uygun geliyor.

Sadece bu kullanıcıya ve (ya normal bir sayfa yük veya XHR'de ile) için uygun bilgi SELECT ve oluşturmak ve onlar gitmek gerekir nesneleri konumlandırmak için çevresindeki her şeyi taşır javascript kullanmak istiyorum geri.

Javascript bir seçenek ise evet, o temelde bir tefrika durumunu açıklayan bir belge (xml veya json veya düz metin, sen javascript kullanarak eğer json muhtemelen kolay olsa, gerçekten o kadar önemli mi) oluşturmak gerekir kurulu.

Daha sonra bir javascript nesne tüm değişiklikler istemci tarafı izlemek, ve olabilir javascript serialize sonra xhr kullanarak sunucuya aktarmak bir dize olarak.

Bu şekilde tarayıcı pozisyonları sergiyi sizin için tüm çalışmaları yapmak ve çünkü ben, bu senaryoda, her nesnenin bir tür (div, açıklık, ne olursa olsun) bir DOM öğesi olmanın ile kapalı en iyi konum, genellikle söyleyebilirim Bu tür, sadece kesinlikle tüm konumlandırmak ve oradan çalışır.