Do.. Okt. 23rd, 2025

I know that JavaScript can be used for game developments, interactive websites and for much more. Today I will recap of what I’ve learned about game development so far.

In order to set up a game, I would need to download VS Studio Code and Node.js, both tools to write and run a code. Once downloaded, I would need to click on Terminal-New Terminal, inside of VS Studio Code, which allows me to initialize Node.js by typing  npm init -y into the Terminal on the lower panel. 

Afterwards, I would need to create and safe a JavaScript file. In order to display this file in the Terminal, I would need to navigate to the right directory. I named my file huntersGame.js, and it is located in the folder GameforP2020, which is located under User.   

If I want to display the JavaScript code in my Terminal, I will have to enter node HuntersGame.js and this will run the code written in my file HuntersGame.js. 

Steps: 

  • Download VS Studio Code 
  • Initialize node.js by entering npm init-y 
  • Navigate to the right directory by entering cd C:\Users\rahel\GameforP2020( if I am in a different folder within the rahel folder, I would need to leave this folder first, by entering cd C:\Users\rahel and then I could proceed by entering cd GameforP2020
  • Run the code by entering node HuntergsGame.js 
  • Read the output 

Moving on with displaying a title and message for a player to read, I would need to use console.log(). 

I chose “Welcome to Hunters Game!” as a title, which can be displayed in the Terminal below the panel. I would need to enter into my HuntersGame.js file, console.log(“Welcome to Hunter’s Game!”); To see the output , I would need to enter in my Terminal node HuntersGame.js. 

Furthermore, I could also display a welcoming message such as, “Prepare yourself for an adventurous journey!” Again, console.log(“Prepare yourself for an adventurous journey!”);  

Interacting with a player by asking questions and receiving answers

If I want to receive information from the player, I would need a special code that allows me to ask questions and to be able to receive answers. Readline-sync is the right tool for this! 

Inside my Terminal and the GameforP2020 folder, I will have to install the readline-sync package by entering npm install readline-sync. 

At the top of my JavaScript file, I have to enter const readline = require(„readline-sync“); 

Let’s say, I would like to ask for a player’s name and welcome a player. I would need to use readline.question().  

I would write const name= readline.question( “What is your name?”); 

This will ask the player inside the Terminal for his name, and the player will be able to answer. I can follow up this answer with a welcome message by writing   

consol.log(“ Welcome “ + playerName + “Your health is on ” + playerHealth + “and you are good to start!”); 

This would be the variables I need to declare in the file, before entering the welcome message. 

Let playerName=”Rahel”; 

let playerHealth= 100; 

Let playerSilver=20; 

Let currentLocation=”city”; 

Von admin

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert