PHP 두 명이 노는 주사위 놀이 만들기
PHP

PHP 두 명이 노는 주사위 놀이 만들기

by nocagklhw 2019. 12. 31.


<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>주사위 놀이</title>
</head>
<body>
    <?php
    
    $dice = rand(1,6);
    echo '1 주사위: '.$dice.'<br/>';
    $dice2 = rand(1,6);
    echo '2 주사위: '.$dice2.'<br/>';
    $player1 = $dice + $dice2;
    echo 'player1: '.$player1.'<br/><br/>';
    
    $dice = rand(1,6);
    echo '1 주사위: '.$dice.'<br/>';
    $dice2 = rand(1,6);
    echo '2 주사위: '.$dice2.'<br/>';
    $player2 = $dice + $dice2;
    echo 'player2: '.$player2.'<br/><br/>';


    if ($player1 < $player2) {
        echo '심판: player2가 이겼어요!';
    } else if ($player1 == $player2) {
        echo '심판: 동점이에요 다시...';
    }
    else {
        echo '심판: player1이 이겼어요!';
    }
    ?>
</body>
</html>

댓글


TOP

TEL. 02.1234.5678 / 경기 성남시 분당구 판교역로