Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ver tabuleiro #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
extends: '@qulture/eslint-config-base',
};

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"javascript.format.enable": false,
"typescript.format.enable": false,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll": true
},

"typescript.tsdk": "node_modules/typescript/lib",
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
},
"homepage": "https://github.com/QultureRocks/FE-trail-template#readme",
"devDependencies": {
"@qulture/eslint-config-base": "^0.0.2"
"@qulture/eslint-config-base": "^0.0.4"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^3.1.0",
"eslint": "^7.1.0",
"eslint-config-airbnb": "^18.1.0"
}
}
29 changes: 29 additions & 0 deletions src/node/board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const BoardConstruct = require('./boardConstructor');
const BoardPrinter = require('./boardPrinter.js');
const Point = require('./point.js');

function Board(size) {
const board = {
size,
matrix: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could call here directly, there would be no problem at all!

const board = {
  size,
  matrix: BoardConstruct(newSize),
  ...
}

updateBoard(point, symbol) {
board.matrix[point.y][point.x].setSymbol(symbol);
},
print: () => {
BoardPrinter(board.matrix);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you created an abstraction in your game called Board, this BoardPrinter would make more sense to receive an actual board than the matrix, right?
When you create a function, pay attention to what you are making it depend of. It makes more sense to a BoardPrinter to depend on a Board than on a "matrix

},
resetBoard: newSize => {
board.matrix = BoardConstruct(newSize);
},
};

board.matrix = BoardConstruct(size);
return board;
}

const board = Board(3);
const a = Point(1, 2);
board.updateBoard(a, 'X');
board.print();

module.exports = Board;
18 changes: 18 additions & 0 deletions src/node/boardConstructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const tileGenerator = require('./tile.js');

function boardConstruct(newSize) {
const boardLength = newSize;
const boardWidth = newSize;
const matrixOfTiles = [];

for (let i = 0; i < boardLength; i += 1) {
Copy link
Contributor

@Sauloxd Sauloxd Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm If you used "boardWidth" for one axis, why not "boardHeight" for the other? It's an exaggeration but "boardLength" could actually mean the length of an array with boards! not its actual dimension

const rowOfTiles = [];
for (let j = 0; j < boardWidth; j += 1) {
rowOfTiles.push(tileGenerator());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always be consistent! If you name add "generator" to functions that create a new instance of something, you should add "generator" to all functions that do that. For example, why Board and not BoardGenerator? Why this function is not Capitalized? (TitleGenerator())?

}
matrixOfTiles.push(rowOfTiles);
}
return matrixOfTiles;
}

module.exports = boardConstruct;
15 changes: 15 additions & 0 deletions src/node/boardPrinter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function BoardPrinter(matrix) {
let boardString = ' _ _ _\n\n';

matrix.forEach(row => {
boardString += '| ';
row.forEach(tile => {
boardString += `${tile.symbol} | `;
});
boardString += '\n _ _ _\n\n';
});

console.log(boardString);
}

module.exports = BoardPrinter;
1 change: 1 addition & 0 deletions src/node/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function Game() {}
15 changes: 15 additions & 0 deletions src/node/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

const hello = (board) => {
console.log('Hello world!');
console.log(board);

};

let a = {
name: "ton",
hello: hello,
board: []
};


module.exports = a;
9 changes: 5 additions & 4 deletions src/node/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const hello = () => {
console.log('Hello world!');
};
const hello = require("./hello.js");

hello.hello(hello.board);



hello();
8 changes: 8 additions & 0 deletions src/node/point.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function Point(x, y) {
return {
x,
y,
};
}

module.exports = Point;
11 changes: 11 additions & 0 deletions src/node/tile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function TileGenerator() {
const tile = {
symbol: ' ',
setSymbol(newSymbol) {
tile.symbol = newSymbol;
},
};
return tile;
}

module.exports = TileGenerator;
2 changes: 2 additions & 0 deletions wd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete this file!

* verTabuleiro
Loading