Skip to content

Commit

Permalink
add password-board component
Browse files Browse the repository at this point in the history
initial implementation
update project version
  • Loading branch information
bugtamer committed Jul 27, 2020
1 parent 9c952e7 commit 816ce81
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "megaman2",
"version": "0.1.0",
"version": "0.2.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { Megaman2Component } from './components/megaman2/megaman2.component';
import { PasswordBoardComponent } from './components/password-board/password-board.component';

@NgModule({
declarations: [
AppComponent,
Megaman2Component
Megaman2Component,
PasswordBoardComponent
],
imports: [
BrowserModule
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/megaman2/megaman2.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<mm2-password-board [data]="password.compute"></mm2-password-board>
<pre>{{ passwordCoordinates }}</pre>

<button (click)="password.incEtanks()" [disabled]="isIncButtonDisable">Increase E-tank</button>
<button (click)="password.decEtanks()" [disabled]="isDecButtonDisable">Decrease E-tank</button>

<p>E-tanks: {{ password.currentEtanks }}</p>
<p>{{ password.currentEtanks }} E-tanks</p>

<div *ngFor="let boss of password.bosses">
<input type="checkbox" (change)="boss.toggleIsDefeated()" [id]="boss.name">
Expand Down
11 changes: 11 additions & 0 deletions src/app/components/password-board/password-board.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table {
border-collapse: collapse;
}

td {
border: 1px solid black;
}

.hide {
border: none;
}
18 changes: 18 additions & 0 deletions src/app/components/password-board/password-board.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table>
<tr>
<td class="hide"></td>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
<tr *ngFor="let row of rows">
<th>{{ row[0] }}</th>
<td>{{ row[1] }}</td>
<td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>
<td>{{ row[4] }}</td>
<td>{{ row[5] }}</td>
</tr>
</table>
25 changes: 25 additions & 0 deletions src/app/components/password-board/password-board.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PasswordBoardComponent } from './password-board.component';

describe('PasswordBoardComponent', () => {
let component: PasswordBoardComponent;
let fixture: ComponentFixture<PasswordBoardComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PasswordBoardComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PasswordBoardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
43 changes: 43 additions & 0 deletions src/app/components/password-board/password-board.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Component, Input } from '@angular/core';
import { Coordinate as xy } from 'src/app/models/coordinate.model';

@Component({
selector: 'mm2-password-board',
templateUrl: './password-board.component.html',
styleUrls: ['./password-board.component.css']
})
export class PasswordBoardComponent {

@Input()
data: Array<xy> = [];

get rows(): any {
const rows = [];
for (let x of this.rowHeader) {
const newRow = [x];
for (let y of this.colHeader) {
const marker = this.getMarker(x, y);
newRow.push(marker);
}
rows.push(newRow);
}
return rows;
}

// LOWER LEVEL IMPLEMENTATION DETAILS

private getMarker(x: string, y: string): string {
const target = `${x}${y}`;
const wasFound = this.data.find(candidate => candidate.xy === target);
return wasFound ? '*' : '';
}

private get colHeader(): Array<string> {
return ['1', '2', '3', '4', '5'];
}

private get rowHeader(): Array<string> {
return ['A', 'B', 'C', 'D', 'E'];
}

}

0 comments on commit 816ce81

Please sign in to comment.