User Tools

Site Tools


ugbasic:user:example:bug905
Translations of this page:


ugBASIC User Manual

PURPOSE

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * TRYING TO USE MORE GRAIN THAN IS IN SILOS? * TRYING TO PLANT MORE ACRES THAN YOU OWN? * ENOUGH GRAIN FOR SEED? * ENOUGH PEOPLE TO TEND THE CROPS? * A BOUNTIFUL HARVEST! * RATS ARE RUNNING WILD!! * LET'S HAVE SOME BABIES * HOW MANY PEOPLE HAD FULL TUMMIES? * HORROS, A 15% CHANCE OF PLAGUE * STARVE ENOUGH FOR IMPEACHMENT?

SOURCE CODE

 
 'DEFINE STRING SPACE 512
 'DEFINE STRING COUNT 32
 'DEFINE SCREEN MODE UNIQUE
 
 OPTION DEFAULT TYPE INTEGER
 TILEMAP ENABLE: CLS
 
 10 PRINT SPC((TILES WIDTH - 8)/2);"HAMURABI"
 20 PRINT SPC((TILES WIDTH - 18)/2);"CREATIVE COMPUTING"
    PRINT SPC((TILES WIDTH - 22)/2);"MORRISTOWN, NEW JERSEY"
 30 PRINT:PRINT:PRINT
 80 PRINT "TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA";
 90 PRINT " FOR A TEN-YEAR TERM OF OFFICE.":PRINT
 
    REM Initializes random number generator in a way that works for emulators too
    PRINT "PRESS A KEY...": WAIT KEY RELEASE: RANDOMIZE RASTER LINE 
  
 95 dead=0: DIM percStarved AS FLOAT: percStarved=0: DIM app AS FLOAT
 100 year=0: population=95: store=2800: harvested=3000: eaten=harvested-store
 110 bpa=3: acres=harvested/bpa: babies=5: plagueRoll=1: REM this is a value in [-3,16] that when <=0 will cause a plague
 
 210 starved=0
 
 	CLS
 215 PRINT:PRINT:PRINT "HAMURABI: I BEG TO REPORT TO YOU, ";: year=year+1
 217 PRINT "IN YEAR ";year;", ";starved;" PEOPLE STARVED,";babies;" CAME TO THE CITY.": PRINT
 218 population=population+babies
 
 227 IF plagueRoll>0 THEN 230
 228 population=population/2
 229 PRINT "A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED."
 
 230	PRINT "POPULATION : ";population
 	PRINT "ACRES OWNED: ";acres
 	PRINT "HARVESTED  : ";bpa;" BUSHELS/ACRE"
 	PRINT "RATS ATE   : ";eaten;" BUSHELS"
 	PRINT "STORE      : ";store;" BUSHELS": PRINT
 270 IF year=11 THEN 860
 
 	REM Check whether player wants to buy land
 	
 310 c=RND(10): bpa=c+17
 312 PRINT "LAND PRICE : ";bpa;" BUSHELS/ACRE."
 320 PRINT "BUY HOW MANY ACRES? ";
 321 INPUT q: IF q<0 THEN 850: REM Get angry and leave
 322 IF bpa*q<=store THEN 330
 323 GOSUB 710: REM Error message
 324 GOTO 320
 330 IF q=0 THEN 340
 331 acres=acres+q: store=store-bpa*q: c=0
 334 GOTO 400
 
 	REM Check whether player wants to sell land
 	
 340 PRINT "SELL HOW MANY ACRES? ";
 341 INPUT q: IF q<0 THEN 850: REM Get angry and leave
 342 IF q<acres THEN 350
 343 GOSUB 720: REM Error message
 344 GOTO 340
 350 acres=acres-q: store=store+bpa*q: c=0
 
 	REM Feed people
 	
 400 
 410 PRINT "FEED HOW MANY BUSHELS? ";
 411 INPUT q
 412 IF q<0 THEN 850: REM Get angry and leave
 420 IF q<=store THEN 430
 421 GOSUB 710: REM Error message
 422 GOTO 410
 430 store=store-q: c=1: PRINT
 
 	REM Plant crop
 	
 440 PRINT "PLANT HOW MANY ACRES? ";
 441 INPUT s: IF s=0 THEN 511
 442 IF s<0 THEN 850: REM Get angry and leave
 445 IF s<=acres THEN 450
 446 GOSUB 720: REM Error message
 447 GOTO 440
 450 IF (s/2)<=store THEN 455
 452 GOSUB 710: REM Error message
 453 GOTO 440
 455 IF s<10*population THEN 510
 460 PRINT "BUT YOU HAVE ONLY ";population;" PEOPLE TO TEND THE FIELDS! NOW THEN, ";
 470 GOTO 440
 510 store=store-(s/2)
 
 	REM Harvest, check rats, recompute store and population
 	
 511 GOSUB 800
 515 bpa=c: harvested=s*bpa: eaten=0
 521 GOSUB 800
 522 IF (c MOD 2)<>0 THEN 530
 525 eaten=store/c
 530 store=store-eaten+harvested
 531 GOSUB 800
 533 babies=INT((20.0*acres+store)*c/population/100.0+1.0)
 540 fed=q/20
 	REM This is indeed 20% chance
 542 plagueRoll=RND(20)-3:
 550 IF population<fed THEN 210
 552 starved=population-fed: IF starved>(0.45*population) THEN 560
 553 percStarved=(percStarved*(year-1)+100.0*starved/population)/year
 555 population=fed: dead=dead+starved: GOTO 215
 560 PRINT: PRINT "YOU STARVED ";starved;" PEOPLE IN ONE YEAR!!!"
 
 	REM Impeachment message
 	
 565 PRINT "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY ";
 566 PRINT "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE ";
 567 PRINT "ALSO BEEN DECLARED NATIONAL FINK!!!!": GOTO 990
 
 	REM Asked to sell too many bushels
 	
 710 PRINT "YOU HAVE ONLY ";
 711 PRINT store;"BUSHELS OF GRAIN."
 712 RETURN
 
 	REM Asked to sell too many acres
 	
 720 PRINT "YOU OWN ONLY ";acres;" ACRES."
 730 RETURN
 
 	REM Roll a 6-side dice in c
 	
 800 c=RND(5)+1
 801 RETURN
 
 	REM An invalid order was entered (e.g. buy a negative quantity of acres)
 	
 850 PRINT: PRINT "HAMURABI: I CANNOT DO WHAT YOU WISH."
 855 PRINT "GET YOURSELF ANOTHER STEWARD!!!!!"
 857 GOTO 990
 
 	REM End of game
 	
 860 PRINT: PRINT "IN YOUR TERM "; INT(percStarved); "% ";
 862 PRINT "PEOPLE DIED ON AVERAGE EACH YEAR. A TOTAL OF ";
 865 PRINT dead;"!!": app=acres/population
 870 PRINT "YOU STARTED WITH 10 ACRES/PERSON AND ENDED WITH ";
 875 PRINT INT(app);" ACRES/PERSON.": PRINT
 880 IF percStarved>33.0 THEN 565: REM Impeachemnt message
 885 IF app<7.0 THEN 565
 890 IF percStarved>10.0 THEN 940
 892 IF app<9.0 THEN 940
 895 IF percStarved>3.0 THEN 960
 896 IF app<10.0 THEN 960
 900 PRINT "A FANTASTIC PERFORMANCE!!! CHARLEMANGE, DISRAELI, AND ";
 905 PRINT "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!":GOTO 990
 940 PRINT "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV. ";
 945 PRINT "THE PEOPLE (REMIANING) FIND YOU AN UNPLEASANT RULER, AND, ";
 950 PRINT "FRANKLY, HATE YOUR GUTS!!":GOTO 990
 960 PRINT "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT ";
 965 PRINT "REALLY WASN'T TOO BAD AT ALL. ";INT(0.8*RND(population));" PEOPLE ";
 970 PRINT "WOULD DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR ";
 975 PRINT "TRIVIAL PROBLEMS."
 
 990 PRINT: FOR n=1 TO 10: 
 'BELL: 
 NEXT n
 995 PRINT "SO LONG FOR NOW.": PRINT
 999 END
 
 

SOURCE FILE

HOW TO COMPILE AND RUN

The instructions here refer to compiling the example from the command line. For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to compile the example with just one click.

ATARI 400/800 family

In order to compile and run the example, you need to have the Altirra emulator, and in particular that the altirra executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.atari bug905.bas -o example.xex
 altirra example.xex
 
 # Windows 
 ugbc.atari.exe bug905.bas -o example.xex
 altirra example.xex

ATARI 600XL/800XL/1200XL/XG(SE) family

In order to compile and run the example, you need to have the Altirra emulator, and in particular that the altirra executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.atarixl bug905.bas -o example.xex
 altirra example.xex
 
 # Windows 
 ugbc.atarixl.exe bug905.bas -o example.xex
 altirra example.xex

Commodore 64

In order to compile and run the example, you need to have the VICE emulator, and in particular that the x64sc executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.c64 bug905.bas -o example.prg
 x64sc example.prg
 
 # Windows 
 ugbc.c64.exe bug905.bas -o example.prg
 x64sc example.prg

Commodore 64+REU

In order to compile and run the example, you need to have the VICE emulator, and in particular that the x64sc executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.c64reu bug905.bas -o example.prg
 x64sc -reu example.prg
 
 # Windows 
 ugbc.c64reu.exe bug905.bas -o example.prg
 x64sc -reu example.prg

Commodore PLUS/4

Using YAPE

In order to run the example, you need to have the YAPE emulator. In particular that the yape executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.plus4 bug905.bas -o example.prg
 yape example.prg
 
 # Windows 
 ugbc.plus4.exe bug905.bas -o example.prg
 yape example.prg
Using VICE

In order to run the example, you need to have the VICE emulator. In particular that the xplus4 executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.plus4 bug905.bas -o example.prg
 xplus4 example.prg
 
 # Windows 
 ugbc.plus4.exe bug905.bas -o example.prg
 xplus4 example.prg

Dragon 32

In order to compile and run the example, you need to have the XROAR emulator, and in particular that the xroar executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.d32 bug905.bas -o example.bin
 xroar -rompath (your rom path) example.bin
 
 # Windows 
 ugbc.d32.exe bug905.bas -o example.bin
 xroar.exe -rompath (your rom path) example.bin

Dragon 64

In order to compile and run the example, you need to have the XROAR emulator, and in particular that the xroar executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.d64 bug905.bas -o example.bin
 xroar -rompath (your rom path) example.bin
 
 # Windows 
 ugbc.d64.exe bug905.bas -o example.bin
 xroar.exe -rompath (your rom path) example.bin

PC128 Olivetti Prodest

In order to compile and run the example, you need to have the DCMOTO emulator, and in particular that the dcmoto executable is accessible.

Then, type this command on the command line and on the emulator:

 # Linux 
 ugbc.pc128op bug905.bas -o example.k7
 dcmoto
 (choose BASIC 128)
 CLEAR,&H2FFF: LOADM"CASS:",R: EXEC
 
 # Windows 
 ugbc.pc128op.exe bug905.bas -o example.k7
 dcmoto
 (choose example.k7)
 (choose BASIC 128)
 CLEAR,&H2FFF: LOADM"CASS:",R: EXEC

Thomson MO5

In order to compile and run the example, you need to have the DCMOTO emulator, and in particular that the dcmoto executable is accessible.

Then, type this command on the command line and on the emulator:

 # Linux 
 ugbc.pc128op bug905.bas -o example.k7
 dcmoto
 (choose BASIC 128)
 CLEAR,&H2FFF: LOADM"CASS:",R: EXEC
 
 # Windows 
 ugbc.pc128op.exe bug905.bas -o example.k7
 dcmoto
 (choose example.k7)
 (choose BASIC 128)
 CLEAR,&H2FFF: LOADM"CASS:",R: EXEC

Commodore VIC-20

In order to compile and run the example, you need to have the VICE emulator, and in particular that the xvic executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.vic20 bug905.bas -o example.prg
 xvic --memory 24k example.prg
 
 # Windows 
 ugbc.vic20.exe bug905.bas -o example.prg
 xvic --memory 24k example.prg

ZX Spectrum

In order to compile and run the example, you need to have the Speccy emulator, and in particular that the speccy executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.zx bug905.bas -o example.tap
 Speccy example.tap
 
 # Windows 
 ugbc.zx.exe bug905.bas -o example.tap
 Speccy example.tap

MSX

In order to compile and run the example, you need to have the openMsx or the BlueMSX emulator, and in particular that its executable is accessible.

Then, type this command on the command line:

openMSX
 # Linux 
 ugbc.msx1 bug905.bas -o example.rom
 openmsx -cart example.rom
 
 # Windows 
 ugbc.msx1.exe bug905.bas -o example.rom
 openmsx -cart example.rom
blueMSX
 # Linux 
 ugbc.msx1 bug905.bas -o example.rom
 bluemsx example.rom
 
 # Windows 
 ugbc.msx1.exe bug905.bas -o example.rom
 bluemsx example.rom

ColecoVision

In order to compile and run the example, you need to have the openMsx or the BlueMSX emulator, and in particular that its executable is accessible.

Then, type this command on the command line:

openMSX
 # Linux 
 ugbc.coleco bug905.bas -o example.rom
 openmsx -machine \"COL - ColecoVision\" -cart example.rom
 
 # Windows 
 ugbc.coleco.exe bug905.bas -o example.rom
 bluemsx -machine \"COL - ColecoVision\" example.rom
blueMSX
 # Linux 
 ugbc.coleco bug905.bas -o example.rom
 bluemsx /machine \"COL - ColecoVision\" /rom1 example.rom
 
 # Windows 
 ugbc.coleco.exe bug905.bas -o example.rom
 bluemsx  /machine \"COL - ColecoVision\" /rom1 example.rom

SEGA SC-3000

In order to compile and run the example, you need to have the BlueMSX emulator, and in particular that its executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.sc3000 bug905.bas -o example.rom
 bluemsx /machine \"SEGA - SC-3000\" /rom1 example.rom
 
 # Windows 
 ugbc.sc3000.exe bug905.bas -o example.rom
 bluemsx  /machine \"SEGA - SC-3000\" /rom1 example.rom

SEGA SG-1000

In order to compile and run the example, you need to have the BlueMSX emulator, and in particular that its executable is accessible.

Then, type this command on the command line:

 # Linux 
 ugbc.sg1000 bug905.bas -o example.rom
 bluemsx /machine \"SEGA - SG-1000\" /rom1 example.rom
 
 # Windows 
 ugbc.sg1000.exe bug905.bas -o example.rom
 bluemsx  /machine \"SEGA - SG-1000\" /rom1 example.rom

ANY PROBLEM?

If you have found a problem trying to run this example, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub. Thank you!

POWERED BY