diff --git a/src/components/Game.astro b/src/components/Game.astro index 3e5869e..b28ab6c 100644 --- a/src/components/Game.astro +++ b/src/components/Game.astro @@ -9,18 +9,27 @@
-
+
+

Mercado

+
+
- + + diff --git a/src/components/cards/DrugCard.astro b/src/components/cards/DrugCard.astro new file mode 100644 index 0000000..e69de29 diff --git a/src/services/drugs.ts b/src/services/drugs.ts index e69de29..e708b41 100644 --- a/src/services/drugs.ts +++ b/src/services/drugs.ts @@ -0,0 +1,12 @@ +import { db, type City, type Drug } from './db'; + +export async function getDrugs(): Promise { + return await db.drugs.toArray(); +} + +export function calculateDrugPrice(drug: Drug, city: City): number { + const demand = city.population / (1000 * Math.random()); + const supply = city.population / (1000 * Math.random()); + const price = Number(drug.basePrice * (demand / supply)); + return Number(price.toFixed(2)); +} \ No newline at end of file diff --git a/src/services/players.ts b/src/services/players.ts index fe7d944..d696359 100644 --- a/src/services/players.ts +++ b/src/services/players.ts @@ -27,3 +27,14 @@ export async function getCurrentPlayer(): Promise { if (!id) return; return db.players.get(Number(id.value)); } + + +export async function travel(player: Player, cityId: number) { + if (player.money < 10) { + throw new Error("Not enough money to travel"); + } + player.money -= 10; + player.cityId = cityId; + await db.players.update(player.id, player); + currentPlayer.set(player); +} \ No newline at end of file