| Welcome, Guest |
You have to register before you can post on our site.
|
| Forum Statistics |
» Members: 48
» Latest member: matty47
» Forum threads: 346
» Forum posts: 2,536
Full Statistics
|
| Online Users |
There are currently 72 online users. » 0 Member(s) | 69 Guest(s) Applebot, Baidu, Bing
|
| Latest Threads |
MoonBASIC
Forum: Programming
Last Post: Marcus
2 hours ago
» Replies: 7
» Views: 197
|
Game Structure Opinions
Forum: Everything else
Last Post: johnno56
04-18-2026, 02:52 PM
» Replies: 7
» Views: 513
|
Card Suit Symbols
Forum: NaaLaa 7 Questions
Last Post: johnno56
04-15-2026, 11:49 PM
» Replies: 4
» Views: 775
|
Blackjack (ASCII Edition)
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
04-15-2026, 07:24 AM
» Replies: 0
» Views: 461
|
Loopz
Forum: NaaLaa 7 Code
Last Post: kevin
04-14-2026, 06:07 PM
» Replies: 10
» Views: 438
|
Jam for All Basic Dialect...
Forum: Programming
Last Post: luwal
04-12-2026, 11:50 PM
» Replies: 96
» Views: 11,582
|
val() command
Forum: NaaLaa 7 Questions
Last Post: johnno56
04-12-2026, 07:40 PM
» Replies: 2
» Views: 645
|
Continue
Forum: NaaLaa 7 Questions
Last Post: johnno56
04-12-2026, 05:54 AM
» Replies: 6
» Views: 825
|
Knightbridge
Forum: NaaLaa 7 Code
Last Post: kevin
04-10-2026, 10:19 AM
» Replies: 7
» Views: 276
|
Is this type of game on t...
Forum: Suggestions
Last Post: luwal
04-03-2026, 12:45 AM
» Replies: 2
» Views: 1,270
|
|
|
| Blackjack (ASCII Edition) |
|
Posted by: 1micha.elok - 04-15-2026, 07:24 AM - Forum: NaaLaa 7 Code
- No Replies
|
 |
==================
BLACKJACK
- ASCII Edition
==================
Code: ' ==================
' BLACKJACK
' - ASCII Edition
' ==================
randomize time()
visible values=[], deckRank=[], deckSuit=[], deckIdx = 0
visible pRank=[], pSuit=[], pCount=0 'player
visible cRank=[], cSuit=[], cCount=0 'computer
visible buf = fill(" ",6,100) 'buffer
values = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]
TitleScreen()
' --------------------
' MAIN LOOP
' --------------------
do
system("cls")
pCount = 0;cCount = 0
InitDeck()
ShuffleDeck()
' Deal initial 2 cards each, 1 card is hidden
Deal("p"); Deal("c")
Deal("p"); Deal("c")
PlayerTurn()
' Computer plays only if player hasn't busted
if CalcScore("p") <= 21 then
ComputerTurn()
system("cls")
endif
ShowHands(0)
DetermineWinner()
pln chr(7)'beep sound
wln "Play again? [1/0]: "
wln "(1) Yes"
wln "(0) No"
ans=rln()
if ans <> 1 then break
loop
' ----------------------
' FUNCTIONS
' ----------------------
function InitDeck()
idx = 0
for s = 3 to 6 'suits ASCII code
for v = 0 to 12 'values
deckRank[idx] = v
deckSuit[idx] = s
idx = idx + 1
next
next
endfunc
function ShuffleDeck()
for i = 51 to 1 step -1
j = rnd(0, i)
tmpR = deckRank[i]
tmpS = deckSuit[i]
deckRank[i] = deckRank[j]
deckSuit[i] = deckSuit[j]
deckRank[j] = tmpR
deckSuit[j] = tmpS
next
deckIdx = 0
endfunc
function Deal(who)
if who = "p" then 'player
pRank[pCount] = deckRank[deckIdx]
pSuit[pCount] = deckSuit[deckIdx]
pCount = pCount + 1
else 'computer
cRank[cCount] = deckRank[deckIdx]
cSuit[cCount] = deckSuit[deckIdx]
cCount = cCount + 1
endif
deckIdx = deckIdx + 1
endfunc
function CalcScore(who)
score = 0
aces = 0
cnt = 0
if who = "p" then
cnt = pCount
else
cnt = cCount
endif
for i = 0 to cnt - 1
r = 0
if who = "p" then
r = pRank[i]
else
r = cRank[i]
endif
if r = 0 then
aces = aces + 1
score = score + 11
elseif r >= 10 then
score = score + 10
else
score = score + (r + 1)
endif
next
' Adjust Aces from 11 to 1 if busting
while score > 21 and aces > 0
score = score - 10
aces = aces - 1
wend
return score
endfunc
function DrawCardToBuf(v, suit, offset)
w = 5
h = 3
' Top border
buf[0][offset] = chr(218)
for i = 1 to w
buf[0][offset+i] = chr(196)
next
buf[0][offset+w+1] = chr(191)
' Value row
buf[1][offset] = chr(179)
for i = 1 to w
buf[1][offset+i] = chr(32)
next
if v = "10" then
buf[1][offset+1] = "1"
buf[1][offset+2] = "0"
else
buf[1][offset+1] = v
endif
buf[1][offset+w+1] = chr(179)
' Middle row
buf[2][offset] = chr(179)
for i = 1 to w
buf[2][offset+i] = chr(32)
next
buf[2][offset+w+1] = chr(179)
' Suit row
buf[h][offset] = chr(179)
for i = 1 to w
buf[h][offset+i] = chr(32)
next
if v=chr(32) then
buf[h][offset+w] = chr(32)
else
buf[h][offset+w] = chr(suit)
endif
buf[h][offset+w+1] = chr(179)
' Bottom border
buf[h+1][offset] = chr(192)
for i = 1 to w
buf[h+1][offset+i] = chr(196)
next
buf[h+1][offset+w+1] = chr(217)
endfunc
function ShowHands(hideComp)
' Clear buffer
for r = 0 to 4
for c = 0 to 70
buf[r][c] = " "
next
next
' Computer
for i = 0 to cCount - 1
if i = 0 and hideComp = 1 then
DrawCardToBuf(chr(32), 3, i * 10) 'hidden with chr(32)
else
DrawCardToBuf(values[cRank[i]], cSuit[i], i * 10)
endif
next
pln "COMPUTER"
for r = 0 to 4
for c = 0 to 70
write buf[r][c]
next
pln
next
' Clear buffer again for you
for r = 0 to 4
for c = 0 to 70
buf[r][c] = " "
next
next
' You
for i = 0 to pCount - 1
DrawCardToBuf(values[pRank[i]], pSuit[i], i * 10)
next
pln;pln
pln "YOU"
for r = 0 to 4
for c = 0 to 70
write buf[r][c]
next
pln
next
endfunc
function PlayerTurn()
do
ShowHands(1)
pScore = CalcScore("p")
if pScore >= 21 then
system("cls")
break
endif
pln
pln "Instruction"
pln "(1) Hit "
pln "(2) Stand "
write "Choose number [1/2] : "; choice = rln()
select choice
case "1";Deal("p")
case "2";system("cls");break
endsel
system("cls")
loop
endfunc
function ComputerTurn()
do
ShowHands(0)
cScore = CalcScore("c")
if cScore < 17 then
Deal("c")
else
break
endif
loop
endfunc
function DetermineWinner()
pScore = CalcScore("p")
cScore = CalcScore("c")
pln;pln
if pScore > 21 then
pln "RESULT: YOU LOSE! (Bust)"
elseif cScore > 21 then
pln "RESULT: YOU WIN! (Computer busts)"
elseif pScore > cScore then
pln "RESULT: YOU WIN!"
elseif cScore > pScore then
pln "RESULT: COMPUTER WINS!"
else
pln "RESULT: PUSH! (Tie)"
endif
endfunc
function TitleScreen()
pln; pln
pln " _ _ _ _ _ "
pln "| | | | | | (_) | | "
pln "| |__ | | __ _ ___| | ___ __ _ ___| | __"
pln "| '_ \| |/ _` |/ __| |/ / |/ _` |/ __| |/ /"
pln "| |_) | | (_| | (__| <| | (_| | (__| < "
pln "|_.__/|_|\__,_|\___|_|\_\ |\__,_|\___|_|\_\"
pln " _/ | "
pln " |__/ "
pln
pln "Aim to get a hand total closer to 21"
pln "without exceeding 21"
pln "Player receive 2 face up cards,"
pln "while computer shows 1 card up and 1 down"
pln "-Hit = take more cards"
pln "-Stand = keep current hand"
pln chr(7) 'beep sound
system("pause")
endfunc
|
|
|
| val() command |
|
Posted by: johnno56 - 04-12-2026, 06:01 AM - Forum: NaaLaa 7 Questions
- Replies (2)
|
 |
I understand that the N7 val() command returns the value of a table element, but I am trying to convert a game that uses val(), in the traditional sense by returning the value of a string. eg: val("2") equals 2
Any ideas?
Thank you.
J
|
|
|
| Continue |
|
Posted by: johnno56 - 04-11-2026, 07:39 AM - Forum: NaaLaa 7 Questions
- Replies (6)
|
 |
I am trying to convert a game and came across the command "continue" in several places.
Within a "do" loop... if not active() then continue
and
Within a For "loop"... if pieces[p][i].finished then continue
Would I be correct in assuming that this is used similar to "break"?
|
|
|
| Card Suit Symbols |
|
Posted by: 1micha.elok - 04-11-2026, 07:27 AM - Forum: NaaLaa 7 Questions
- Replies (4)
|
 |
I’ve noticed an interesting quirk in my application: the card suit symbols (♥, ♦, ♣, ♠) render perfectly in the console, but they appear as empty spaces when running in windowed mode. Is there a way to correctly display these symbols using the chr() function for a windowed environment ?
Code: '--------------
' CONSOLE MODE
'--------------
randomize time()
values = ["A ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "10", "J ", "Q ", "K "]
v = values[rnd(0,12)]
s = rnd(3,6) 'ASCII code 3=heart, 4=diamond, 5=club, 6=spade
card(5,4,v,s)
pln chr(7) 'bell sound
wait 1000
'--------------
' WINDOW MODE
'--------------
set window "cards",300,300,false
do
wln "My card is the "+v+" of "+chr(s)
'ASCII code 3=heart, 4=diamond, 5=club, 6=spade
do;wait 1;until keydown(KEY_ESCAPE,true)
end
loop
'----------
' FUNCTION
'----------
function card(w,h,value,suit)
'top border
write chr(218) ; for i = 1 to w write chr(196) ; wln chr(191)
'vertical border
write chr(179)+value ; for i = 3 to w write chr(32) ; wln chr(179)
for i = 1 to h-2
write chr(179) ; for j = 1 to w write chr(32); wln chr(179)
next
write chr(179); for i = 1 to w-2 write chr(32) ; write chr(suit)+chr(32);wln chr(179)
'bottom border
write chr(192); for i = 1 to w write chr(196) ; wln chr(217)
endfunc
|
|
|
| Examples for list.n7 |
|
Posted by: 1micha.elok - 03-30-2026, 07:47 AM - Forum: NaaLaa 7 Questions
- Replies (3)
|
 |
Hi Marcus,
I'm trying to use the "list.n7" library, herewith the code :
Code: include "list.n7"
' 1. Create a List object
myList = List()
' 2. Add items using the Add function
for i = 0 to 5
myList.Add(i)
next
wln
' 3. Display initial list
wln "=== Initial List ==="
wln "Size:"+ myList.Size()
wln "Contents:"+ myList.ToString()
wln
' 4. Test Contains and Add
wln "=== Contains Test ==="
wln "Contains 6?"+ myList.Contains(6)
myList.Add(6)
wln "After Add(6), Contains 6?"+ myList.Contains(6)
wln "Contents:"+ myList.ToString()
wln
' 5. Sort Ascending
wln "=== Sort Ascending ==="
' Add some unsorted numbers first
myList.Add(2)
myList.Add(8)
myList.Add(1)
wln "Before sort:"+ myList.ToString()
myList.Sort(myList.ASCENDING)
wln "After Sort(ASCENDING):"+ myList.ToString()
wln
' 6. Sort Descending
wln "=== Sort Descending ==="
myList.Sort(myList.DESCENDING)
wln "After Sort(DESCENDING):"+ myList.ToString()
wln
' 7. Sorted (Returns copy, doesn't modify original)
wln "=== Sorted (Returns Copy) ==="
myList.Add(5)
myList.Add(3)
wln "Original before Sorted():"+ myList.ToString()
sortedCopy = myList.Sorted(myList.ASCENDING)
wln "Sorted copy (ascending):"+ sortedCopy.ToString()
wln "Original unchanged:"+ myList.ToString()
wln
' 8. SortByField (For lists containing tables/objects)
wln "=== SortByField Example ==="
people = List()
person1 = []
person1["name"] = "Charlie"
person1["age"] = 35
people.Add(person1)
person2 = []
person2["name"] = "Alice"
person2["age"] = 25
people.Add(person2)
person3 = []
person3["name"] = "Bob"
person3["age"] = 30
people.Add(person3)
wln "People before sort:"+ people.ToString()
people.SortByField("age", people.ASCENDING)
wln "People sorted by age (ascending):"+ people.ToString()
people.SortByField("name", people.DESCENDING)
wln "People sorted by name (descending):"+ people.ToString()
system("pause")
Unfortunately some outputs are unreadable 8. SortByField (For lists containing tables/objects).
Could you please advise me ? It's not urgent, you may reply when you have time later.
Thank you
|
|
|
| Game Structure Opinions |
|
Posted by: johnno56 - 03-29-2026, 07:01 PM - Forum: Everything else
- Replies (7)
|
 |
Over the years, I have noticed, two trending methods of game structure. Both methods are almost identical but the 'way' they are carried out are different... I will try to explain...
These are 'my' lables... 1. Sequential and 2. Modularised.
Sequential: Initialise and load assets; main loop consisting of; update stuff and draw stuff; screen refesh; end main loop. Followed by any exit reporting or play agian.
Modularised: Almost the same as sequential except that the update and draw stuff are divided into 'external functions' and are referenced within the main loop...
Given that processing speed has greatly improved of the decades, choosing either method may not be in issue when it comes to speed, I am curious as to everyone's opinion on the pros and cons of each system. (or if you use another system, please share)
This is all based on observation and curiosity and 'not' designed to be a 'can of worms'... lol
Discuss....
J
|
|
|
|