aspose file tools*
The moose likes Game Development and the fly likes Web Browser Game in Java/JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Web Browser Game in Java/JSP" Watch "Web Browser Game in Java/JSP" New topic
Author

Web Browser Game in Java/JSP

Bruno Sysemp
Greenhorn

Joined: Apr 15, 2011
Posts: 3
Hi all, I found this forum today and I'd like to ask you some questions.
In 2006 I created a PHP Browser Game (Web Game like Ogame/Travian) and now, for fun and to learn new things, I'm thinking to convert it to Java/JSP.

I'm learning struts, tiles, hibernate and others... do you have any tips for me? Do you think its a good idea to use all of this?

In PHP I had a problem, every time a user made a click I had to instantiate all the buildings, researches and ships available at the game.
This configuration game units, because they never change, should always be loaded on memory and when the user clicks I could access them.
First, do you agree with this approach? If yes, how do you recommend it to be implemented on Java?

Another idea is to have a background Java application always running on the server and the JSP request some how creates a thread in the main application. The new thread would be responsible for processing the data and send the response to JSP. This way my main application shared some data between all threads/requests.
Again, what do you think about this idea? Its possible? How? Only with Sockets or Webservices?

Thank you for your time.
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Bruno Sysemp wrote:
I'm learning struts, tiles, hibernate and others... do you have any tips for me? Do you think its a good idea to use all of this?


Yes. Frontend, presentation, persistence, all are needed, all are proven choices. Especially "Others" will be helpful ;-).


In PHP I had a problem, every time a user made a click I had to instantiate all the buildings, researches and ships available at the game.
This configuration game units, because they never change, should always be loaded on memory and when the user clicks I could access them.
First, do you agree with this approach? If yes, how do you recommend it to be implemented on Java?

Another idea is to have a background Java application always running on the server and the JSP request some how creates a thread in the main application. The new thread would be responsible for processing the data and send the response to JSP. This way my main application shared some data between all threads/requests.
Again, what do you think about this idea? Its possible? How? Only with Sockets or Webservices?

Thank you for your time.


That's why Java scales so good, i.e. is so fast. The server is running all the time, it is not started for every request like PHP does (ok, not the server itself...). In Java for every request a thread is created automatically, you don't do this manually. The web framework helps you separate your application into the processing and presentation part. You chose Struts (2, I guess), a classic MVC2 framework.

The one thing you don't have in your mentioned software stack is "a something" that maintains application state. You could do this manually, to a degree, by using sessions (with the right scope) or hand-made singletons. A better idea would be to add something like Spring to your software stack. This framework let's you build the application with components that you wire up, with easy scopes and dependency injection (and, er, managed singletons). Caching can be added easily and declaratively, too. So this is the "Others" I would add. No need for sockets or webservices here.
Bruno Sysemp
Greenhorn

Joined: Apr 15, 2011
Posts: 3
Thank you for your answer.

I wrote a Singleton and it worked just fine
Nonetheless I will get more information about Spring.

I have two more questions:
* Today I learned about the "xwork-validator" but I couldn't figure out how to manipulate the error message location, it always appears before the textfield. Is there a way to specify it's location? Do you recommend some other kind of validation to input fields?
* The tutorials I'm following use struts tags like textfield, form, among others. This tags produces HTML code that includes tables and labels that I can't configure. If I want to specify all the tables and where each item is supposed to be, should I use pure HTML and forget about this tags?

Once more, thanks!
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Thats Struts? You should ask this in the Struts forum then.

While Struts is a proven technology (just look at the number if threads in its forum here) it does not appeal to me, so you will not find me there. Struts 1 hit the shelves at the right time, Struts 2 just lived off the name of its predecessor. Personally I find Spring WebMVC, Wicket or GWT much more interesting. For a game I would certainly go the GWT route (unless the target audience are people who loathe JavaScript; then it would be Wicket). But developing with GWT is something of its own and has nothing to do with JSP.

Oh, and Spring does pay off. And just because I mentioned Spring WebMVC: You can use Spring (Core) without WebMVC, you can plug in virtually every frontend you want (like Struts or Wicket).
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
Bruno Sysemp wrote:In PHP I had a problem, every time a user made a click I had to instantiate all the buildings, researches and ships available at the game.
This configuration game units, because they never change, should always be loaded on memory and when the user clicks I could access them.
Surely PHP allows you to remember store such things.

Couldn't you either store the data as either :
  • session variables
  • or store variables and arrays in a file
  • or store in a database


  • Arcade : Alien Swarm
    Board : Chess - Checkers - Connect 4 - Othello
    Adeel Ahmed Fareed Ahmed
    Greenhorn

    Joined: Jun 23, 2011
    Posts: 1
    Hi Friends,
    I am also using struts framework for backend game application and flash for frontend.

    I am facing lots of problems on backend side.
    Actually my game is like SnakeAndLadder and I want to maintain game state and every user will share the data. I put all data and game state in Application/Context Scope, SO users can access the data. Is there any better way to store or maintain game state?

    Anxious about your reply.

    Thanks You..
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Web Browser Game in Java/JSP