Skip to content

Commit

Permalink
feat: add the whole map + moving system
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPierne committed Oct 17, 2022
1 parent 251e02f commit d962da0
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 20 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
"homepage": "https://github.com/sherpa1/typescript-project-bootstrap#readme",
"dependencies": {
"@types/jest": "^29.1.1",
"keypress": "^0.2.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"typescript": "^4.8.4"
},
"devDependencies": {
"nodemon": "^2.0.20",
"jest": "^29.1.2"
"jest": "^29.1.2",
"nodemon": "^2.0.20"
}
}
}
13 changes: 4 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
class Game{
import World from './modules/world';

constructor(){};
const world = new World();

init(){

};
}
world.generate();

console.log(new Game().init());

export default Game;
console.log(world.render());
3 changes: 2 additions & 1 deletion src/modules/interfaces/irender.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
interface IRender{
export default interface IRender {
_world : string[][];
render(): string;
}
4 changes: 4 additions & 0 deletions src/modules/interfaces/irender.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default interface IRender {
_world : string[][];
render(): string;
}
91 changes: 86 additions & 5 deletions src/modules/world.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const IRender = require('./interfaces/irender');
import keypress from "keypress";
import IRender from './interfaces/irender';

let x = 13, y = 8;

console.clear();

class World implements IRender {

private _world : string[][];
_world : string[][];

constructor(){
this._world = Array(16).fill('').map(() => Array(32).fill('1'));
this._world = Array(16).fill('').map(() => Array(64).fill(' '));
this.controller();
}

getPos(x: number, y: number): string|undefined {
Expand All @@ -16,10 +22,85 @@ class World implements IRender {
this._world[x][y] = value;
}

controller(){
keypress(process.stdin);

process.stdin.on('keypress', (ch, key) => {
if (key && key.ctrl && key.name == 'c') {
process.stdin.pause();
}
if (key && key.name === 'left') {
this.setPos(x, y, ' ');
this.setPos(x, --y, 'M');
console.clear();
console.log(this.render());
}

if (key && key.name === 'right') {
this.setPos(x, y, ' ');
this.setPos(x, ++y, 'M');
console.clear();
console.log(this.render());
}

});

process.stdin.setRawMode(true);
process.stdin.resume();
}

generate(): void {
for(let x = 0; x < this._world.length; x++){
for(let y = 0; y < this._world[x].length; y++){
if (x > 13 && x < 17) {
this.setPos(x, y, '#');
}

if (x === 10 && y === 22) {
this.setPos(x, y, '?');
}

if (x === 10) {
if ([32, 33, 34, 35, 36, 37, 38].includes(y)) {
const character = (y % 2 === 0) ? '=' : '?';
this.setPos(x, y, character);
}
}

if (x === 6 && y === 35) {
this.setPos(x, y, '?');
}

if (x === 13 && y === 8) {
this.setPos(x, y, 'M');
}

if (x === 13 && y === 33) {
this.setPos(x, y, '@');
}
}
}
}

render(): string {
return this._world.join('\n');
return this._world.join('\n').replaceAll(',', '');
}

};

export default World;
export default World;

/*
______
/ \
/ \
/ \
/
*/
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"target": "es2022",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist"
},
"lib": ["es2015"]
"lib": ["es2022"]
}

0 comments on commit d962da0

Please sign in to comment.