-
Notifications
You must be signed in to change notification settings - Fork 35
Projeto II - Mariana Seidel #35
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
base: main
Are you sure you want to change the base?
Changes from all 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /node_modules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| class Equipments { | ||
| equipments = []; | ||
|
|
||
| choseEquipments() { | ||
| this.equipments = []; | ||
| this.handEquipments = []; | ||
| } | ||
|
|
||
| addHandsEquipment(equipment) { | ||
| if (this.equipments.length < 2) { | ||
| this.handEquipments.push(equipment) | ||
| return `Você pegou ${equipment}!` | ||
| } else { | ||
| 'Suas mãos estão cheias!' | ||
| } | ||
| } | ||
|
|
||
| reduceEquipment(equipment) { | ||
| for (let i = this.totalInjuries; i < 3; i++) { | ||
| equipments = this.equipments.filter(item => item != equipment); | ||
| this.equipments = equipments; | ||
| } | ||
|
|
||
| if (this.equipments.length > 7) { | ||
| const diference = this.equipments.length - 7; | ||
| return `Você possui mais equipamentos do que sua capacidade de armanezamento! Descarte ${diference} itens.` | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class CombateItems extends Equipments { | ||
| combate = [ | ||
| 'bastão de baseball', | ||
| 'frigideira', | ||
| 'machado', | ||
| 'pistola' | ||
| ]; | ||
| } | ||
|
|
||
| class UtilitarianItems extends Equipments { | ||
| utilitarian = [ | ||
| 'garrafa de água', | ||
| 'comida', | ||
| 'kit de primeiros socorros' | ||
| ]; | ||
| } | ||
|
|
||
| module.exports = { Equipments } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| let { Survivor } = require('./Survivor') | ||
|
|
||
| class Level { | ||
| level; | ||
| experience; | ||
|
|
||
| constructor(survivor) { | ||
| this.level = survivor.level; | ||
| if (!survivor.level === 'Blue') { | ||
| survivor.level === this.level | ||
| } | ||
| this.experience = survivor.experience; | ||
| } | ||
|
|
||
| changeLevel() { | ||
| if (this.experience >= 42) { | ||
| this.level = 'Red' | ||
| return `Seu nível é: ${this.level}.` | ||
| } else if (this.experience >= 18 && this.experience < 42) { | ||
| this.level = 'Orange' | ||
| return `Seu nível é: ${this.level}.` | ||
| } else if (this.experience >= 6) { | ||
| this.level = 'Yellow' | ||
| return `Seu nível é: ${this.level}.` | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { Level } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| let { Level } = require('./Level'); | ||
| let { Survivor } = require('./Survivor'); | ||
|
|
||
| describe('verify level class', () => { | ||
|
|
||
| let level, survivor; | ||
|
|
||
| beforeEach(() => { | ||
| level = new Level(survivor); | ||
| survivor = new Survivor(); | ||
| }) | ||
|
|
||
| it('should check the experience when de surviver begings the match', () => { | ||
| expect(survivor.experience).toBe(0); | ||
| }); | ||
|
|
||
| it('should check the level when de surviver begings the match', () => { | ||
| expect(survivor.level).toBe('Blue'); | ||
| }); | ||
|
|
||
| it('should check the function changeLevel', () => { | ||
| survivor.experience = 19; | ||
| expect(level.changeLevel()).toBe('Seu nível é: Orange.'); | ||
| }); | ||
|
|
||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| let { Survivor } = require('./Survivor') | ||
|
|
||
| class Match { | ||
| survivors; | ||
| level; | ||
|
|
||
| constructor() { | ||
| this.survivors = Survivor.allSurvivors.length | ||
| if (this.survivors === 0) { | ||
| return `Fim do jogo!` | ||
| } | ||
|
|
||
| const filterLevel = Survivor.allSurvivors.filter((element) => { | ||
| if (element === 'Red') { | ||
| return element.level | ||
| } else if (element === 'Orange') { | ||
| return element.level | ||
| } else if (element.level === 'Yellow') { | ||
| return element.level | ||
| } else { | ||
| return element.level | ||
| } | ||
| }) | ||
|
|
||
| this.level = filterLevel; | ||
| } | ||
|
|
||
| addSurvivors(newPlayers) { | ||
| if (!(newPlayers instanceof Survivor)) { | ||
| return 'Insira um jogador válido.' | ||
| } | ||
| return Survivor.allSurvivors | ||
| } | ||
| } | ||
|
|
||
| module.exports = { Match } | ||
|
|
||
|
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. Adorei essa classe!! Seu código está super limpo e fácil de entender!! |
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const { Match } = require('./Match'); | ||
| const { Survivor } = require('./Survivor'); | ||
|
|
||
| describe('verify match class', () => { | ||
|
|
||
| let match1; | ||
|
|
||
| beforeEach(() => { | ||
| match1 = new Match(); | ||
| }) | ||
|
|
||
| it('should check a match when there is not survivers', () => { | ||
| expect(match1).toBe('Fim do jogo!'); | ||
| }); | ||
|
|
||
| it('should check add players when the parameter is not a survivor object', () => { | ||
| const player1 = 'player1'; | ||
| expect(match1.addSurvivors(player1)).toBe('Insira um jogador válido.'); | ||
| }); | ||
|
|
||
| it('should check add players', () => { | ||
| const player1 = new Survivor('player1'); | ||
| match1.addSurvivors(player1); | ||
| expect(match1.survivors).toBe(1); | ||
| }); | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| let { Level } = require('./Level') | ||
|
|
||
| class Skill { | ||
| skillTree; | ||
| potencialSkills = ['+1 Dano', | ||
| 'Tesouro escondido', | ||
| '+1 Ação de Movimento', | ||
| '+1 equipamento em mãos', | ||
| '+1 vida']; | ||
| unlockedSkills = ['+1 Ação']; | ||
|
|
||
| skills() { | ||
| switch (this.level) { | ||
| case 'Yellow': | ||
| this.skillTree = 1; | ||
| break; | ||
| case 'Orange': | ||
| this.skillTree = 2; | ||
| break; | ||
| case 'Red': | ||
| this.skillTree = 3; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| unlockedSkills() { | ||
| if (this.level === 'Yellow') { | ||
| this.skillTree.push(unlockedSkills[0]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { Skill } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| class Survivor { | ||
| name; | ||
| totalInjuries; | ||
| actions = 3; | ||
| equipment = {}; | ||
| level = 'Blue'; | ||
| experience = 0; | ||
| skillTree = []; | ||
|
|
||
| static allSurvivors = []; | ||
|
|
||
| constructor(name) { | ||
| this.name = name; | ||
| this.totalInjuries = 0; | ||
| this.constructor.allSurvivors.push({ survivor: this }); | ||
| } | ||
|
|
||
| injuries() { | ||
| this.totalInjuries++; | ||
|
|
||
| if (this.totalInjuries >= 3) { | ||
| return 'Fim do jogo. Você morreu!' | ||
| } else { | ||
| return `Cuidado, você possui o total de ${this.totalInjuries} ferimento(s)!` | ||
| } | ||
| } | ||
|
|
||
| killZumbi() { | ||
| this.experience += 1; | ||
| return 'Zumbi morto!' | ||
| } | ||
|
|
||
| endGame(){ | ||
| if(this.experience === 150){ | ||
| return `Fim do jogo!` | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { Survivor } | ||
|
|
||
|
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. Ficou muito bom o seu código, a lógica está clara e sua classe tá sensacional. Estou com vergonha da minha classe depois que vi a sua kkkk parabéns, está muito bom mesmo!! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| const { Survivor } = require('./Survivor') | ||
|
|
||
| describe('verify survivor class', () => { | ||
|
|
||
| let survivor1, survivor2; | ||
|
|
||
| beforeEach(() => { | ||
| survivor1 = new Survivor(); | ||
| survivor2 = new Survivor(); | ||
| }) | ||
|
|
||
| it('should check when the survivor suffers an injury', () => { | ||
| expect(survivor1.injuries()).toBe('Cuidado, você possui o total de 1 ferimento(s)!'); | ||
| }) | ||
|
|
||
| it('should check when the survivor suffers 03 injuries and die', () => { | ||
| survivor1.injuries(); | ||
| survivor1.injuries(); | ||
| expect(survivor1.injuries()).toBe('Fim do jogo. Você morreu!'); | ||
| }) | ||
|
|
||
| it('should check when the survivor kill a zumbi', () => { | ||
| expect(survivor1.killZumbi()).toBe('Zumbi morto!'); | ||
| expect(survivor1.experience).toBe(1); | ||
| }) | ||
|
|
||
| it('should check a list of survivors with the static variable', () => { | ||
| survivor1.name = 'Ellie'; | ||
| survivor2.name = 'Joel'; | ||
| expect(Survivor.allSurvivors).toBe(`[{ | ||
| survivor: Survivor { | ||
| name: 'Ellie', | ||
| totalInjuries: 0, | ||
| actions: 3, | ||
| equipment: {}, | ||
| level: 'blue', | ||
| experience: 0, | ||
| skillTree: [] | ||
| } | ||
| }, | ||
| { | ||
| survivor: Survivor { | ||
| name: 'Joel', | ||
| totalInjuries: 0, | ||
| actions: 3, | ||
| equipment: {}, | ||
| level: 'blue', | ||
| experience: 0, | ||
| skillTree: [] | ||
| } | ||
| }]`); | ||
| }) | ||
| }) |
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.
Mariana do céu, estou aplaudindo o seu código. Genial sua sacada de criar uma classe equipamentos e duas classes de tipos específicos de equipamentos herdando da genérica, uau!!