Wednesday, 24 August 2011

If life was a game, this is how it might look like

start

define:
energy_max = 10; //maximum energy available to perform a task, also starting energy
xp = 0; //starting experience
task_action = 0; //0: no task has been assigned, 1: task has been assigned
task_status = 0; //0: task not completed, 1: task completed
task_count = 0; //starting number of completed tasks player has

while task_action == 1 and task_status == 0 //task has been assigned but not completed
energy_max = energy_max - task_energy;
if energy_max < 0 //check that character has enough energy to carry out assigned task
then print("Not enough energy, need energy boost. Task will be aborted.") //warn player that extra energy is required to complete task
else xp = xp + task_xp; //increase player's experience from completing task
task_status = 1; //task completed
task_action = 0; //assigned task has been completed
task_count = task_count + 1; //note number of player's completed tasks
end

1 comment:

p_falcon said...

// can include more nonlinearities, physical outputs
// and better legibility

# include "stdio.h"

# define ENERGY_MAX 10
# define MIN 0

int main(int argc, char* args[])
{
// defining values used - it might be better to use
// floating point numbers instead?
int energy_max = ENERGY_MAX;
int xp = MIN;
int task_action = MIN;
int task_status = MIN;
int task_count = MIN;
int task_energy = MIN;
int task_xp = MIN;

// adding this...
int alive = !MIN;
int deadc = MIN;

while(alive)
{
printf("How many hours would it take?");
scanf("%i",&task_energy);

printf("How much would I gain from this?");
scanf("%i",&task_xp);

printf("\n");
task_action=1;
task_status=0;

while(task_action&&!task_status)
{
energy_max-=task_energy;

if(!energy_max)
{
printf("You have just passed out.\n\n");
energy_max+=ENERGY_MAX;
deadc++;
}

// thinking of adding in some Murphy's Law uncertainties here...

else
{
xp+=task_xp;
task_status++;
task_action--;
task_count++;
}

}

if(deadc>ENERGY_MAX),alive--;
}

if(task_count>1),printf("Congratulations - you've done %i things in your lifetime!",task_count);

else if(task_count),printf("A lifetime well-spent on doing a single thing!");

else,printf("Living counts as something - so you still did one thing!");

fflush(stdin);
getchar();

return 0;
}