Introduction: cloud development platform will “life to open simulator” fork to the cloud development of the warehouse, users only need to fork directly to their own warehouse can be in the cloud development platform for rapid magic change and one key deployment, binding their domain name can let friends together to feel your magic change creative oh.

Life can’t come again, the game can start again!

The Life Relaunch simulator has become wildly popular for no apparent reason. It’s a text-only MUD. Players can start by selecting 3 out of 10 unique talents and assigning points to their 4 attributes (appearance level, intelligence, constitution, family) to restart your life. You have no idea what you’re going to experience. You’re going to die at the age of 2 without enough food, go home at 5 PM, go to jail without enough food, get a girlfriend, get a boyfriend, etc. There are a lot of amazing hidden endings!

The entire game is point-by-point, from birth to death like a powerpoint presentation, with no art, no sound, not even ads. But its magic random text entries mix with ordinary light daily, occasionally there will be strange expansion, let me want to explore the boundaries of life, repeatedly reopen, repeatedly screen talent, configuration attributes, always want to experience a different life, accidentally hundreds of cycles. Once playing addiction, reopen nearly 300 times of life, but also escaped the ordinary fate, or did not experience the open hanging of life. That to ah, to magic change ah, immortal version, immortal version, sound version, you can have.

Cloud development platform will fork the original project to the cloud development of the warehouse, users only need to fork directly to their own warehouse after the cloud development platform for rapid magic change and one-key deployment, binding their domain name will be able to let friends together to feel your magic change creative oh.

Life reopening simulator implementation logic analysis

There are no more than 10 JS files in the game’s repo. There is no complex library, just a simple front end with jQuery and CSS. The only complex part is the game logic processing.

First, game data, such as talents and events, is stored in the Data directory: it contains XLSX and JSON files related to game data, such as events for each age, conditions for each event, talents, and so on. The author also wrote a script file utils/ xlsxtransform.js to convert XLSX files into JSON for easy reading.

Looking at this table, we can see that there are several basic attributes of a character:

  • CHR(Charm): Level of appearance
  • INT (Intelligence) : Intelligence
  • STR (Strong) : physical fitness
  • MNY (Money) : the family circumstances
  • SPR (Spirit) : happy New Year
  • LIF (Life) : Life

The occurrence of the event may bring about changes in physical appearance, intelligence, physical fitness, and family circumstances.

  • The change in life is only “-1”. Including “you die” and “you go to heaven.” So xiuxian successful friends do not be too proud. If you think you are in the immortal class, maybe you are the ripe fruit picked by heaven?
  • The different fates of the rural line, the urban line, and the Chinese-American line have been created by saying “you can only be random when something happens” and “you can’t be random when something happens”. TLT (Talent) also has an effect on the occurrence of events, such as tall buildings between cities must be born in the city.
  • After an event occurs, it may go to different branches depending on the pre-event and character attributes. For example, “You were molested by a teacher” would lead to “you called the police and the teacher was arrested” in character INT>7, whereas “You are depressed but afraid to tell others.”

Second, the main code for the game is in the SRC directory:

You can start with SRC /index.js. This file does two things:

  1. Read the JSON game data under the data mentioned above and bind it as a global variable; Bind a global banner Handler.

  2. Initialize the app.

    import App from ‘.. /src/app.js’;

    window.json = async fileName => await (await fetch(.. /data/${fileName}.json)).json();

    // Pssst, I’ve created a github package – github.com/brookesb91/… window.hideBanners = (e) => { document .querySelectorAll(“.banner.visible”) .forEach((b) => b.classList.remove(“visible”)); };

    const app = new App(); app.initial();

Then you can read the SRC /app.js code, which is the main front end of jQuery, responsible for generating views and binding functions, and basically most of the front end logic is here. For example, the following code:

Const indexPage = $(' <div id="main"> <div id=" CNT "class="head"> </div> <button id="rank"> </button> <button <div style="font-size:1.5rem; font-weight:normal;" </div> <button id="restart" class="mainbtn"><span class="iconfont">&#xe6a7; </button> </div> '); indexPage .find('#restart') .click(()=>this.switch('talent'));Copy the code

This code is to first write an HTML component indexPage, then find a button with the id restart and bind a function to it ()=>this.switch(‘talent’). This. Switch should be used to switch between screens. The logic here is “click the restart button and go to the talent selection screen”.

Then the three remaining SRC files are related to the game logic:

Event.js is responsible for random event-related logic,

Property.js is responsible for the character attribute logic,

Talent.js is responsible for talent-related logic,

Life.js is the logic of life advancement.

Underneath SRC /function are several helper functions, including parsing of the event condition, and life summaries.

Magic modified life reopening simulator one – key hosting

1. Environment preparation

  • Landing cloud development platform. Open the website workbench.aliyun.com/, use ali Cloud account login,…

  • Create the repository of code required for the project. Visit github.com/AliyunWorkb… Init generates the same default template content.

2. Create a life simulator app

  • Create front-end applications. Open the quick start workbench.aliyun.com/page/quicks…

  • Cloud resource access authorization. If you have not used the cloud development platform before, the option of cloud resource authorization management will appear. Click “Agree to Authorize” and then the authorization will be successful. Click “Next”.

  • Bind the Github account. After authorization is completed, select the source repository as Github, click unbind as prompted, bind Github account, log in and click Authorize Aliyunworkben to allow cloud development platform to build and publish your Github code as accessible website.

  • Select fork good code repository. Select the repository, trunk branch from step 1, and click Next. The trunk branch generally refers to a branch of code such as master or main.

  • Enter basic information to complete the creation. Fill in the basic information and click finish. The application details and deployment page is displayed.

3. Configure and online applications in the daily environment

  • Obtain the AK/SK of ali Cloud account. Click ram.console.aliyun.com/manage/ak, create the Accesskey, success will be generated after AccesskeyID (AK) and the Accesskey Secret (SK)

  • Deployment configuration. After the application is created, the page for application details is displayed. Click deployment configuration in the line of daily environment. The configuration description is displayed in the window that is displayed.

  • Configuration dead simple. Go to Github and click New Reposority Secret to reposority Secret (AK, SK). Create two secret servers using the AccessKey ID and AccessKey secret values. After the creation, you can see that there are two secret: AK and SK.

  • One-click deployment. After the configuration is complete, click Deploy in daily environment to deploy the system

4. Access the vm after the deployment is successful

  • After the deployment is successful, click Deploy Configuration again, and click Test Domain name in the window that is displayed to access your application. Temporary domain name valid for 30 minutes, please pay attention to test the expiration time of the domain name, after the expiration of the refresh can continue to use, link support to share to friends visit. If the magic change has been modified, and want to go online for a long time, for everyone to play, you can follow the following steps to bind to their own personal domain name.

  • Bind a personal domain name. To add your own custom domain name, click “Deploy configuration”, “Custom Domain Name”, add your own domain name, and click “Deploy” again. Then, add your domain name CNAME to the specified OSS domain name as prompted, and you can use your own domain name to continuously access the application.

  • Use CDN to accelerate domain name access and save traffic charges (optional). If the website has heavy traffic, you can click How to Configure CDN Acceleration in Deployment Configuration to bind your domain name to CDN acceleration to speed up website access and save traffic costs.
  • Visit the online deployment website. Once the CNAME is in effect, we can access the application deployed to the online environment by entering the newly bound domain name into the browser. Now, how to deploy an application to the online environment, how to bind your domain name to access an online application is complete, quickly deploy your application to the online environment, use your domain name to play;)

Play life, live in the moment

Address: online demo-liferestart.workbenchapi.com/

If you look at it like a game, you’re trying to get as many branching endings as possible;

If you think of it as life, to keep reopening is to try to experience as different a life as possible.

After watching the recently released “Runaway Player”, I suddenly felt that:

That in the game repeated cycle of life NPC, is not tired of monotonous boring life, eager to experience a different life?

But on second thought, in fact, each of us, and it is not the NPC in the world of others?

So, don’t struggle, live the present, live yourself, that’s enough.

Of course, in your spare time, you can also reopen the life simulator to feel the imagination of life and games.

The original link

This article is the original content of Aliyun and shall not be reproduced without permission.