From Computer Science Wiki
|
|
Line 7: |
Line 7: |
| # Today in class we will apply our understanding of php and arrays as we work on a RPG character creation system | | # Today in class we will apply our understanding of php and arrays as we work on a RPG character creation system |
| # we will revisit conditionals | | # we will revisit conditionals |
| | |
| | The HTML form: |
|
| |
|
| <syntaxhighlight lang="html"> | | <syntaxhighlight lang="html"> |
Line 42: |
Line 44: |
| </html> | | </html> |
|
| |
|
| | |
| | </syntaxhighlight> |
| | |
| | |
| | <syntaxhighlight lang="php"> |
| | <?php |
| | |
| | $pay_to_win = $_POST['paytowin']; |
| | $race = $_POST['race']; |
| | $gender = $_POST['gender']; |
| | |
| | echo "debug: you are passing pay to win = $pay_to_win, race = $race |
| | and gender = $gender"; |
| | |
| | if ($pay_to_win == "yes") |
| | |
| | { |
| | |
| | $strength = mt_rand(50,100); |
| | $intelligence = mt_rand(0,50); |
| | $agility = mt_rand(50,100); |
| | |
| | } |
| | |
| | else |
| | |
| | { |
| | |
| | $strength = mt_rand(0,100); |
| | $intelligence = mt_rand(0,100); |
| | $agility =mt_rand(0,100); |
| | |
| | } |
| | |
| | |
| | echo "<p>Strength: $strength </p>"; |
| | echo "<p>Intelligence: $intelligence </p>"; |
| | echo "<p>Agility: $agility </p>"; |
| | |
| | ?> |
|
| |
|
| </syntaxhighlight> | | </syntaxhighlight> |
Revision as of 10:39, 18 October 2016
What are we going to learn today?[edit]
- Today in class we will apply our understanding of php and arrays as we work on a RPG character creation system
- we will revisit conditionals
The HTML form:
<!doctype html>
<html>
<!-- welcome to our simple chargen system -->
<form action="char_gen.php" method="post">
<p><label>Pay to win:
<input type="radio" name="paytowin" value="yes">Yes
<input type="radio" name="paytowin" value="no">No
</label></p>
<p>Race:
<br />
<br />
<input type="radio" name="race" value="elf">Elf<br />
<input type="radio" name="race" value="dwarf">Dwarf<br />
<input type="radio" name="race" value="human">Human<br />
<input type="radio" name="race" value="khajit">Khajiit<br />
<input type="radio" name="race" value="gnome">Gnome<br />
<input type="radio" name="race" value="centaur">Centaur<br />
</p>
<p>Gender:
<br />
<br />
<input type="radio" name="gender" value="male">Male<br />
<input type="radio" name="gender" value="female">Female<br />
<input type="radio" name="gender" value="other">Other<br />
</p>
<p><input type="submit" value="Onto step 2!" /></p>
</form>
</html>
<?php
$pay_to_win = $_POST['paytowin'];
$race = $_POST['race'];
$gender = $_POST['gender'];
echo "debug: you are passing pay to win = $pay_to_win, race = $race
and gender = $gender";
if ($pay_to_win == "yes")
{
$strength = mt_rand(50,100);
$intelligence = mt_rand(0,50);
$agility = mt_rand(50,100);
}
else
{
$strength = mt_rand(0,100);
$intelligence = mt_rand(0,100);
$agility =mt_rand(0,100);
}
echo "<p>Strength: $strength </p>";
echo "<p>Intelligence: $intelligence </p>";
echo "<p>Agility: $agility </p>";
?>
|
Homework[edit]
- Please review our page about collections and arrays
|
How am I being assessed today?[edit]
- You will be formatively assessed in class today
|
Standards we are covering today[edit]
|
As a computer scientist, you have:[edit]
- Confidence in dealing with complexity
- Persistence in working with difficult problems
- Tolerance for ambiguity
- The ability to deal with open-ended problems
- The ability to communicate and work with others to achieve a common goal or solution
|
Credits[edit]
|