第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何制作可以從數(shù)組中為劊子手游戲選擇單詞的按鈕

如何制作可以從數(shù)組中為劊子手游戲選擇單詞的按鈕

PHP
有只小跳蛙 2022-10-14 16:09:40
我正在嘗試為學(xué)校項(xiàng)目創(chuàng)建一個(gè)劊子手游戲,但我被卡住了。所以我有一個(gè)單詞數(shù)組,我希望玩家選擇其中一個(gè)單詞,以便另一個(gè)可以嘗試猜測(cè)字母/單詞。像這樣的東西:示例這是單詞數(shù)組:public $words = [      'apple',      'tree',      'car',      'school',      'table',      'laptop',      'house',      'summer', ];我不知道這是否有幫助,但這是我的其余代碼:<?php class game {     public $letters = [];     public $chosenword;     public $words = [          'apple',          'tree',          'car',          'school',          'table',          'laptop',          'house',          'summer',        ];    function randomWord() {        $this->chosenword = $this->words[rand ( 0 , count($this->words) -1)];        return $this->chosenword;    }    function addLetter($letter){        array_push($this->letters, $letter);    }    function ShowWord(){        $pattern = '/[^' . implode('', $this->letters) . ']/';        return preg_replace($pattern, '-', $this->chosenword);    }    function isWord($woord, $randomRandom){        if ($woord == $randomRandom) {            return "Found";        }        return "Not Found";    } }$game = new game ();$randomRandom = $game ->randomWord();echo $randomRandom;$game->addLetter('a');echo "<br>";echo $game->ShowWord();echo "<br>";echo $game->isWord('apple', $randomRandom);?>我想在不同的 PHP 文件中制作按鈕,但真的想不出我應(yīng)該從哪里開始。有沒有人給我提示或可以告訴我如何繼續(xù)?
查看完整描述

1 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

一種方法是使用表單并將您的表單發(fā)布chosenword到服務(wù)器。在此示例中,首先顯示表單。提交后,游戲?qū)?dòng):


// your game class

class game {


     public $letters = [];

     public $chosenword;

     public $words = [

          'apple',

          'tree',

          'car',

          'school',

          'table',

          'laptop',

          'house',

          'summer',

        ];


    function randomWord() {


        $this->chosenword = $this->words[rand ( 0 , count($this->words) -1)];

        return $this->chosenword;

    }


    function addLetter($letter){

        array_push($this->letters, $letter);

    }


    function ShowWord(){

        $pattern = '/[^' . implode('', $this->letters) . ']/';

        return preg_replace($pattern, '-', $this->chosenword);

    }


    function isWord($woord, $randomRandom){

        if ($woord == $randomRandom) {

            return "Found";

        }

        return "Not Found";

    }

}


// init a new game

$game = new game();


// if the form is not sent before, show the form

if( !isset( $_POST['chosenword'] ) )  { ?>


<form action="" method="post">

  <select name="chosenword">

    <?php foreach( $game->words as $word ) { ?>

      <option value="<?= $word; ?>"><?= $word; ?></option>

    <?php } ?>

  </select>

  <button type="submit">Submit</button>

</form>


<?php } else {

  // this will be executed if the form was sent before


  // set the chosenword from the post data

  $game->chosenword = $_POST['chosenword'];


  // do the rest of your code

  $randomRandom = $game->randomWord();

  echo $randomRandom;

  $game->addLetter('a');

  echo "<br>";

  echo $game->ShowWord();

  echo "<br>";

  echo $game->isWord('apple', $randomRandom);

}

?>


查看完整回答
反對(duì) 回復(fù) 2022-10-14
  • 1 回答
  • 0 關(guān)注
  • 118 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)