Added MiniScript version of 21_Calendar.

This commit is contained in:
JoeStrout
2023-07-25 17:27:50 -07:00
parent 8426a39c48
commit 6a611c04d7
3 changed files with 108 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
Conversion to [MiniScript](https://miniscript.org).
Ways to play:
1. Command-Line MiniScript:
Download for your system from https://miniscript.org/cmdline/, install, and then run the program with a command such as:
miniscript calendar.ms
2. Mini Micro:
Download Mini Micro from https://miniscript.org/MiniMicro/, launch, and then click the top disk slot and chose "Mount Folder..." Select the folder containing the BASIC program. Then, at the Mini Micro command prompt, enter:
load "calendar"
run

View File

@@ -0,0 +1,89 @@
import "stringUtil"
print " "*32 + "Calendar"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
startingDOW = 0
leapYear = false
// Note: while the original program required changes to the code to configure
// it for the current year, in this port we choose to ask the user.
// Here's the function to do that.
getParameters = function
days = "sunday monday tuesday wednesday thursday friday saturday".split
globals.startingDOW = 999
while startingDOW == 999
ans = input("What is the first day of the week of the year? ").lower
if not ans then continue
for i in days.indexes
if days[i].startsWith(ans) then
globals.startingDOW = -i
break
end if
end for
end while
while true
ans = input("Is it a leap year? ").lower
if ans and (ans[0] == "y" or ans[0] == "n") then break
end while
globals.leapYear = (ans[0] == "y")
while true
ans = input("Pause after each month? ").lower
if ans and (ans[0] == "y" or ans[0] == "n") then break
end while
globals.pause = (ans[0] == "y")
end function
getParameters
monthNames = [
" JANUARY ",
" FEBRUARY",
" MARCH ",
" APRIL ",
" MAY ",
" JUNE ",
" JULY ",
" AUGUST ",
"SEPTEMBER",
" OCTOBER ",
" NOVEMBER",
" DECEMBER",
]
monthDays = [31, 28 + leapYear, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
// Function to print one month calendar.
// month: numeric month number, 0-based (0-11)
printMonth = function(month)
daysSoFar = monthDays[:month].sum
daysLeft = monthDays[month:].sum
print "** " + str(daysSoFar).pad(4) + "*"*18 + " " + monthNames[month] +
" " + "*"*18 + " " + str(daysLeft).pad(4) + "**"
print
print " S M T W T F S"
print
print "*" * 61
// calculate the day of the week, from 0=Sunday to 6=Saturday
dow = (daysSoFar - startingDOW) % 7
print " " * 5 + " " * (8*dow), ""
for i in range(1, monthDays[month])
print str(i).pad(8), ""
dow += 1
if dow == 7 then
dow = 0
print
if i == monthDays[month] then break
print; print " " * 5, ""
end if
end for
print
end function
// Main loop.
for month in range(0, 11)
printMonth month
print
if month < 11 and pause then input
end for

View File

@@ -24,4 +24,6 @@ http://www.vintage-basic.net/games.html
#### Porting Notes
(please note any difficulties or challenges in porting here)
- While many modern environments have time/date functions that would make this program both easier and more automatic, in these ports we are choosing to do without them, as in the original program.
- Some ports choose to ask the user the starting day of week, and whether it's a leap year, rather than force changes to the code to fit the desired year.