Rolling 6 different dice...

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
QuackerNET
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Dec 11, 2018 3:10 pm

Tue Dec 11, 2018 3:18 pm

I feel noob-ish, or maybe I am overthinking it ...

I got where it is 6 different dice no problem, but lol I want to be able to see if there are any matching sets.

Any help would be appreciated, and thanks in advance.

QuackerNET
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Dec 11, 2018 3:10 pm

Tue Dec 11, 2018 3:29 pm

Code: Select all

    
    /// Script start
	
	/// Creates variable $dice and sets the content to a random number between the 1 and 6
	$dice1 = rand(1,6);
	$dice2 = rand(1,6);
	$dice3 = rand(1,6);
	$dice4 = rand(1,6);
	$dice5 = rand(1,6);
	$dice6 = rand(1,6);

    /// Display $dice 
    echo $dice1;
    echo $dice2;
    echo $dice3;
    echo $dice4;
    echo $dice5;
    echo $dice6;
    
    echo '<br />';
    
	// If $dice1 is a 1 or 5 then display echo message
	if($dice1 == 1) {
	echo "Save?[1]";
    echo"<br/>";
    }
    
    if($dice1 == 5){
        echo "Save?[1]";
        echo"<br/>";
    }
    // If $dice2 is "save"

	if($dice2 == 1) {
        echo "Save?[2]";
        echo"<br/>";
        }
        
    if($dice2 == 5){
            echo "Save?[2]";
            echo"<br/>";
        }
    // If $dice3 is "save"
    if($dice3 == 1) {
            echo "Save?[3]";
            echo"<br/>";
            }
            
    if($dice3 == 5){
                echo "Save?[3]";
                echo"<br/>";
            }

	// If $dice4 is a 1 or 5 then display echo message
	if($dice4 == 1) {
        echo "Save?[4]";
        echo"<br/>";
        }
        
        if($dice4 == 5){
            echo "Save?[4]";
            echo"<br/>";
        }
        // If $dice5 is "save"
    
        if($dice5 == 1) {
            echo "Save?[5]";
            echo"<br/>";
            }
            
        if($dice5 == 5){
                echo "Save?[5]";
                echo"<br/>";
            }
        // If $dice6 is "save"
        if($dice6 == 1) {
                echo "Save?[6]";
                echo"<br/>";
                }
                
        if($dice6 == 5){
                    echo "Save?[6]";
                    echo"<br/>";
                }
	/// If $dice is lower then 3 display echo message
	if($dice1 < 3) {
	echo "Don't give up try again!";
	}
	
	/// Script end


    

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 834
Joined: Mon Feb 22, 2016 5:52 pm

Tue Dec 11, 2018 5:35 pm

?

Code: Select all

if ($dice1 == $dice2){
  ...
}

chorn
php-forum Fan User
php-forum Fan User
Posts: 600
Joined: Fri Apr 01, 2016 2:18 am

Wed Dec 12, 2018 12:14 am

just have a look if array_unique changes your data.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 834
Joined: Mon Feb 22, 2016 5:52 pm

Wed Dec 12, 2018 8:38 am

The OP is not using arrays.

It looks like a homework type question, in which case the OP may not have got very far yet in what they have been taught?

QuackerNET
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Dec 11, 2018 3:10 pm

Wed Dec 12, 2018 2:15 pm

Code: Select all

<?php
  $dices = [];

  for ($i = 1; $i <= 6; $i++) {
    $dices[] = rand(1, 6);
  } 

  for ($i = 0; $i <= 5; $i++) {
    echo "Position {$i}: {$dices[$i]} \n";

    switch ($dices[$i]) {
      case 1:
      case 5:
        $pos = $i+1;
        echo "Save? [{$pos}] \n";
        break;
    }
  } 

  if ($dices[0] < 3) {
    echo "Don't give up, try again!";
  }
?>
I made it work with this simple solution, I was just over thinking it as I knew I was.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 834
Joined: Mon Feb 22, 2016 5:52 pm

Wed Dec 12, 2018 2:48 pm

That's quite a re-write!

What about
I want to be able to see if there are any matching sets.

QuackerNET
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Dec 11, 2018 3:10 pm

Sun Dec 23, 2018 1:30 pm

Currently, doing that now and re-working them in where there is more than one set back and worth, as shown.

111, 1111, 11111, 111111 --- or in 2's 3's 4's 5's 6's

Then we will go from there.

Post Reply