


Use javascript to make a small game platform (2) Game selector_javascript skills
Today I will preview tonight’s results, as follows (if you are frustrated, don’t throw bricks):
Today I mainly designed a selector, which is to display the game list when entering the game, and then use it to select the game An idiot's function.
The selector is based on yesterday's game class. I made some modifications to yesterday's code:
//5. Game category: name, logical method, keyboard method, start method, start level method, end method
var Game = function(name, logicalFn , keyFn, startFn, loadFn, endFn) {
//Game name
this._name = name || "Unnamed";
//5.a.1: Logic control
this. _LControl = logicalFn || function(date) {
//Simple game logic control
if (this._FrameMain) {
var innHTML = "Game time:" date.getSeconds() "Seconds" date. getMilliseconds();
innHTML = "
The current game is not writing, you can press Esc to exit the game;";
this._FrameMain.innerHTML = innHTML;
}
} ;
//5.a.2: Keyboard control
this._KControl = keyFn || function(event) {
//Simple keyboard logic
alert("You tapped" event. keyCode "key");
};
//5.b.1:Title area
this._FrameTitle = null;
//5.b.2:Game area
this ._FrameMain = null;
//5.b.3: Status display area
this._FrameState = null;
//5.b.4: Control area
this._FrameControl = null;
//5.c.1: Opening animation
this._AnmLoad = new Animation("Enter the game",null);
//5.c.2: Pass animation
this._AnmNext = new Animation("Loading",null);
//5.c.3: End animation
this._AnmEnd = new Animation("End",null);
//5.d .1: Start: Call the start animation, start processing method, load the game
this._Start = function() {
this._AnmLoad = this._AnmLoad || new Animation(null);
var temp = this; //Get the current object
this._AnmLoad._palyEnd = this._AnmLoad._palyEnd || function() {
startFn && startFn();
temp._Load();
};
this._AnmLoad._play();
};
//5.d.2: End
this._End = endFn || function() {
alert("Game is over ");
};
//5.d.3: Loading: every time you start the game (level starts)
this._Load = function() {
this._AnmNext = this. _AnmNext || new Animation(null);
var temp = this; //Get the current object
this._AnmNext._palyEnd = this._AnmNext._palyEnd || function() {
if (!loadFn) {
temp._FrameTitle = _HtmlControl._newPanel(0, 0, 400, 30);
temp._FrameTitle.innerHTML = temp._name || "Unnamed game";
temp._FrameMain = _HtmlControl. _newPanel(0, 30, 350, 370);
temp._FrameState = _HtmlControl._newPanel(350, 30, 50, 180);
temp._FrameControl = _HtmlControl._newPanel(350, 210, 50, 190) ;
_HtmlControl._ClearArea();
_HtmlControl._AddControl(temp._FrameTitle);
_HtmlControl._AddControl(temp._FrameMain);
_HtmlControl._AddControl(temp._FrameState); ._AddControl(temp._FrameControl);
} else {
loadFn();
}
}
this._AnmNext && this._AnmNext._play();
}
//5.e Map
this._Map = [];
mapIndex = -1;
};
//Create a game
var game1 = new Game("Snake", null, null);
var game2 = new Game("Tetris", null, null);
var game3 = new Game("Pushbox", null, null);
var game4 = new Game("Racing", null, null);
var game5 = new Game("Tank Battle", null, null);
//------------------------------------------------ ------------
//6. Game list
var _GameList = [game1, game2, game3, game4, game5];
//------ -----------------------------------------------
/ /7. Game selector
var _GameChoose = new Game("selector", null, null);
{
_GameChoose._Map = _GameList;
_GameChoose._Load = function() {
this._FrameTitle = _HtmlControl._newPanel(0, 0, 400, 30);
this._FrameTitle.innerHTML = "Please select a game";
this._FrameMain = _HtmlControl._newPanel(0, 30, 240 , 370);
this._FrameState = _HtmlControl._newPanel(240, 30, 160, 180);
this._FrameState.innerHTML = "You can
use the up and down keys
this._FrameControl = _HtmlControl._newPanel(240, 210, 160, 190);
this._FrameControl.innerHTML = "Press Enter
to enter the game";
this._tempButtons = [];
this._tempButtonsIndex = 0;
//this._FrameMain.style.scrollbar//
if (this._Map.length > 0) {
for (var i = 0; i var button = _HtmlControl._newButton(this._Map[i]._name, 200, 30);
this._FrameMain.appendChild (button);
this._tempButtons.push(button);
}
this._tempButtons[0].select();
}
_HtmlControl._AddControl(this._FrameTitle);
_HtmlControl._AddControl(this._FrameMain);
_HtmlControl._AddControl(this._FrameState);
_HtmlControl._AddControl(this._FrameControl);
};
_GameChoose._LControl = function( date) {
if (mapIndex != -1) {
this._Map && this._Map[mapIndex]._LControl(date);
}
};
_GameChoose._KControl = function(event) {
if (mapIndex == -1) {
switch (event.keyCode) {
case _KeyParameters.KeyUp:
{
//alert("upper t" );
if (this._tempButtonsIndex > 0) {
this._tempButtonsIndex--;
for (var i = 0; i this ._tempButtons[i].unselect();
}
this._tempButtons[this._tempButtonsIndex].select();
}
}
break;
case _KeyParameters.KeyDown :
{
//alert("下");
if (this._tempButtonsIndex this._tempButtonsIndex;
for (var i = 0; i this._tempButtons[i].unselect();
}
this._tempButtons[this._tempButtonsIndex].select();
}
}
break;
case _KeyParameters.KeyEnter:
{
mapIndex = this._tempButtonsIndex;
this._Map && this._Map[mapIndex]._Start() ;
}
break;
default:
{
} break;
}
} else {
if (event.keyCode == _KeyParameters.KeyESC) {
mapIndex = -1;
this._Start();
return;
}
this._Map && this._Map[mapIndex]._KControl(event);
}
}
}
Just write the content like this. Due to time constraints, Snake still hasn’t done it. Yesterday, the last slogan was said by someone from the company, saying that I have assigned tasks to the company. Throw it away.
Today I want to change a slogan to facilitate the completion of the first game: authority during the day, greedy snake at night, I want to be greedy to the extreme, hehe...
[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh it to execute
The writing is obviously very frustrating. But in order to improve my abilities in various aspects, I still posted it. Your criticism is welcome.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools