As many things that I do, there is most likely a more efficient way of what I'm prescribing. But I wanted to post to let ye know I'm typing a longer post that will be pasted into this one.
edit : Provided I'm not pulled away while I'm typing it.
What I'm thinking here in terms of how to start to tackle this borders between what I "think" I know and a more crude, less beautiful way of doing it. This does not reveal the actual positioning of the code, more like pseudo code.
You have a string containing the weekday. Which could be Monday through Friday. Tuesday might be "TU" and Thursday might be "TH".
For purposes of this example, I'm treating time periods starting from 12:00 AM as period 0.
You have an integer containing the actual period which keeps track of the time. So if it's 5:00 AM, then the actual period might be 10. If the player takes an action, it advances the actual period by the action's period cost and reduces the player's energy by the action's period cost.
i.e. It's 5:00 AM and the player wakes up with full energy.
Code: Select all
$ actual_period = 10
$ player_energy = 48
Let's say the player has the action of "Sleep In", "Eat Breakfast", and "Go to School Early". Sleeping In may cost 4 periods, BUT restore energy. Eat Breakfast may cost 1 period. Go to School Early may cost 3 periods.
Pseudocode.
After choosing the action, change the following variables.
if action == "Sleep In":
$ rest = True
$ period_cost = 4
Once the action is executed, have a function that will check to see if the player will fall asleep. First, we check to see if this is a rest action. Pseudocode.
Code: Select all
if rest == True:
#Execute the action and calculate its benefits.
elif rest == False: #This isn't a rest action, so let's check to see if the player passes out.
if energy - period_cost <= 0: #If say your current energy is 2 and the period cost is 3, this condition will be true
action = "Passed Out" #And so your next real action is passing out. Unless you want to do a hybrid action.
#Run this function again except with the Passed Out credentials, i.e. rest = True, period_cost = 20, resets energy.
elif energy - period_cost > 0: #There is enough energy to execute the action.
energy -= period_cost #Deduct the period_cost from the player's energy.
#Execute the action, calculate its benefits
actual_period += period_cost
#And a function that checks a period's rollover, to be covered later.
Time goes by quicker than I realize and I've barely typed anything.
May have to address calculating the actual_period / time and checking for future events at a later time.
The future events check was going to be if the event is available on that day (perhaps five booleon values, one for each day) and an integer that contains the start time of the action. And say if we wanted to check only 8 periods in advance, a series of loops would be used to check actions available (if action_available_period >= actual_period and action_available <= actual_period + 8, then action_available_flag = True). Ideally, I'd like to throw the action into an array of available actions and display that array onto the screen to be selected. But short of that (and though inefficient still) is another loop that displays the list of possible actions on the screen based on how many actions were flagged as "true".
Will expound on this at a later time (or unless others expound or find more valid and/or effective ways).
edit: You may need a dedicated programmer to write this part of the engine.