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 6163295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:48:10+00:00 2026-05-23T21:48:10+00:00

Oh, hi. I’m a junior java developer working in my free time on some

  • 0

Oh, hi. I’m a junior java developer working in my free time on some 2D tile-based game. Now I am trying to implement the very basic things in game Model – how objects of various types interact with each other.
I hope to add network support someday, so now acting objects change their state synchronously – when singleton Ticker (running in its own thread) notifies subscribed objects with .tick(), making them execute command objects previously assigned to them.
Implementing simple one-tick activities like picking up some object was quite simple, like:

abstract class Character extends AbstractActing {

    void tick() {
        action.execute();
    }

    private void pickUp(Item item) {
        inventory.add(item);
    }

    private IAction action;

    //...

    class PickUp implements IAction {
        void execute() {
            //check if allowed to do
            pickUp(item)
        }

        PickUp(Item item) {
            this.item = item;
        }

        private Item item;
    }
}

Now I want to write a skeletal implementation for more complicated actions like channeling some spell, kicking one’s ass or running to point on map. I suppose that objects representing these complex actions will inside interprete themselves into queue of simple, atomic instructions. For example, “Walk(Location x)” command will internally use pathfinding algorithms to build queue of “DoOneStep(Direction d)” and will be able to rebuild it if something will happen in the way.
The problem is that single atomic step will need more information to be executed like Character’s speed or ground type. BTW, depending on character’s speed I might wanna change Character’s real location not every single tick. I think I have to add some step-executor object inside Action that observes objects related to calculations and updates its state.

My queston (finally!) is – is there some well-known design patterns fore me to meditate on? My code grows more unintelligible and un-inheritable with every edit, maybe I shall rewrite entire acting system?

  • 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-05-23T21:48:10+00:00Added an answer on May 23, 2026 at 9:48 pm

    You might want to consider using the State pattern (also known as the State Machine pattern, since it is based on the mathematical theory of finite state machines). The idea is that a character (or any other kind of game object, for that matter) is always in exactly one state (picked from a predetermined collection of possible states), and that certain events can trigger transitions to other states. Then, the tick() method can perform different actions depending on the current state. A more advanced version of this pattern is to have classes for the different states, and use instances of the state classes to collect information about e.g. how long you have been in that state. So in your case, possible states are Walking, PickingUp, Idle, etc.

    Actually, you’ve almost invented this pattern yourself, as your IAction concept is essentialy the same thing as a state. So I think you’re headed in the right direction.

    Edit: To be more specific to your situation, I’d suggest that you simply drop the requirement that an IAction is atomic; instead, it may last for several ticks. IAction.execute() should simply perform as much of the action as can be performed in the course of one tick, such as walking a small distance along the desired path. The action itself can e.g. keep track of where the target position is, how far one has come, etc.

    (Historical note: The original Unreal Engine was based on states (and I’d guess that the newer versions are too) – when coding e.g. a custom weapon, you’d split the code into one section for each possible state, such as Firing, Reloading, Idle, etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.