-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
extends: '@qulture/eslint-config-base', | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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", | ||
} |
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: [], | ||
updateBoard(point, symbol) { | ||
board.matrix[point.y][point.x].setSymbol(symbol); | ||
}, | ||
print: () => { | ||
BoardPrinter(board.matrix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you created an abstraction in your game called |
||
}, | ||
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; |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm If you used "board |
||
const rowOfTiles = []; | ||
for (let j = 0; j < boardWidth; j += 1) { | ||
rowOfTiles.push(tileGenerator()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
matrixOfTiles.push(rowOfTiles); | ||
} | ||
return matrixOfTiles; | ||
} | ||
|
||
module.exports = boardConstruct; |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
function Game() {} |
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; |
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(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function Point(x, y) { | ||
return { | ||
x, | ||
y, | ||
}; | ||
} | ||
|
||
module.exports = Point; |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
master[m | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete this file! |
||
* [32mverTabuleiro[m |
There was a problem hiding this comment.
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!