我有一个问题 因为我现在想要如何在不等于null时隐藏行 因为玩家需要让物品到达那个位置 所以任何帮助都是值得欣赏的
的index.php
<?php
session_start();
require_once ('inc/loadsmarty.php');
require_once ('inc/Location.class.php');
require_once ('inc/DBconnection.php');
require_once ('inc/Choice.class.php');
require_once ('inc/Inventory.class.php');
$location_id = (isset($_GET['location_id']) ? $_GET['location_id'] : 1); // kijk welke locatie wordt gevraagd
$errors = []; // hou fouten bij in deze array
$loc = new Location(); // maak lege locatie aan
$did_load_work = $loc->LoadFromDb($mysqli, $location_id); // laad locatie en choices vanuit de database
if ($did_load_work == false) { // als het laden fout ging, voeg dan een error toe aan de array $errors
array_push($errors, "This location does not exist in the database");
}
if($location_id == 22 ) {
$_SESSION['Paddle'] = true;
}
if ($location_id == 23) {
$_SESSION['Basebalbat'] = true;
}
if ($location_id == 24) {
$_SESSION['Axe'] = true;
}
if ($location_id == 26) {
$_SESSION['Hammer'] = true;
}
// Make Session End 2 when you reached location 27
if($location_id == 27) {
$_SESSION['End2'] = true;
}
/*
if (isset($loc)) {
if (is_null($loc->Choices)) {
// Load choice->to_id 25
echo "Hello Friend";
}
var_dump($loc);
}
*/
$smarty->assign('pagetitle', 'Games to play');
$smarty->assign('errors', $errors); // geef lege of gevulde array $errors mee
$smarty->assign('location', $loc); // geef locatie (en daarin de choices) mee
$smarty->assign('location', $loc); // geef locatie (en daarin de choices) mee
$smarty->display("tpl/index.html.tpl");
if (isset($_SESSION['Paddle']) || isset($_SESSION['End2']) || isset($_SESSION['Hammer']) || isset($_SESSION['Axe']) || isset($_SESSION['Basebalbat'])) {
echo "<div id=\"msg\"> You have picked up the item";
$converted = settype($location_id, 'integer');
$converted = settype($loc->id, 'integer');
echo "<br />";
switch ($location_id) {
case $location_id == 22:
echo "You picked up the paddle";
echo "<br />";
break;
case $location_id == 23;
echo "You picked up the Basebalbat";
echo "<br />";
break;
case $location_id == 24;
echo "You picked up the Axe";
echo "<br />";
break;
case $location_id == 26;
echo "You picked up a hammer";
echo "<br />";
break;
default:
echo "no items has been picked up";
echo "<br />";
}
}
在index.tpl
<html>
<head>
<title> {$pagetitle} </title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div class="plaatje">
{if isset($errors) }
<p style="border: 1px solid red;">
<ul>
{foreach $errors as $error}
<li>{$error}</li>
{/foreach}
</ul>
{/if}
{if isset($location) }
<h1>{$location->Title }</h1>
<p>{$location->Story }</p>
{$location->Foto_url }
{/if}
<ul>
{foreach $location->Choices as $choice}
<!-- change the string output to a int value -->
{$choice->to_id|intval}
<!-- looks of Choice->to_id is equal to 22 or 23 or 24 or 25 then change them -->
<!-- First looks of $_SESSION['Pickup'] Exist -->
{if isset($smarty.session.Paddle)}
{if $choice->to_id == 22}
<p class="hide"> Nothing Here Friend</p>
{else}
<li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
{/if}
{elseif isset($smarty.session.End2)}
{if $choice->to_id == 25}
<p class="hide"> Nothing Here Friend</p>
{/if}
{elseif isset($smarty.session.Basebalbat)}
{if $choice->to_id == 23}
<p class="hide"> Nothing Here friend</p>
{else}
<li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
{/if}
{elseif isset($smarty.session.Axe)}
{if $choice->to_id == 24}
<p class="hide"> Nothing Here friend</p>
{else}
<li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
{/if}
{elseif isset($smarty.session.Hammer)}
{if $choice->to_id == 26}
<p class="hide"> Nothing Here friend</p>
{else}
<li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
{/if}
{else}
<li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li>
{/if}
{if $location->id == 25}
{session_unset()}
{session_destroy()}
{/if}
{if $choice->need_item_id != ""}
<p> Hello </p>
{/if}
<!-- <li><a href="index.php?location_id={$choice->to_id}">{$choice->title}</a></li> -->
{/foreach}
</ul>
<ul>
{foreach $location->Inventory as $hello}
<li> {$hello->player_id} {$hello->item_id} {$hello->space}</li>
{/foreach}
</ul>
</div>
</body>
</html>
玩家按位置查找某些位置是需要的商品ID 作为问题,当玩家将物品放在他的库存中时,我该怎么隐藏呢?
这是游戏的课程
Location.class.php
<?php
require_once ("DBconnection.php");
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
class Location
{
public $id;
public $Title;
public $Foto_url;
public $Story;
public $Choices = [];
public $Inventory = [];
function LoadFromDb($mysqli, $id)
{
$sql = "SELECT * FROM locations WHERE id=" . $id . ";";
$results = $mysqli->query($sql);
if ($results->num_rows >= 1) {
$record = $results->fetch_assoc();
$this->id = $record['id'];
$this->Title = $record['Title'];
$this->Foto_url = ('<img src="' . $record['Foto_url'] . '">');
$this->Story = $record['Story'];
}
// load choices
$sql = "SELECT * FROM choices WHERE from_id=" . $id . ";";
$results2 = $mysqli->query($sql);
while ($record = $results2->fetch_assoc()) {
$choice = new Choice();
$choice->id = $record['id'];
$choice->from_id = $record['from_id'];
$choice->to_id = $record['to_id'];
$choice->title = $record['title'];
$choice->need_item_id = $record ['need_item_id'];
array_push($this->Choices, $choice);
}
// Load inventory
$sql = "SELECT * FROM inventory";
$results3 = $mysqli->query($sql);
while ($row = $results3->fetch_assoc()) {
$item = new Inventory();
$item->id = $row['id'];
$item->player_id = $row['player_id'];
$item->item_id = $row['item_id'];
$item->space = $row['space'];
array_push($this->Inventory, $item);
}
return true;
}
}
答案 0 :(得分:0)
我关闭了这个,我已经找到了自己的灵魂所以非常赞赏所有的支持
{if $choice->need_item_id}
{foreach $location->Inventory as $itm}
{if $itm->item_id == $choice->need_item_id}
<p class="hide"> YOU HAVE IT </p>
{else}
<p class="item"> Go search the item {$choice->need_item_id}</p>
{/if}
{/foreach}
<!-- So yes then show the choice -->
{/if}