Timing in a Turn-Based Game

Discussion in 'Game Development (Technical)' started by aaro, Apr 24, 2014.

  1. aaro

    aaro New Member

    Joined:
    Apr 24, 2014
    Messages:
    6
    Likes Received:
    0
    Hi there!

    Quick introduction: I'm fairly new to programming (I've taken a few introductory programming courses in college, but nothing language-specific), and have chosen to learn Python for practicality and fun. In an effort to apply what I learn, I'm building a game piece by piece, testing new programming concepts as I acquire them. The game I'm working on is a simple ASCII, turn-based "pseudo-tower defense/roguelike", and though it's very early in the development phase, I'm having a lot of fun.

    Now, my question is this: I want to create a global resource (in this case, oxygen) that begins at 100%, and then is reduced by a certain value (typically 1-3%) per turn the player makes. How the heck would I do that?

    Please know, I don't need actual code or anything (though pseudo-code would be appreciated). I'm really just more curious about how such a thing would be implemented. Actually creating it is still a ways down the road, and at this point, I'm just interested in the logic of it. So far, I've been able to construct the logic for most of the game, but this is just puzzling to me.

    I'd really love to just have a discussion about this particular aspect of programming, and would really appreciate any guidance the Indie Gamer community could offer.

    Thanks in advance!
     
  2. bantamcitygames

    Administrator Original Member Indie Author Greenlit

    Joined:
    Jul 27, 2004
    Messages:
    1,737
    Likes Received:
    79
    Hi aaro, and welcome to indiegamer! I'd be happy to help, but I'm not sure I understand the question fully... here goes anyway: Can you just create a 'global' variable (not sure if Python has these), or a member variable on your player class would work as well. Each time the player takes a turn you would decrease this variable by 1-3 randomly or based on whatever logic determines that number.

    Does that make sense or did I miss the point of your question?
     
  3. aaro

    aaro New Member

    Joined:
    Apr 24, 2014
    Messages:
    6
    Likes Received:
    0
    Hi, Bantam!

    Thanks for the welcome, and you hit my question right on the head. Python does have global variables (I don't know how to use them yet, but I am aware of them), and the idea seems effective, but leads to my next question: what mechanism would measure a player's turn? Maybe something that modifies the variable after receiving any type of raw input?

    The question seems so difficult in my mind, I guess, because my concept of a 'turn' is slightly non-traditional. In this game, a turn is any player action, from entering a command at the virtual computer interface (used to set system statuses, monitor vitals, etc), to actually engaging in a roguelike activity by moving the '@' symbol.

    If it seems nonsensical, I'm sorry, the idea is somewhat difficult to explain, and I don't want to bore you with the details of the actual game.
     
  4. dannthr

    dannthr New Member

    Joined:
    May 11, 2007
    Messages:
    456
    Likes Received:
    2
    Both of these issues are about keeping track of information. In programming, information is stored in variables. Numerical information can be stored in the various numerical variables.

    Just as you can have a variable that stores the amount of oxygen left in the game, you can have a variable that stores the number of turns that have passed in the game.

    In games, typically, events are cued from within a main loop that allows your program to continue running until the program logic determines that the game is done. Logic is measured by mathematical operators and conditions are set up to determine the various outcomes based on the information stored, the events that occur, or actions/reactions that result from either of those two things.

    It might be a good idea for you to start with a simpler game--take the simplest game you know how to play and break it down into pseudo-code (its setup, the information that is stored, where it is stored, and the various actions and events that take place during the repeated turns of the game, etc.

    Good luck!
     
  5. buto

    Original Member

    Joined:
    Oct 2, 2006
    Messages:
    45
    Likes Received:
    0
    How about a member function in your player class called 'action_performed'. Everything you consider an action would call this method. In the method 'action_performed' you can now perform all tasks which have to take place before the next action can be performed, e.g. decrease the oxygen-member variable as suggested by Bruno.
    Regards,
    Sebastian
     
  6. aaro

    aaro New Member

    Joined:
    Apr 24, 2014
    Messages:
    6
    Likes Received:
    0
    dannthr, thanks for the great explanation!

    And yes, I'm starting to see that, even though I'm beginning small with the intention of expanding the complexity of the game gradually, it's quickly spiraling out of control. Thanks for the advice, and I definitely think I'll simplify my game for now.

    buto, that is also a great suggestion. I'll experiment with the method idea, and eventually (maybe) I'll be able to implement it when I revisit this game concept. Thanks for the advice!
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer