JS Object-Oriented Programming-simple Super Mario games

Source: Internet
Author: User
<SCRIPT type = "text/JavaScript"> function Mario () {// Mario class this. X = 0; this. y = 0; var top, left; this. move = function (direct) {Switch (direct) {// 1-> 2-> 3-> 4-> case 1: var mymario = document. getelementbyid ('mymario '); Top = mymario. style. top; Top = parseint (top. substr (0, top. length-2); If (! (Check (top-20, left, direct) window. alert ("gold coins are not here"); elsemymario. style. top = (top-20) + "PX"; if (top-20> = 430) & (left> = 840) document. write ("good job"); break; Case 2: var mymario = document. getelementbyid ('mymario '); left = mymario. style. left; left = parseint (left. substr (0, left. length-2); If (! (Check (top, left-20, direct) window. alert ("gold coins are not here"); elsemymario. style. left = (left-20) + "PX"; if (top> = 430) & (left-20> = 840) document. write ("good job"); break; Case 3: var mymario = document. getelementbyid ('mymario '); left = mymario. style. left; left = parseint (left. substr (0, left. length-2); If (! (Check (top, left + 20, direct) window. alert ("gold coins are not here"); elsemymario. style. left = (left + 20) + "PX"; if (top> = 430) & (left + 20> = 840) document. getelementbyid ("win "). innerhtml = "good job"; break; Case 4: var mymario = document. getelementbyid ('mymario '); Top = mymario. style. top; Top = parseint (top. substr (0, top. length-2); If (! (Check (top + 20, left, direct) window. alert ("gold coins are not here"); elsemymario. style. top = (top + 20) + "PX"; if (top + 20> = 430) & (left> = 840) document. write ("good job"); break;} function check (top, left, direction) {// determines whether to touch the boundary. If yes, the system prompts "the gold coin is not here, please continue to work!" // Window. alert (Direction); // If (top> = 430) & (left> = 840) // window. alert ("good job"); // window. alert (top); // window. alert (left); If (Direction = 1 | direction = 4) {If (top <10 | top> 510) {return 0;} else return 1 ;} if (Direction = 2 | direction = 3) {If (left <0 | left> 940) {return 0;} else return 1 ;}}} vaR Mario = new Mario (); function mariomove (direct) {Switch (direct) {Case 1: Mario. move (direct); // up break; Case 2: Mario. move (direct); // to the left break; Case 3: Mario. move (direct); // break to the right; Case 4: Mario. move (direct); // downward break;} function CGO () {window. alert ("hello") ;}</SCRIPT>
<body><div class="gamebackground" >      <font id="win" class="winstyle"></font>  <table class="controlcenter"> <tr><td></td><td><input type="button" value="↑" onclick="marioMove(1)"/></td><td></td></tr> <tr><td><input type="button" value="←" onclick="marioMove(2)"/></td><td><input type="button" value="◆"/> </td><td><input type="button" value="→" onclick="marioMove(3)"/></td></tr> <tr><td></td><td><input type="button" value="↓" onclick="marioMove(4)"/></td><td></td></tr></table> </div>  </body>

/* CSS Document */.gamebackground{width:1000px;height:600px;background-color:pink;position:fixed;top:10px;left:130px;}.controlcenter {width:100px;height:100px;position:fixed;top:500px;left:140px;}.winstyle {font-size:150px;color:#006633;font-style:italic;font-weight:700;position:fixed;top:400x;left:250px;}

Games:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.