游戏网站开发学习笔记(二)

时间:2021-01-27 03:29:15

这两天进度有些慢,一直在忙着看闲书了。赶紧赶上,闲话少说,言归正传。

学习js,我个人认为,重要的是与用户的交互性要强,否则感觉就和单纯的html页面没区别了。针对用户与机器交互内容的不同,页面做出相应的、不同的反应,增强灵活性,考虑到各种情况,就能作出不同的反应。

最近,做了一个填字游戏,就是根据用户输入的条件,生成一个简单的小故事。

游戏网站开发学习笔记(二)

游戏网站开发学习笔记(二)

上代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gregs' Gambits|Greg's Tales</title>
<link rel="stylesheet" href="../carla/carla.css" />
<script type="text/javascript">
function startGame(){
var gender="boy";
var city=" ";
var monster=" ";
var food=" ";
var drink=" ";
numYears=prompt("Enter a number greater than 0:");
gender=prompt("Is the story about a boy or a girl?");
letter=gender.charAt(0);
gender=(letter=="b"||letter=="B")?"boy":"girl";
pronoun=(gender=="boy")?"he":"she";
name=prompt("Enter the hero's name:");
city=prompt("Enter a name of the city:");
monster=prompt("Enter a type of a monster:");
food=prompt("Enter a food of you like:");
drink=prompt("Enter a drink of you like:");
document.getElementById("content").innerHTML=("Once up a time,about"+numYears+"years ago,therre was a"+gender+" named "+name+"." +name+"lived in a small carbin in the woods just outside"+city+" limits.</p> <p>"
+name+" enjoy walking in the woods every day until... One day "+pronoun+" come upon a "+monster+" sitting on a log eating a "+food+" .</p> <p>The"
+monster+" jumped up,spilling his "+drink+" ."+name+" ran home as fast as"
+pronoun+" could but the "+monster+" followed and ...</p><h3>What happed? you decide!</h3><p>Ending 1:The "
+monster+" and "+name+" became the best friends.</p><p>Ending 2:The "+monster+" overpowered "+name+" and gobbled down all the "+food+" and "
+drink+" in "+name+" 's refrigerator.</p> <p>Ending 3:"+name+" screaming mean things at the "+monster+" ,casuing the "
+monster+" to turn and run back to the woods,never to be seen again.</p>");
}
</script>
</head>
<body>
<div id="container">
<img src="../images/superhero.jpg" class="floatleft" />
<h1><em>Greg's tales</em></h1>
<h3>
For this game, you will create a story by entering words as prompted.
The story will change each time you run this game,as you enter different words.
</h3>
<div id="nav">
  <p><a href="index.html">Home</a>
  <a href="greg.html">About Greg</a>
  <a href="greg-table.html">Play a Game</a>
  <a href="sign.html">Sign In</a>
  <a href="contact.html">Contact Us</a>
  <a href="aboutme.html">Tell me about you</a>
  </p>
</div>
<div id="content">
<p>&nbsp;</p>
<input type="button"value="click to begin"onclick="startGame()" /></div>
<div id="footer">Copyright &copy; 2018 Greg's Gambits<br />
<a href="mailto:yourfirstname@yourlastname.com">登陆邮箱</a></div>
</div>
</body>

</html>


好了,今天分享到这儿,希望各位大神能够多多指教,欢迎留言。

再续。。。