BrainClub

From Esolang
Jump to: navigation, search

BrainClub is a program language (invented by User:Zzo38) for compiling to client-brainfuck. The name is based on BrainSub (and a similar ideas) but "Cl" instead of "S" because it is "cl"ient-brainfuck.

There is a BrainClub compiler written in JavaScript and runs on XPC shell. Download at http://zzo38computer.org/brainclub/.


Examples

This program allows you to type something, and it puts spaces in between the letters.

."Make space" CR
0 BEGIN
  INPUT OUTPUT
  DUP 8 = IF
    DROP DROP
  THEN
  DUP 10 = IF
    DROP 0
  THEN
DUP WHILE REPEAT
."OK: "
DROP REWIND
ITERATE EMIT 32 OUTPUT NEXT
CR

This code is a hangman game:

hangman.bcl =

\---------------------------\
\ Hangman game in BrainClub \
\---------------------------\

\ Subroutines
: UPPERCASE DUP 96 > IF 32 - THEN ;
: YOUWIN 1EMPH ."You win!" BEGIN {,} AGAIN ;
: YOULOSE CR 1EMPH ."You lose!" BEGIN {,} AGAIN ;

\ Declare variables
( LIVES 1 )VAR
( LETTER 1 )VAR
( CORRECTLETTER 1 )VAR
( BLANKS 1 )VAR
( WORDLENGTH 1 )VAR
( DISPLAYWORD 36 )VAR
( WORD 36 )VAR

\ Initialize some variables
7 ( ! )LIVES

\ Read word to play game with
BEGIN
  ( 1+ )WORDLENGTH
  INPUT DUP
  ( @ )WORDLENGTH INDEX ( ! )WORD ?"." ( ! )DISPLAYWORD OUTDEX
  ?"!" =
UNTIL
( 1- @ )WORDLENGTH ( ! )BLANKS

\ Main game loop
BEGIN
  CLS 1EMPH ."  HANGMAN!  " 0EMPH CR
  ." <"
  ( ZERO )BLANKS
  0 BEGIN
    1+
    DUP INDEX ( OUTPUT @ )DISPLAYWORD OUTDEX
    ?"." = IF ( 1+ )BLANKS THEN
    DUP ( @ )WORDLENGTH =
  UNTIL DROP
  .">" CR
  ."Lives: " ( @ )LIVES ?"0" + EMIT CR
  ( @ )BLANKS 0= IF YOUWIN THEN
  ."Guess a letter: " INPUT UPPERCASE OUTPUT
  ( ZERO )CORRECTLETTER
  0 BEGIN
    1+
    DUP INDEX ( @ )WORD OUTDEX
    ( 2 )PICK = IF
      2DUP INDEX ( ! )DISPLAYWORD OUTDEX
      ( 1+ )CORRECTLETTER ( 1- )BLANKS
    THEN
    DUP ( @ )WORDLENGTH =
  UNTIL DROP DROP
  ( @ )CORRECTLETTER 0= IF
    ( 1- @ )LIVES 0= IF YOULOSE THEN
  THEN
AGAIN


External resources