HTML5 games have viewable source code. Is there a way to make them like swf file?
How to hide the game algorithm?
Part of the really nice things about the web as it's all human-readable. This makes it an excellent learning resource. If you're telling me that you've never looked at the source of a website to learn how it does something, then feel free to tell me I'm wrong.
I'm all bout sharing the love with code, otherwise I wouldn't answer questions on a website about offering help, all for free, would I?
The best you can do is to protect against bandwidth theft and obfuscate if you really feel the need, but it's not going to stop people if they're really determined.
Even if you don't obfuscate your code, HTML/ JS is already about the same level of difficulty to reverse engineer as SWF.
SWF files contain the original Actionscript code, (IIRC), with comments etc, unless they're obfuscated. Names of objects etc, are also contained within the SWF.
SWF decompilers / recompilers exist, and just because you can't see it with a text editor, does not mean SWF is in any way safe from reverse engineering.
In fact the level of obfuscation is really no different to a SWF. You could obfuscate your JS code using some obfuscator, but that just makes bug reports more difficult to interpret.
You probably want to focus your efforts into making something worth stealing, rather than preventing people stealing it. Plenty of SWFs get ripped off and used for unauthorised purposes (with changed graphics, etc)
Use the free Yahoo YUI compressor.
I use it because it compresses my code drastically (including removing comments and unnecessary whitespace). This lets me comment and structure my code exactly how I want without worrying about how easy I'm making it for thieves.
(Though with YUI compressor you may need to augment its functionality to also get rid of function names. I have altered the way I name functions specifically for the purpose of automatically and selectively removing most function names. This may require some custom code on your end.)
HTML5 games have viewable source code. Is there a way to make them like swf files?
Yeah, use Flash and translate your code to ActionScript.
How would one go about hiding the game algorithms?
In absolute terms, you can't do that.
Obfuscation is nothing but a very thin barrier for somebody who'd be serious about stealing your code. Still, it's simple to setup, it can repulse the most dumb script kiddies, and it's the only thing you can do to protect client-side code. It has the additional benefit that it reduces the script size (faster download) and can even optimize the code (faster execution). Check this entry on Stack Overflow for details on obfuscation. Summary: you have plenty of options. I personally tried UglifyJS and had very satisfactory results.
The only tool I know that currently supports HTML5 in the context of Gaming development is JScrambler. I'm not sure if others will work.
For the porpoise of discussion, obfuscation is not a silver bullet. We have software that is compiled encrypted, protected with several anti copy solutions and still o can get them without paying. That said I believe that obfuscation beats leaving your code open for any one to read when you intention is not that.
I really love open source and support the movement yet sometimes closing the source makes lots of sense.
You can use native code. Programming on C++ and compile for HTML5. Cocos2d-X is a library that work on iOS, Android, and HTML5. Your code will be hidden.