From cb000d29aa2a6913816e0673eaf7d9123386b034 Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Sat, 26 Apr 2025 19:37:09 +0200 Subject: [PATCH] buy ships --- .../ship-dialog/ship-dialog.component.html | 3 +-- .../ship-dialog/ship-dialog.component.scss | 2 +- .../dialog/ship-dialog/ship-dialog.component.ts | 4 ++++ src/app/components/ships/buy/buy.component.html | 1 + src/app/components/ships/buy/buy.component.ts | 5 +++-- .../tutorial/welcome/welcome.component.html | 12 +++++++----- .../tutorial/welcome/welcome.component.scss | 4 ++++ .../tutorial/welcome/welcome.component.ts | 3 ++- src/app/model/ships/ship.model.ts | 17 +++++++++++++---- src/app/scene/map.scene.ts | 8 ++++++++ src/app/service/game.service.ts | 10 +++++++++- 11 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/app/components/dialog/ship-dialog/ship-dialog.component.html b/src/app/components/dialog/ship-dialog/ship-dialog.component.html index 4e96e82..2920841 100644 --- a/src/app/components/dialog/ship-dialog/ship-dialog.component.html +++ b/src/app/components/dialog/ship-dialog/ship-dialog.component.html @@ -71,8 +71,7 @@
- - +
diff --git a/src/app/components/dialog/ship-dialog/ship-dialog.component.scss b/src/app/components/dialog/ship-dialog/ship-dialog.component.scss index a9f51e6..aebc929 100644 --- a/src/app/components/dialog/ship-dialog/ship-dialog.component.scss +++ b/src/app/components/dialog/ship-dialog/ship-dialog.component.scss @@ -5,7 +5,7 @@ position: absolute; top: 24px; left: 24px; - // width: 240px; + width: 400px; // height: 240px; // background-color: var(--background-color); // color: var(--primary-color); diff --git a/src/app/components/dialog/ship-dialog/ship-dialog.component.ts b/src/app/components/dialog/ship-dialog/ship-dialog.component.ts index 4abcda4..d14af4a 100644 --- a/src/app/components/dialog/ship-dialog/ship-dialog.component.ts +++ b/src/app/components/dialog/ship-dialog/ship-dialog.component.ts @@ -42,4 +42,8 @@ export class ShipDialogComponent { get activeRoute(): string[] { return this.ship.route?.planetNames ?? [] } + + sell() { + this.gameService.sellShip(this.ship); + } } diff --git a/src/app/components/ships/buy/buy.component.html b/src/app/components/ships/buy/buy.component.html index 5fc1b6f..f8e19c6 100644 --- a/src/app/components/ships/buy/buy.component.html +++ b/src/app/components/ships/buy/buy.component.html @@ -5,6 +5,7 @@
🚀 Neues Schiff: Pioneer-1
+
{{ config.desciption }}
@@ -45,13 +45,15 @@ Achte auf die Bedürfnisse der Siedlungen. Gut versorgte Kolonien wachsen und erhöhen ihren Bedarf an Waren. Bei Mangel wandern die Siedler ab! Für den Anfang benötigen die Kolonien nur Nahrung und Wasser. Mit wachsender Bevölkerung steigt auch der Bedarf an weiteren Rohstoffen.

- Du beginnst mit 10.000 Credits. Gib sie weise aus, Schiffe und Raumhäfen kosten Unterhalt. Je mehr Waren du transportierst, desto mehr Geld verdienst du auch. Planeten kaufen allerdings nur Waren, die sie auch brauchen. + Du beginnst mit {{ gameService.money | number }} Credits. Gib sie weise aus, Schiffe und Raumhäfen kosten Unterhalt. Je mehr Waren du transportierst, desto mehr Geld verdienst du auch. Planeten kaufen allerdings nur Waren, die sie auch brauchen. Schiffe auf Handelsrouten fliegen die Planeten ab, und versorgen sie automatisch mit den Gütern die sie benötigen. +

+ Gute Planeten für den Start sind Terra Nova und Aqualis, da sie Nahrung und Wasser produzieren.

- +
\ No newline at end of file diff --git a/src/app/components/tutorial/welcome/welcome.component.scss b/src/app/components/tutorial/welcome/welcome.component.scss index bc4be99..f26f24b 100644 --- a/src/app/components/tutorial/welcome/welcome.component.scss +++ b/src/app/components/tutorial/welcome/welcome.component.scss @@ -17,4 +17,8 @@ overflow: hidden; display: flex; flex-direction: column; +} + +p { + font-size: 13px; } \ No newline at end of file diff --git a/src/app/components/tutorial/welcome/welcome.component.ts b/src/app/components/tutorial/welcome/welcome.component.ts index 98d7b02..6042a60 100644 --- a/src/app/components/tutorial/welcome/welcome.component.ts +++ b/src/app/components/tutorial/welcome/welcome.component.ts @@ -1,9 +1,10 @@ import { Component, inject } from '@angular/core'; import { GameService } from '../../../service/game.service'; +import { CommonModule } from '@angular/common'; @Component({ selector: 'app-welcome', - imports: [], + imports: [CommonModule], templateUrl: './welcome.component.html', styleUrl: './welcome.component.scss' }) diff --git a/src/app/model/ships/ship.model.ts b/src/app/model/ships/ship.model.ts index 37fa974..7d203b9 100644 --- a/src/app/model/ships/ship.model.ts +++ b/src/app/model/ships/ship.model.ts @@ -13,6 +13,7 @@ export interface ShipConfig { cost: number; planetRoute: Planet[]; buyCost: number; + desciption: string; } export class Ship { @@ -26,8 +27,12 @@ export class Ship { public name = "Pioneer-01-" + Math.round(Math.random() * 100); public loadingSpeed = 3.5; public cost = 0.5 + public buyCost = 0; + public description: string = ""; - private updateInterval = interval(1000); + private updateInterval = interval(1000).subscribe(() => { + this.update(); + }) private gameService: GameService; constructor(gameService: GameService, config: ShipConfig) { @@ -37,11 +42,10 @@ export class Ship { this.maxSpeed = config.maxSpeed; this.loadingSpeed = config.loadingSpeed; this.cost = config.cost; + this.buyCost = config.buyCost; + this.description = config.desciption; this.route = new TradeRoute(config.planetRoute) - this.updateInterval.subscribe(() => { - this.update(); - }) } @@ -163,6 +167,11 @@ export class Ship { update() { this.gameService.money -= this.cost; } + + + sell() { + this.updateInterval.unsubscribe(); + } } export enum FlightMode { diff --git a/src/app/scene/map.scene.ts b/src/app/scene/map.scene.ts index 780f739..23620c9 100644 --- a/src/app/scene/map.scene.ts +++ b/src/app/scene/map.scene.ts @@ -101,6 +101,14 @@ export class MapScene extends Phaser.Scene { this.physics.world.enable(ui); this.ships.push(ui); }) + + this.gameService.onShipDestroy.subscribe(ship => { + const ui = this.ships.find(i => i.model = ship); + if (ui) { + ui.destroy(); + } + this.ships = this.ships.filter(s => s != ui); + }) // this.enableMouseLogging(); } diff --git a/src/app/service/game.service.ts b/src/app/service/game.service.ts index 76c5a3a..957106a 100644 --- a/src/app/service/game.service.ts +++ b/src/app/service/game.service.ts @@ -15,9 +15,10 @@ export class GameService { showTutorial = true; - public money = 10000; + public money = 12000; onShipCreate: EventEmitter = new EventEmitter(); + onShipDestroy: EventEmitter = new EventEmitter(); constructor() {} @@ -43,4 +44,11 @@ export class GameService { this.ships.push(ship); this.onShipCreate.emit(ship); } + + sellShip(ship: Ship) { + this.ships = this.ships.filter(s => s != ship); + ship.sell(); + this.onShipDestroy.emit(ship); + this.money += ship.buyCost; + } } \ No newline at end of file