Setup
Now that we know the more about the concepts, let's scaffold out the basics of our project
Let's Build!
Okay, I'm building this in Node.js with Typescript. I hope to get to building it in a few different frameworks and languages, but this is the starter, as it's a very flexible language and framework that still has constraints built in to keep things clean. If Typescript/Javascript aren't your thing, let me know the frameworks you want to see it in! Making Pokemon Games is how I learn these things!
In a terminal run the following commands:
mkdir pokemon-game
cd pokemon-game
# this creates a node.js project with all the defaults
yarn init -y
# add the necessary dependencies as "devDependencies"
yarn add -D typescript ts-node @types/node
# initialize our Typescript project
yarn tsc --init
# it's always a good idea to keep your source data in a single directory
mkdir src
# here's the entry point to our app
touch src/index.ts
# create a .gitignore file so our node_modules aren't picked up
echo 'node_modules' > .gitignore
# add git to our project
git init
# add everything (excluding the node_modules in our .gitignore)
git add .
# save the game!
git commit -m "initial commit"
At this point, you should have the following files:
.git/
src/
- index.ts
package.json
tsconfig.json
yarn.lock
If you want a section on Git, let me know and we can cover that! There are a ton of things to learn about it, but you can get 80% of the benefits knowing less than 5% of the aspects of Git. But I always use it as a safety net so I don't lose work, even if I never push it to a remote repository.
In our ./src/index.ts
, let's put the following line of code in there, just as a check to see that everything is alright:
console.log("Hello world!");
In our package.json
, let's add a scripts
section and a start
command, so that our file looks like this:
{
"name": "pokemon-game",
"version": "1.0.0",
"main": "index.ts", // let's change this from .js -> .ts
"author": "<your name and email>",
"license": "MIT",
"scripts": {
"start": "ts-node src/index.ts",
},
"devDependencies": {
"@types/node": "^18.0.6", // these just happen to be the versions I used
"ts-node": "^10.9.1", // you should be safe with any version, so don't
"typescript": "^4.7.4" // worry about matching mine exactly.
}
}
So if we run the following command:
yarn start
It should print the following:
Hello, world!
Last updated