質問

I created a card game in silverlight a year or so ago in order to learn a bit about Silverlight.

I am now wanting to make a HTML5 version of the game in an effort to learn a little bit more about that.

I am thinking I'd like to take advantage of stuff like Knockout.js and WebSockets and the canvas element.

Now what I'm confused about is how to lay out the cards on the screen.

With Silverlight I was able to make a "Hand" control, which was made up of two sub controls - the cards the player has in their hand and the ones they have on the table. And they in turn were made up of Card controls.

Now I don't believe there is the concept on a User Control in javascript. So I am possibly thinking about this in entirely the wrong way.

So my question is - how could I lay out some cards on the table and perhaps make reuse of something for each player?

I have a client side JSON object called game, which contains an array of players. Each player has a hand which is made up of an array of in-hand cards and on-table cards. Ideally I would like to bind these to something using Knockout.js - but I don't know what I could bind to.

Would I simply position images (of cards) on a canvas? Is there a way to make some kind of Hand object that each player could have and that I could bind to?

Any advice? Or sample code you've seen elsewhere?

役に立ちましたか?

解決

There is no view construct such as XAML or DOM in the canvas. With canvas you are literally drawing lines, fills, images, and such with really basic functionality. You will need a canvas library to find, or more probably build, the types of controls you mention. See Processing.js for a possible canvas library candidate.

他のヒント

Instead of using a single canvas for rendering the game I would probably use a canvas per card and then layout them using CSS.

If you decide to choose this route you'll need to figure out how to sort out selections, possible dragging etc. This should be easy compared to doing all that on a single canvas though since in this case you can rely on vanilla JS and CSS.

If you can provide some kind of visual mockup I can probably give you some more specific pointers.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top