Welcome Guest, Not a member yet? Register   Sign In
How would I code this?
#1

[eluser]IamPrototype[/eluser]
Hello ya'll. I've been thinking like a maniac for the last two hours. For the fun of it I'd like to create a mini browser game with CodeIgniter (nothing public, just local.. so I can expand my skills). Anyways here's what I'd like to do.

- You'll start at level 1, okay that's pretty easy.
- There has to be a shop, where you can buy new "weapons"
-- Each weapon has an attack value like 544.
-- The higher the attack value is the higher the chance is to successful a "job".

I don't know if any of you know MouseHunt, the mini game on Facebook, well that's how it works out. You start in a town, buys a trap, hunt mouses every 15 minutes, but I don't want to have that 15 minutes break. The only thing I guess I can't figure out to code is the part where you buy a better trap and you'll be able to catch better and bigger mouses.

--Of course the "job" have to be a certain level, the higher level the more hard it's going to be. So it's like a "huge" mathematic string where I've to include the weapons attack and the "jobs" level.

Sorry if you don't understand what I'm trying to code, but english isn't my native language! Any misunderstandings or questions? Feel free to ask me. Smile
#2

[eluser]Dam1an[/eluser]
So the only part you're not sure of is the equation for if an attack (or job) is successful?
I could do something like
$success = ((weapon_rating * random(1-100)) / job_difficulty) > difficulty

where weapon rating is a number between 1 and 1000
random(1-100) is a random number between 1 and 100
This will give you a value between 1 and 100,000
Job difficulty is how hard the job is, a number between 1 and 100,000
Difficulty is how much fudge you have, I recommend ~0.8 as a good starting point

You could even make it so that the random part start off between 1-100,
but as you get more experience, it starts at a higher number
#3

[eluser]IamPrototype[/eluser]
0.8.. user level, right?

So it goes like this:

Code:
<?php

$weapon = 544;
$job_difficulty = 4000;
$fudge = 0.8;

$success = (($weapon * rand(1,100)) / $job_difficulty) > $fudge;

if ($success)
{
echo "YES";
}
else
{
echo "NO";
}

?>

Output: YES

So the job will be successful no matter what... and... uhm, wouldn't it be a lot more "real life" if you was able to successful the job BUT sometimes you could fail. Your code is really good, but the higher your level and weapon is the higher the chance is to successful, but sometimes you will fail because something did happen.. like you lost your... thing... etc. It's hard for me to explain, let me try this way:

In MouseHunt.. you'll start catching white and brown mices, when you're on the next level.. you'll be able to catch better mouses, but sometimes you still fail catching the white and brown etc. because the mouse got the cheese without setting the trap off, get the idea? Smile

EDIT: Just tried to update my scripts a few times.. and I DO fail sometimes, sorry, I didn't notice. I guess the random number between 1 and 100 does that part, right?

---

Anyways, the jobs could have a certain amount of EXP, nothing random, but a number that I'll pick. So everytime the job is a success the users fudge will be plussed with the EXP.

I could code an extension for the default controller and check the users level, or would that be a bad idea? What I'm thinking of is:

Code:
if ($user_level > 500) {
// update level
} else {
if($user_level > 1000) {
// update
} // and so on
}

I guess that wouldn't be the best way on how to do it Sad And receiving the levels from a database table would be better, so I could create custom levels whenever I want to.. would it be good to use some loop here, or?

P.S: You're helping me a lot, thanks! Smile
#4

[eluser]Dam1an[/eluser]
Maybe fudge wasn't the best choice of words
Its just a value the left part needs to be greater then to evaluate to true, so the higher this is, the fewer things will succeed
And if a mission is successful, uoi'll want to either lower the value on the rigth of the equation, or increase the lower value of the rand function
#5

[eluser]IamPrototype[/eluser]
Kay, thanks. Smile




Theme © iAndrew 2016 - Forum software by © MyBB