-5
所以,我正在用php創建一個Rock,Paper,Scissor遊戲。我正在創建兩個網頁。第一個網頁將包含三個單選按鈕,分別是岩石,紙張,剪刀和一個提交按鈕。第一頁將把信息發送到第二頁。第二頁是電腦。電腦將隨機選擇岩石,紙張,剪刀。php遊戲Rock,paper,scissors
這就是我現在所擁有的。它只是沒有以正確的方式發送信息。
First page:
<?php
session_start(); //session start
if(!isset($_SESSION['username'])) //if session not found redirect to homepage
{
header('location:login.php');
}
else{
echo '<form action="game.php" method="post" />
<input type="radio" name="user_choice" value="Rock" title="Rock" />Rock <br /><br />
<input type="radio" name="user_choice" value="Paper" title="Paper" />Paper <br /><br />
<input type="radio" name="user_choice" value="Scissors" title="Scissors" />Scissors <br /><br />
<input type="submit" name="form_submit" value="submit"/>
</form> ';
}
?>
Second Page:
<?php
session_start(); //session start
//if session not found redirect to homepage
if(!isset($_SESSION['username'])) {
header('location:login.php');
} elseif {
if($_POST['user_choice']) {
$user_choice = $_POST['user_choice'];
$Choosefrom= array('Rock', 'Paper', 'Scissors');
$Choice= rand(0,2);
$Computer=$Choosefrom[$Choice];
if($user_choice == $Computer) {
echo 'Player: '.$user_choice.' CPU: '.$Computer.'. Result: Win';
} else {
echo 'Player: '.$user_choice.' CPU: '.$Computer.'. Result: Lose';
}
}
}
?>
我認爲同樣的問題http://stackoverflow.com/questions/ 40602274/rock-paper-scissors-game-php –
它不一樣。請仔細閱讀 – AAV
2問題有什麼不同? –