Magic Square variation

Started by geecee, March 09, 2009, 12:21:53 AM

Previous topic - Next topic

geecee

Here's another short programme ...... A Magic Square variation.

There is still a problem with the alignment in the last line of the Magic Square numbers ...... Maybe someone can offer a solution.

May be room for improvement in the coding also.

Numbers less than 10 are preceeded by a zero to enhance the screen appearance.

I have restricted the number selection range to between 34 and 360 simply to keep any number inside a square from being double zero and from exceeding two digits.

PlayBASIC Code: [Select]
remstart
=======================================================

MAGIC SQUARE VARIATION
***********************

Author: geecee
Written for Play Basic - March 2009

***********************

=======================================================
remend


` Start of programme
start:

` Clear screen
cls rgb(0,0,0)

` Tell PB to include the input support library
#include "Input"

` Declare array/s
dim message$(4)

` Set down coordinate
down=30

` Set new ink colour
ink rgb(255,217,128)

` Set text style and size
loadfont "arial bold",1,30,0

` Define title
title$="MAGIC SQUARE VARIATION"

` Write title to screen
centertext 400,down,title$

` Set text style and size
loadfont "arial bold",1,20,0

` Determine height of text
height=gettextheight("arial bold")

` Until criteria are met
repeat

` Define message/s
message$="Enter any number over 33 up to 360 > "

` Determine width of message
width=gettextwidth(message$)

` Set cursor position and enter the desired number
setcursor 400-width/2,300
select_a_number$=staticinput(message$)

` Set new ink colour and draw box to hide previous text at location
ink rgb(0,0,0)
box 2,300,799,320,1

` A short wait before proceeding
sync
wait 3000

` Set new ink colour
ink rgb(255,217,128)

until val(select_a_number$)>33 and val(select_a_number$)<361

` Define message/s and write to screen
message$="You chose the number "+str$(val(select_a_number$))
centertext 400,down+height*4,message$

` A short wait before proceeding
sync
wait 1000

` Define message/s and write to screen
message$="Please wait while the Magic Square is being built"
centertext 400,down+height*6,message$

` A short wait before proceeding
sync
wait 3000*200

` Determine start number and remainder
start_number=val(select_a_number$)-30
remainder=mod(start_number,4)
start_number=start_number/4

t$=""
for a=start_number to start_number+15
c=(a-Start_number)+1
t$=t$+digits$(a,2)+" "
c$=right$(t$,12)
if mod(c,4)=0
if c=16
if remainder=1 or remainder=2 or remainder=3
k=val(mid$(c$,1,2))+remainder
l=val(mid$(c$,4,2))+remainder
m=val(mid$(c$,7,2))+remainder
n=val(mid$(c$,10,2))+remainder
c$=str$(k)+" "+str$(l)+" "+str$(m)+" "+str$(n)
endif
endif
if c=4
centertext 400,down+height*10,c$
endif
if c=8
centertext 400,down+height*11,c$
endif
if c=12
centertext 400,down+height*12,c$
endif
if c=16
centertext 400,down+height*13,c$
endif
endif
next

` A short wait before proceeding
sync
wait 1000

` Define message/s
message$(1)="Write down these numbers as they are ...... Press any key when ready."

` Write message/s to screen
centertext 400,down+height*16,message$(1)

` Wait for a keypress
sync
waitkey
waitnokey

` Go to subroutine to draw box
gosub draw_a_box

` A short wait before proceeding
sync
wait 1000

` Define message/s and write to screen
message$(1)="Circle any one of the numbers and cross out the other numbers in the same row and"
message$(2)="column ...... Press any key when ready"
Login required to view complete source code


As always, comments constructive or otherwise appreciated.

:)
Enjoy
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

micky4fun

Hi geecee

another great little trick with numbers , just love it

mick :)