Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:15:49+00:00 2026-06-18T11:15:49+00:00

I have a game with 2 players. They have almost same beginning data and

  • 0

I have a game with 2 players. They have almost same beginning data and of course it changes in the course of the game.

I am guessing I need some king of constructor object that I will replicate and then modify, also I need it to be JSON for easy ajax sending.

Is there a design pattern that can help me? I prefer not to use database since I need the data only for a single game instance.

This is the structure I use now for one player:

player = {
    "active" : true,
    "room" : openRoom,
    "id" : playerID,
    "name": username,
    "hp" : 5,
    "units" : {
        1 : {
            "id" : 1,
            "hp" : 3,
            "row" : 1,
            "square" : 1
        },
        2 : {
            "id" : 2,
            "hp" : 4,
            "row" : 2,
            "square" : 1
        },
        3 : {
            "id" : 3,
            "hp" : 5,
            "row" : 3,
            "square" : 1
        }
    }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:15:50+00:00Added an answer on June 18, 2026 at 11:15 am

    There are several design patterns regarding object instantiation and initialization. However, you don’t seem to need any inheritance or “property sharing” techniques, so a very simple function that returns a new object should fit well as a constructor. You even can use object literals in coding it.

    An example of two constructor functions, each with some parameters:

    function makePlayer(id, name, units) {
        return {
            "active" : true,
            "room" : openRoom,
            "id" : id,
            "name": name,
            "hp" : 5,
            "units" : units
        };
    }
    var uuid = 1;
    function makeUnit(row) {
        return {
            "id" : uuid++,
            "hp" : 3,
            "row" : row,
            "square" : 1
        };
    }
    var player = makePlayer(playerId, username, [makeUnit(2), makeUnit(4), makeUnit(3)]);
    var jsonstring = JSON.stringify(player);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some tables that contain data about players and the games they have
I have data which is related to movement of players in a game. Each
I have the need to create a database for some data I have, and
I have a game server (WoW). I want my players to download my custom
I have a big 3d game that lets players build and create interesting and
I have a database that tracks players through their attempts at a game. To
Support we have an n * m table, and two players play this game.
In a game, I have players where their position and orientation is stored in
Usually players in a soccer manager game have market values. The managers sell their
I have one table GAMES and another PLAYERS . Currently each game has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.