From 5e5b1bd3982d03b1a0f15de2ed94ab98c8d5d91d Mon Sep 17 00:00:00 2001 From: nihilazo Date: Thu, 25 Mar 2021 10:11:14 +0000 Subject: [PATCH] make pay and can-afford? words work wwith other currencies --- main.fs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.fs b/main.fs index f392092..1db7992 100644 --- a/main.fs +++ b/main.fs @@ -123,11 +123,11 @@ S" you feel like throwing some stuff into the pool." set-message \ the word exit-game exits the game. : exit-game page show-cursor bye ; -\ the word can-afford? tests if you could afford n devices. -: can-afford? ( n -- flag ) s>f devices f@ f<= ; +\ the word can-afford? tests if you could afford n of a currency. +: can-afford? ( n currency -- flag ) f@ s>f f>= ; -\ the word pay pays an amount of devices -: pay ( n -- ) s>f devices f@ fswap f- devices f! ; +\ the word pay pays an amount of a currency. +: pay ( n currency -- ) dup f@ swap s>f fswap f- f! ; \ the word clear-message clears the onscreen message : clear-message S" " set-message ; @@ -135,9 +135,9 @@ S" you feel like throwing some stuff into the pool." set-message \ the word hire-chat-member hires a chat member. : hire-chat-member membercost @ dup !0= swap \ checks if cost is nonzero, leaving member cost on the stack - can-afford? + devices can-afford? and if - membercost @ pay + membercost @ devices pay 1 membercount +! \ add a member to the count membercount @ 2 * 5 + membercost +! \ increase the cost of buying a new member membercost 1 changed @@ -147,9 +147,9 @@ S" you feel like throwing some stuff into the pool." set-message \ the word build-construct builds a construct. : build-construct constructcost @ dup !0= swap - can-afford? + devices can-afford? and if - constructcost @ pay + constructcost @ devices pay 1 constructcount +! constructcount @ 4 * 10 + constructcost +! constructcount 1 changed