Skip to content

Commit

Permalink
connect flood and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad2002 committed Oct 29, 2023
1 parent 8277d7a commit 7769b65
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 36 deletions.
3 changes: 1 addition & 2 deletions tidal-harvest/src/app/core/game/TickMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {CropKey} from "../model/field/farm/crop/CropKey";
import {Crop} from "../model/field/farm/crop/Crop";
import {Silo} from "../model/field/farm/Silo";
import {Flood} from "./Flood";
import {CropAmount} from "../model/economy/CropAmount";

export class TickMachine {

Expand Down Expand Up @@ -49,7 +48,7 @@ export class TickMachine {
});
this._tick.next(this._matrix);
this._globalCrops.next(this.countCrops()); // probably calls #countCrops way too often (no time to fix)
if (counter % 60 === 0) {
if (counter % 10 === 0) {
this._flood.next(new Flood(this._matrix, this._gameObjects).flood())
}
}, 1000);
Expand Down
9 changes: 7 additions & 2 deletions tidal-harvest/src/app/core/service/ui.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ export class UiService {
}

public getFloodMatrix(): Observable<boolean[][]> {
this.flood.next(this.floodMatrix)
return this.flood;
return this.game.flood();
}

public triggerFlood(): void {
this.flood.next(this.floodMatrix)
}

public collectCrops(x: number, y: number) {
console.log("collect crops at: " + x + ";" + y);
}


}
5 changes: 4 additions & 1 deletion tidal-harvest/src/app/ui/grid/ship/ship.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<img src="assets/ship.png" alt="ship" (click)="onShipClick()">
<img src="assets/ship.png" alt="ship" (click)="showShop = true">
<th-big-popup [popupTitle]="'Shop'" *ngIf="showShop" (close)="showShop = false">
<p>Ganz toller Shop Content!!</p>
</th-big-popup>
5 changes: 2 additions & 3 deletions tidal-harvest/src/app/ui/grid/ship/ship.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Component } from '@angular/core';
})
export class ShipComponent {

onShipClick() {
alert("SHOP!!");
}
showShop: boolean = false;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="popup-container">
<button class="close-btn" (click)="onClose()"></button>
<h1>{{popupTitle}}</h1>
<ng-content></ng-content>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
:host {
position: fixed;
top: 0;
left: 0;
z-index: 16;
background-color: #0006;
width: 100%;
height: 100vh;
}

.popup-container {
background-image: url("/assets/ui/popup_big.png");
width: 500px;
background-size: 100%;
height: 284px;
margin: 23vh auto;
color: black;
padding: 10px 40px;

h1 {
text-align: center;
}
}

.close-btn {
margin-left: 494px;
margin-top: 9px;
position: absolute;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { BigPopupComponent } from './big-popup.component';

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

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [BigPopupComponent]
});
fixture = TestBed.createComponent(BigPopupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Component, EventEmitter, Input, Output} from '@angular/core';

@Component({
selector: 'th-big-popup',
templateUrl: './big-popup.component.html',
styleUrls: ['./big-popup.component.scss']
})
export class BigPopupComponent {
@Input() popupTitle: string = "Mitteilung";
@Output() close: EventEmitter<any> = new EventEmitter<any>();

onClose() {
this.close.emit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<select formControlName="cropType">
<option *ngFor="let cropType of cropTypes" [value]="cropType">{{cropType}}</option>
</select>
<th-button (buttonClick)="selectCropType()">Select</th-button>
<th-button (buttonClick)="selectCropType()">Auswählen</th-button>
</form>
<th-button (buttonClick)="selectCropType()" [active]="field.crops > 0">Sammeln</th-button>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,10 @@
font-weight: normal;
margin-left: 4px;
}
}

.close-btn {
background-image: url("/assets/ui/close_btn.png");
background-size: 100%;
width: 20px;
height: 20px;
padding: 0;
margin: 0;
background-color: transparent;
border: none;
position: absolute;
top: -6px;
left: 93px;
cursor: pointer;

&:hover {
filter: brightness(1.3);
}
}
.close-btn {
position: absolute;
top: -6px;
left: 93px;
}
7 changes: 5 additions & 2 deletions tidal-harvest/src/app/ui/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ButtonComponent } from './button/button.component';
import {ReactiveFormsModule} from "@angular/forms";
import { WaterSourcePopupComponent } from './popup/field-popup/water-source-popup/water-source-popup.component';
import { SiloPopupComponent } from './popup/field-popup/silo-popup/silo-popup.component';
import { BigPopupComponent } from './popup/big-popup/big-popup.component';



Expand All @@ -22,12 +23,14 @@ import { SiloPopupComponent } from './popup/field-popup/silo-popup/silo-popup.co
WaterChannelPopupComponent,
ButtonComponent,
WaterSourcePopupComponent,
SiloPopupComponent
SiloPopupComponent,
BigPopupComponent

],
exports: [
FieldPopupComponent,
ButtonComponent
ButtonComponent,
BigPopupComponent
],
imports: [
CommonModule,
Expand Down
21 changes: 14 additions & 7 deletions tidal-harvest/src/app/ui/ui.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<th-button [buttonType]="placing === FieldType.FARMER ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMER)">{{placing === FieldType.FARMER ? 'abbrechen' : 'Farmer setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.FARMLAND ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMLAND)">{{placing === FieldType.FARMLAND ? 'abbrechen' : 'Acker setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.ROCK ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.ROCK)">{{placing === FieldType.ROCK ? 'abbrechen' : 'Stein setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.WATER_CHANNEL ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.WATER_CHANNEL)">{{placing === FieldType.WATER_CHANNEL ? 'abbrechen' : 'Graben setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.SILO ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.SILO)">{{placing === FieldType.SILO ? 'abbrechen' : 'Silo setzen'}}</th-button>
<hr>
<th-button [buttonType]="'normal'" (buttonClick)="triggerFlood()">Flut auslösen</th-button>

<div class="header">
<th-button [buttonType]="placing === FieldType.FARMER ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMER)">{{placing === FieldType.FARMER ? 'abbrechen' : 'Farmer setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.FARMLAND ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMLAND)">{{placing === FieldType.FARMLAND ? 'abbrechen' : 'Acker setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.ROCK ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.ROCK)">{{placing === FieldType.ROCK ? 'abbrechen' : 'Stein setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.WATER_CHANNEL ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.WATER_CHANNEL)">{{placing === FieldType.WATER_CHANNEL ? 'abbrechen' : 'Graben setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.SILO ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.SILO)">{{placing === FieldType.SILO ? 'abbrechen' : 'Silo setzen'}}</th-button>
<hr>
<th-button [buttonType]="'normal'" (buttonClick)="triggerFlood()">Flut auslösen</th-button>
</div>

<div class="footer">
&copy; Carmen, Entjic (V) und Konrad
</div>

<th-grid
*ngIf="matrix"
Expand Down
16 changes: 16 additions & 0 deletions tidal-harvest/src/app/ui/ui.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ th-grid {
display: block;
margin: 0
}

.header,
.footer {
position: fixed;
background-color: transparent;
z-index: 11;
width: 100%;
}

.header {
top: 0;
}

.footer {
bottom: 0;
}
17 changes: 17 additions & 0 deletions tidal-harvest/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ body {
color: #d3d3d3;
margin: 0;
}


.close-btn {
background-image: url("/assets/ui/close_btn.png");
background-size: 100%;
width: 20px;
height: 20px;
padding: 0;
margin: 0;
background-color: transparent;
border: none;
cursor: pointer;

&:hover {
filter: brightness(1.3);
}
}

0 comments on commit 7769b65

Please sign in to comment.