Calculation......

Discussion in 'PHP' started by Namuk, Mar 15, 2008.

  1. #1
    i got a problem about calculation...
    this is my problem...

    $score = 0;

    //this is come form random choose by computer.
    if(condition)
    {
    $result = 1;
    }
    elseif(condition)
    {
    $result = -1;
    }
    else
    {
    $result = 0;
    }

    //calculate the value of result as score.
    $score +=$result

    i want to this repeat calculate as long as i need...
    but i need the $score will be change value to the next calculation.

    example;
    //first calculate
    $score = 0
    $result= 1

    so $score +=$result = 0+1 = 1

    //second calculation
    $score=1 //come from first calculation
    $result=1

    =2

    //third calculation
    $score =2 //come from second calculation
    $result=-1

    =1


    so how do i change the value of $score after calculation to be the total value
    and bring it to the next operation.

    please help me... i have try so many time but i don't, how to change it....
    the value of $score do not change.....

    thanks.....
     
    Namuk, Mar 15, 2008 IP
  2. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #2
    use while loop if you have limited the game, i mean if some ones time over then it should stop like this ..

    while(time is over)
    {
    your whole calculation code here
    }

    or use if to check $score ....
    if($_POST['score'] === 0)
    { $score = 0}

    put it on top of your calculation code. and other code is ok.
     
    AdnanAhsan, Mar 15, 2008 IP
  3. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for this suggestion....
    can u explain me more about how to limit the game...?
    if i limited the game only 1 minute....
    how do i does it..... and calculate the score?...

    please.... thanks...:confused:
     
    Namuk, Mar 15, 2008 IP
  4. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #4
    i did not see your game, and i am not aware what you have done till now, i use limit word as a example, so it doesn't needed ...
     
    AdnanAhsan, Mar 16, 2008 IP
  5. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ooo... my game is a simple one....
    player just choose three character like A,B and C.
    the computer also choose that...A,B and C randomly.

    the score is come after the game....
    if player win.... they get 1 point
    lose..... -1 point
    and if draw...0 point.

    so, if i set the game is only 5 round, how do i set the time limit of that?...
     
    Namuk, Mar 16, 2008 IP
  6. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #6
    just declear a function for that or a session variable for countng rounds, when some one played 5 rounds, session variable will have value of 5, give a condition if session variable has 5, than stop the game as you want ...

    see a simple example

    $_SESSION['round'] += 1;
    if($_SESSION['round']==5)
    {
    header('Location: Finalscore.php');

    exit;

    }

    in finalscore.php you can unset session :). i hope you got it . please correct if any thing wrong, i just wrote a code here from my sense, i did not try it so correct it if any thing goes wrong :)
    Thanks
     
    AdnanAhsan, Mar 17, 2008 IP