*unified line ending.
This commit is contained in:
parent
390df0d992
commit
144d392851
14
.travis.yml
14
.travis.yml
@ -1,7 +1,7 @@
|
|||||||
language: c
|
language: c
|
||||||
|
|
||||||
compiler:
|
compiler:
|
||||||
- clang
|
- clang
|
||||||
- gcc
|
- gcc
|
||||||
|
|
||||||
script: make
|
script: make
|
||||||
|
34198
core/my_basic.c
34198
core/my_basic.c
File diff suppressed because it is too large
Load Diff
1304
core/my_basic.h
1304
core/my_basic.h
File diff suppressed because it is too large
Load Diff
@ -1,77 +1,77 @@
|
|||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
#define APSTUDIO_READONLY_SYMBOLS
|
#define APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
|
||||||
#undef APSTUDIO_READONLY_SYMBOLS
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
|
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
|
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
|
||||||
# pragma code_page(936)
|
# pragma code_page(936)
|
||||||
# endif //_WIN32
|
# endif //_WIN32
|
||||||
|
|
||||||
# ifdef APSTUDIO_INVOKED
|
# ifdef APSTUDIO_INVOKED
|
||||||
|
|
||||||
1 TEXTINCLUDE
|
1 TEXTINCLUDE
|
||||||
BEGIN
|
BEGIN
|
||||||
"resource.h\0"
|
"resource.h\0"
|
||||||
END
|
END
|
||||||
|
|
||||||
2 TEXTINCLUDE
|
2 TEXTINCLUDE
|
||||||
BEGIN
|
BEGIN
|
||||||
"#include ""windows.h""\r\n"
|
"#include ""windows.h""\r\n"
|
||||||
"\0"
|
"\0"
|
||||||
END
|
END
|
||||||
|
|
||||||
3 TEXTINCLUDE
|
3 TEXTINCLUDE
|
||||||
BEGIN
|
BEGIN
|
||||||
"\r\n"
|
"\r\n"
|
||||||
"\0"
|
"\0"
|
||||||
END
|
END
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
IDI_ICON_MAIN ICON "icon.ico"
|
IDI_ICON_MAIN ICON "icon.ico"
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,2,0,0
|
FILEVERSION 1,2,0,0
|
||||||
PRODUCTVERSION 1,2,0,0
|
PRODUCTVERSION 1,2,0,0
|
||||||
FILEFLAGSMASK 0x17L
|
FILEFLAGSMASK 0x17L
|
||||||
# ifdef _DEBUG
|
# ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
# else
|
# else
|
||||||
FILEFLAGS 0x0L
|
FILEFLAGS 0x0L
|
||||||
# endif
|
# endif
|
||||||
FILEOS 0x4L
|
FILEOS 0x4L
|
||||||
FILETYPE 0x1L
|
FILETYPE 0x1L
|
||||||
FILESUBTYPE 0x0L
|
FILESUBTYPE 0x0L
|
||||||
BEGIN
|
BEGIN
|
||||||
BLOCK "StringFileInfo"
|
BLOCK "StringFileInfo"
|
||||||
BEGIN
|
BEGIN
|
||||||
BLOCK "080404b0"
|
BLOCK "080404b0"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "Comments", "For more information, see https://github.com/paladin-t/my_basic/."
|
VALUE "Comments", "For more information, see https://github.com/paladin-t/my_basic/."
|
||||||
VALUE "CompanyName", "Wang Renxin"
|
VALUE "CompanyName", "Wang Renxin"
|
||||||
VALUE "FileDescription", "MY-BASIC Interpreter for Windows"
|
VALUE "FileDescription", "MY-BASIC Interpreter for Windows"
|
||||||
VALUE "FileVersion", "1, 2, 0, 0"
|
VALUE "FileVersion", "1, 2, 0, 0"
|
||||||
VALUE "InternalName", "my_basic"
|
VALUE "InternalName", "my_basic"
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2011 - 2016 Wang Renxin"
|
VALUE "LegalCopyright", "Copyright (C) 2011 - 2016 Wang Renxin"
|
||||||
VALUE "LegalTrademarks", "MY-BASIC"
|
VALUE "LegalTrademarks", "MY-BASIC"
|
||||||
VALUE "OriginalFilename", "my_basic.exe"
|
VALUE "OriginalFilename", "my_basic.exe"
|
||||||
VALUE "ProductName", "MY-BASIC"
|
VALUE "ProductName", "MY-BASIC"
|
||||||
VALUE "ProductVersion", "1, 2, 0, 0"
|
VALUE "ProductVersion", "1, 2, 0, 0"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "Translation", 0x804, 1200
|
VALUE "Translation", 0x804, 1200
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef APSTUDIO_INVOKED
|
#ifndef APSTUDIO_INVOKED
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,40 +1,40 @@
|
|||||||
## Samples of MY-BASIC
|
## Samples of MY-BASIC
|
||||||
|
|
||||||
**Copyright (C) 2011 - 2016 Wang Renxin. All rights reserved.**
|
**Copyright (C) 2011 - 2016 Wang Renxin. All rights reserved.**
|
||||||
|
|
||||||
This folder contains severial sample code of MY-BASIC.
|
This folder contains severial sample code of MY-BASIC.
|
||||||
|
|
||||||
### Contents
|
### Contents
|
||||||
|
|
||||||
**Fundamental**
|
**Fundamental**
|
||||||
|
|
||||||
Including loop, condition, and other fundamental statements.
|
Including loop, condition, and other fundamental statements.
|
||||||
|
|
||||||
sample01.bas
|
sample01.bas
|
||||||
sample02.bas
|
sample02.bas
|
||||||
sample03.bas
|
sample03.bas
|
||||||
sample04.bas
|
sample04.bas
|
||||||
|
|
||||||
**Sub routine**
|
**Sub routine**
|
||||||
|
|
||||||
sample05.bas
|
sample05.bas
|
||||||
|
|
||||||
**Prototype based class**
|
**Prototype based class**
|
||||||
|
|
||||||
sample06.bas
|
sample06.bas
|
||||||
|
|
||||||
**A Brainfuck interpreter in MY-BASIC**
|
**A Brainfuck interpreter in MY-BASIC**
|
||||||
|
|
||||||
sample07.bas
|
sample07.bas
|
||||||
|
|
||||||
**A comprehensive simple game named YARD (Yet Another RPG Dungeon)**
|
**A comprehensive simple game named YARD (Yet Another RPG Dungeon)**
|
||||||
|
|
||||||
yard/entity.bas
|
yard/entity.bas
|
||||||
yard/goal.bas
|
yard/goal.bas
|
||||||
yard/level.bas
|
yard/level.bas
|
||||||
yard/map.bas
|
yard/map.bas
|
||||||
yard/monster.bas
|
yard/monster.bas
|
||||||
yard/npc.bas
|
yard/npc.bas
|
||||||
yard/player.bas
|
yard/player.bas
|
||||||
yard/start.bas
|
yard/start.bas
|
||||||
yard/utils.bas
|
yard/utils.bas
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
' This script is an example of MY-BASIC
|
' This script is an example of MY-BASIC
|
||||||
' Copyright (c) 2011 - 2016 Wang Renxin. All rights reserved.
|
' Copyright (c) 2011 - 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information, see https://github.com/paladin-t/my_basic/
|
' For more information, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
class animal
|
class animal
|
||||||
def speak(a)
|
def speak(a)
|
||||||
print "Default" + a;
|
print "Default" + a;
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
|
||||||
class cat(animal)
|
class cat(animal)
|
||||||
def speak(a)
|
def speak(a)
|
||||||
print "Meow" + a;
|
print "Meow" + a;
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
|
||||||
class dog(animal)
|
class dog(animal)
|
||||||
def speak(a)
|
def speak(a)
|
||||||
print "Woof" + a;
|
print "Woof" + a;
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
|
||||||
c = new(cat)
|
c = new(cat)
|
||||||
d = new(dog)
|
d = new(dog)
|
||||||
|
|
||||||
c.speak("!")
|
c.speak("!")
|
||||||
d.speak("!")
|
d.speak("!")
|
||||||
|
@ -1,100 +1,100 @@
|
|||||||
' This script is an example of MY-BASIC
|
' This script is an example of MY-BASIC
|
||||||
' Copyright (c) 2011 - 2016 Wang Renxin. All rights reserved.
|
' Copyright (c) 2011 - 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information, see https://github.com/paladin-t/my_basic/
|
' For more information, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
def reserve(m, n)
|
def reserve(m, n)
|
||||||
for j = len(m) to n + 2
|
for j = len(m) to n + 2
|
||||||
push(m, 0)
|
push(m, 0)
|
||||||
next
|
next
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def forward(cmd, i)
|
def forward(cmd, i)
|
||||||
l = len(cmd)
|
l = len(cmd)
|
||||||
k = 0
|
k = 0
|
||||||
while i < l
|
while i < l
|
||||||
h = mid(cmd, i, 1)
|
h = mid(cmd, i, 1)
|
||||||
if h = "[" then
|
if h = "[" then
|
||||||
k = k + 1
|
k = k + 1
|
||||||
elseif h = "]" then
|
elseif h = "]" then
|
||||||
k = k - 1
|
k = k - 1
|
||||||
endif
|
endif
|
||||||
if h = "]" and k = 0 then
|
if h = "]" and k = 0 then
|
||||||
return i
|
return i
|
||||||
endif
|
endif
|
||||||
i = i + 1
|
i = i + 1
|
||||||
wend
|
wend
|
||||||
|
|
||||||
return i
|
return i
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def backward(cmd, i)
|
def backward(cmd, i)
|
||||||
k = 0
|
k = 0
|
||||||
while i > 0
|
while i > 0
|
||||||
h = mid(cmd, i, 1)
|
h = mid(cmd, i, 1)
|
||||||
if h = "]" then
|
if h = "]" then
|
||||||
k = k + 1
|
k = k + 1
|
||||||
elseif h = "[" then
|
elseif h = "[" then
|
||||||
k = k - 1
|
k = k - 1
|
||||||
endif
|
endif
|
||||||
if h = "[" and k = 0 then
|
if h = "[" and k = 0 then
|
||||||
return i
|
return i
|
||||||
endif
|
endif
|
||||||
i = i - 1
|
i = i - 1
|
||||||
wend
|
wend
|
||||||
|
|
||||||
return i
|
return i
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def brainfuck(cmd)
|
def brainfuck(cmd)
|
||||||
m = list()
|
m = list()
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
cursor = 0
|
cursor = 0
|
||||||
|
|
||||||
l = len(cmd)
|
l = len(cmd)
|
||||||
while i < l
|
while i < l
|
||||||
c = mid(cmd, i, 1)
|
c = mid(cmd, i, 1)
|
||||||
if c = ">" then
|
if c = ">" then
|
||||||
cursor = cursor + 1
|
cursor = cursor + 1
|
||||||
elseif c = "<" then
|
elseif c = "<" then
|
||||||
cursor = cursor - 1
|
cursor = cursor - 1
|
||||||
elseif c = "+" then
|
elseif c = "+" then
|
||||||
reserve(m, cursor)
|
reserve(m, cursor)
|
||||||
b = m(cursor)
|
b = m(cursor)
|
||||||
m(cursor) = b + 1
|
m(cursor) = b + 1
|
||||||
elseif c = "-" then
|
elseif c = "-" then
|
||||||
reserve(m, cursor)
|
reserve(m, cursor)
|
||||||
b = m(cursor)
|
b = m(cursor)
|
||||||
m(cursor) = b - 1
|
m(cursor) = b - 1
|
||||||
elseif c = "." then
|
elseif c = "." then
|
||||||
reserve(m, cursor)
|
reserve(m, cursor)
|
||||||
print chr(m(cursor))
|
print chr(m(cursor))
|
||||||
elseif c = "," then
|
elseif c = "," then
|
||||||
reserve(m, cursor)
|
reserve(m, cursor)
|
||||||
input ch$
|
input ch$
|
||||||
m(cursor) = asc(ch$)
|
m(cursor) = asc(ch$)
|
||||||
elseif c = "[" then
|
elseif c = "[" then
|
||||||
reserve(m, cursor)
|
reserve(m, cursor)
|
||||||
b = m(cursor)
|
b = m(cursor)
|
||||||
if b = 0 then
|
if b = 0 then
|
||||||
i = forward(cmd, i)
|
i = forward(cmd, i)
|
||||||
endif
|
endif
|
||||||
elseif c = "]" then
|
elseif c = "]" then
|
||||||
reserve(m, cursor)
|
reserve(m, cursor)
|
||||||
b = m(cursor)
|
b = m(cursor)
|
||||||
if b <> 0 then
|
if b <> 0 then
|
||||||
i = backward(cmd, i)
|
i = backward(cmd, i)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
i = i + 1
|
i = i + 1
|
||||||
wend
|
wend
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
' This is a brainfuck interpreter written with MY-BASIC
|
' This is a brainfuck interpreter written with MY-BASIC
|
||||||
input "Input: ", cmd$
|
input "Input: ", cmd$
|
||||||
' Use a sample code?
|
' Use a sample code?
|
||||||
if cmd$ = "hello" then
|
if cmd$ = "hello" then
|
||||||
cmd$ = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
|
cmd$ = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
|
||||||
endif
|
endif
|
||||||
|
|
||||||
brainfuck(cmd$)
|
brainfuck(cmd$)
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
## YARD (Yet Another RPG Dungeon)
|
## YARD (Yet Another RPG Dungeon)
|
||||||
|
|
||||||
**Copyright (C) 2016 Wang Renxin. All rights reserved.**
|
**Copyright (C) 2016 Wang Renxin. All rights reserved.**
|
||||||
|
|
||||||
"Yet Another RPG Dungeon" is a text based game. It's a simple comprehensive example and a tutorial which demonstrates lots of concepts of MY-BASIC.
|
"Yet Another RPG Dungeon" is a text based game. It's a simple comprehensive example and a tutorial which demonstrates lots of concepts of MY-BASIC.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
**Windows**
|
**Windows**
|
||||||
|
|
||||||
my_basic start.bas
|
my_basic start.bas
|
||||||
|
|
||||||
**OS X**
|
**OS X**
|
||||||
|
|
||||||
my_basic_mac start.bas
|
my_basic_mac start.bas
|
||||||
|
|
||||||
**Others**
|
**Others**
|
||||||
|
|
||||||
my_basic_bin start.bas
|
my_basic_bin start.bas
|
||||||
|
|
||||||
**Note**
|
**Note**
|
||||||
|
|
||||||
It requires an importing directories information if the working directory of your interpreter is `my_basic/output/`:
|
It requires an importing directories information if the working directory of your interpreter is `my_basic/output/`:
|
||||||
|
|
||||||
my_basic -f ../sample/yard/ ../sample/yard/start.bas
|
my_basic -f ../sample/yard/ ../sample/yard/start.bas
|
||||||
|
@ -1,47 +1,47 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
class entity
|
class entity
|
||||||
var name = ""
|
var name = ""
|
||||||
|
|
||||||
var alive = true
|
var alive = true
|
||||||
|
|
||||||
var hp = 0
|
var hp = 0
|
||||||
var atk = 0
|
var atk = 0
|
||||||
var defence = 0
|
var defence = 0
|
||||||
|
|
||||||
var dead_handler = nil
|
var dead_handler = nil
|
||||||
|
|
||||||
def tostring()
|
def tostring()
|
||||||
return "Entity [" + name + "]"
|
return "Entity [" + name + "]"
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def init(_hp, _atk, _def)
|
def init(_hp, _atk, _def)
|
||||||
hp = _hp
|
hp = _hp
|
||||||
atk = _atk
|
atk = _atk
|
||||||
defence = _def
|
defence = _def
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def kill()
|
def kill()
|
||||||
if dead_handler <> nil then
|
if dead_handler <> nil then
|
||||||
dead_handler(me)
|
dead_handler(me)
|
||||||
endif
|
endif
|
||||||
alive = false
|
alive = false
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def hurt_by(e)
|
def hurt_by(e)
|
||||||
p = e.atk / defence
|
p = e.atk / defence
|
||||||
if p <= 0 then
|
if p <= 0 then
|
||||||
p = 1
|
p = 1
|
||||||
endif
|
endif
|
||||||
hp = hp - p
|
hp = hp - p
|
||||||
if hp < 0 then
|
if hp < 0 then
|
||||||
hp = 0
|
hp = 0
|
||||||
endif
|
endif
|
||||||
if hp = 0 then
|
if hp = 0 then
|
||||||
kill()
|
kill()
|
||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
import "entity.bas"
|
import "entity.bas"
|
||||||
|
|
||||||
class goal(entity)
|
class goal(entity)
|
||||||
var take_handler = nil
|
var take_handler = nil
|
||||||
|
|
||||||
def tostring()
|
def tostring()
|
||||||
return "Goal [" + name + "]"
|
return "Goal [" + name + "]"
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def take(e)
|
def take(e)
|
||||||
if take_handler <> nil then
|
if take_handler <> nil then
|
||||||
take_handler(me)
|
take_handler(me)
|
||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
@ -1,262 +1,262 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
import "goal.bas"
|
import "goal.bas"
|
||||||
import "map.bas"
|
import "map.bas"
|
||||||
import "monster.bas"
|
import "monster.bas"
|
||||||
import "npc.bas"
|
import "npc.bas"
|
||||||
|
|
||||||
class game_status
|
class game_status
|
||||||
var invalid = 0
|
var invalid = 0
|
||||||
var playing = 1
|
var playing = 1
|
||||||
var win = 2
|
var win = 2
|
||||||
var lose = 3
|
var lose = 3
|
||||||
endclass
|
endclass
|
||||||
|
|
||||||
class level
|
class level
|
||||||
var status = game_status.invalid
|
var status = game_status.invalid
|
||||||
var roads = new(map)
|
var roads = new(map)
|
||||||
var role = nil
|
var role = nil
|
||||||
|
|
||||||
def set_node(x, y, ...)
|
def set_node(x, y, ...)
|
||||||
n = new(map_node)
|
n = new(map_node)
|
||||||
roads.set_node(x, y, n)
|
roads.set_node(x, y, n)
|
||||||
n.set_valid_dirs(...)
|
n.set_valid_dirs(...)
|
||||||
|
|
||||||
return n
|
return n
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def get_node(x, y)
|
def get_node(x, y)
|
||||||
return roads.get_node(x, y)
|
return roads.get_node(x, y)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def create()
|
def create()
|
||||||
roads.set_size(3, 3)
|
roads.set_size(3, 3)
|
||||||
|
|
||||||
n = set_node(0, 0, dirs.right_dir)
|
n = set_node(0, 0, dirs.right_dir)
|
||||||
|
|
||||||
n = set_node(1, 0, dirs.left_dir, dirs.right_dir, dirs.up_dir)
|
n = set_node(1, 0, dirs.left_dir, dirs.right_dir, dirs.up_dir)
|
||||||
|
|
||||||
n = set_node(2, 0, dirs.left_dir, dirs.up_dir)
|
n = set_node(2, 0, dirs.left_dir, dirs.up_dir)
|
||||||
|
|
||||||
m = new(monster)
|
m = new(monster)
|
||||||
m.name = "Skeleton"
|
m.name = "Skeleton"
|
||||||
m.init(7, 1, 1)
|
m.init(7, 1, 1)
|
||||||
m.dead_handler = lambda (_)
|
m.dead_handler = lambda (_)
|
||||||
(
|
(
|
||||||
print "- " + _.name + " dead";
|
print "- " + _.name + " dead";
|
||||||
)
|
)
|
||||||
n.add_entity(m)
|
n.add_entity(m)
|
||||||
|
|
||||||
n = set_node(0, 1, dirs.right_dir)
|
n = set_node(0, 1, dirs.right_dir)
|
||||||
|
|
||||||
n = set_node(1, 1, dirs.left_dir, dirs.up_dir, dirs.down_dir)
|
n = set_node(1, 1, dirs.left_dir, dirs.up_dir, dirs.down_dir)
|
||||||
|
|
||||||
m = new(monster)
|
m = new(monster)
|
||||||
m.name = "Slime"
|
m.name = "Slime"
|
||||||
m.init(5, 1, 1)
|
m.init(5, 1, 1)
|
||||||
m.dead_handler = lambda (_)
|
m.dead_handler = lambda (_)
|
||||||
(
|
(
|
||||||
print "- " + _.name + " dead";
|
print "- " + _.name + " dead";
|
||||||
)
|
)
|
||||||
n.add_entity(m)
|
n.add_entity(m)
|
||||||
|
|
||||||
n = set_node(2, 1, dirs.up_dir, dirs.down_dir)
|
n = set_node(2, 1, dirs.up_dir, dirs.down_dir)
|
||||||
|
|
||||||
n = set_node(0, 2, dirs.right_dir)
|
n = set_node(0, 2, dirs.right_dir)
|
||||||
|
|
||||||
g = new(goal)
|
g = new(goal)
|
||||||
g.name = "Goal"
|
g.name = "Goal"
|
||||||
n.add_entity(g)
|
n.add_entity(g)
|
||||||
|
|
||||||
n = set_node(1, 2, dirs.left_dir, dirs.right_dir, dirs.down_dir)
|
n = set_node(1, 2, dirs.left_dir, dirs.right_dir, dirs.down_dir)
|
||||||
|
|
||||||
m = new(monster)
|
m = new(monster)
|
||||||
m.name = "Dragon"
|
m.name = "Dragon"
|
||||||
m.init(10, 5, 1)
|
m.init(10, 5, 1)
|
||||||
m.dead_handler = lambda (_)
|
m.dead_handler = lambda (_)
|
||||||
(
|
(
|
||||||
print "- " + _.name + " dead";
|
print "- " + _.name + " dead";
|
||||||
)
|
)
|
||||||
n.add_entity(m)
|
n.add_entity(m)
|
||||||
|
|
||||||
n = set_node(2, 2, dirs.left_dir, dirs.down_dir)
|
n = set_node(2, 2, dirs.left_dir, dirs.down_dir)
|
||||||
|
|
||||||
c = new(npc)
|
c = new(npc)
|
||||||
c.name = "Therapist"
|
c.name = "Therapist"
|
||||||
c.talk_handler = lambda (_)
|
c.talk_handler = lambda (_)
|
||||||
(
|
(
|
||||||
print "- " + _.name + ": give you 23 HP";
|
print "- " + _.name + ": give you 23 HP";
|
||||||
_.alive = false
|
_.alive = false
|
||||||
role.hp = role.hp + 23
|
role.hp = role.hp + 23
|
||||||
)
|
)
|
||||||
n.add_entity(c)
|
n.add_entity(c)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def start(r)
|
def start(r)
|
||||||
status = game_status.playing
|
status = game_status.playing
|
||||||
role = r
|
role = r
|
||||||
role.pos.x = 0
|
role.pos.x = 0
|
||||||
role.pos.y = 0
|
role.pos.y = 0
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def format()
|
def format()
|
||||||
if status = game_status.win then
|
if status = game_status.win then
|
||||||
print "You Win";
|
print "You Win";
|
||||||
elseif status = game_status.lose then
|
elseif status = game_status.lose then
|
||||||
print "Game Over";
|
print "Game Over";
|
||||||
|
|
||||||
return
|
return
|
||||||
elseif status = game_status.playing then
|
elseif status = game_status.playing then
|
||||||
print "<" + str(role.pos.x) + ", " + str(role.pos.y) + ">";
|
print "<" + str(role.pos.x) + ", " + str(role.pos.y) + ">";
|
||||||
|
|
||||||
n = roads.get_node(role.pos.x, role.pos.y)
|
n = roads.get_node(role.pos.x, role.pos.y)
|
||||||
|
|
||||||
contains_goal = false
|
contains_goal = false
|
||||||
gl = n.get_entities(goal)
|
gl = n.get_entities(goal)
|
||||||
it = iterator(gl)
|
it = iterator(gl)
|
||||||
if move_next(it) then
|
if move_next(it) then
|
||||||
contains_goal = true
|
contains_goal = true
|
||||||
ent = get(it)
|
ent = get(it)
|
||||||
print " ", ent;
|
print " ", ent;
|
||||||
it = nil
|
it = nil
|
||||||
endif
|
endif
|
||||||
|
|
||||||
contains_npc = false
|
contains_npc = false
|
||||||
np = n.get_entities(npc)
|
np = n.get_entities(npc)
|
||||||
it = iterator(np)
|
it = iterator(np)
|
||||||
if move_next(it) then
|
if move_next(it) then
|
||||||
contains_npc = true
|
contains_npc = true
|
||||||
ent = get(it)
|
ent = get(it)
|
||||||
print " ", ent;
|
print " ", ent;
|
||||||
it = nil
|
it = nil
|
||||||
endif
|
endif
|
||||||
|
|
||||||
contains_monster = false
|
contains_monster = false
|
||||||
ms = n.get_entities(monster)
|
ms = n.get_entities(monster)
|
||||||
it = iterator(ms)
|
it = iterator(ms)
|
||||||
if move_next(it) then
|
if move_next(it) then
|
||||||
contains_monster = true
|
contains_monster = true
|
||||||
ent = get(it)
|
ent = get(it)
|
||||||
print " ", ent;
|
print " ", ent;
|
||||||
it = nil
|
it = nil
|
||||||
endif
|
endif
|
||||||
|
|
||||||
print "[Operations]";
|
print "[Operations]";
|
||||||
|
|
||||||
if contains_goal then
|
if contains_goal then
|
||||||
print " G: Accomplish goal";
|
print " G: Accomplish goal";
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if contains_npc then
|
if contains_npc then
|
||||||
print " T: Talk to " + ent.name;
|
print " T: Talk to " + ent.name;
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if contains_monster then
|
if contains_monster then
|
||||||
print " A: Attack " + ent.name;
|
print " A: Attack " + ent.name;
|
||||||
else
|
else
|
||||||
if bit_and(n.valid_dirs, dirs.left_dir) then
|
if bit_and(n.valid_dirs, dirs.left_dir) then
|
||||||
print " W: Go west";
|
print " W: Go west";
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if bit_and(n.valid_dirs, dirs.right_dir) then
|
if bit_and(n.valid_dirs, dirs.right_dir) then
|
||||||
print " E: Go east";
|
print " E: Go east";
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if bit_and(n.valid_dirs, dirs.up_dir) then
|
if bit_and(n.valid_dirs, dirs.up_dir) then
|
||||||
print " N: Go north";
|
print " N: Go north";
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if bit_and(n.valid_dirs, dirs.down_dir) then
|
if bit_and(n.valid_dirs, dirs.down_dir) then
|
||||||
print " S: Go south";
|
print " S: Go south";
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
print " Q: Quit game";
|
print " Q: Quit game";
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def update(i)
|
def update(i)
|
||||||
if i = "" then
|
if i = "" then
|
||||||
return false
|
return false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ipt = to_lower_case(i)
|
ipt = to_lower_case(i)
|
||||||
|
|
||||||
if ipt = "q" then print "Bye."; : end
|
if ipt = "q" then print "Bye."; : end
|
||||||
|
|
||||||
if status <> game_status.playing then
|
if status <> game_status.playing then
|
||||||
return false
|
return false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
n = roads.get_node(role.pos.x, role.pos.y)
|
n = roads.get_node(role.pos.x, role.pos.y)
|
||||||
|
|
||||||
gl = n.get_entities(goal)
|
gl = n.get_entities(goal)
|
||||||
it = iterator(gl)
|
it = iterator(gl)
|
||||||
if ipt = "g" and move_next(it) then
|
if ipt = "g" and move_next(it) then
|
||||||
ent = get(it)
|
ent = get(it)
|
||||||
it = nil
|
it = nil
|
||||||
status = game_status.win
|
status = game_status.win
|
||||||
|
|
||||||
return true
|
return true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
np = n.get_entities(npc)
|
np = n.get_entities(npc)
|
||||||
it = iterator(np)
|
it = iterator(np)
|
||||||
if ipt = "t" and move_next(it) then
|
if ipt = "t" and move_next(it) then
|
||||||
ent = get(it)
|
ent = get(it)
|
||||||
it = nil
|
it = nil
|
||||||
ent.talk(role)
|
ent.talk(role)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
contains_monster = false
|
contains_monster = false
|
||||||
ms = n.get_entities(monster)
|
ms = n.get_entities(monster)
|
||||||
it = iterator(ms)
|
it = iterator(ms)
|
||||||
if move_next(it) then
|
if move_next(it) then
|
||||||
contains_monster = true
|
contains_monster = true
|
||||||
|
|
||||||
if ipt = "a" then
|
if ipt = "a" then
|
||||||
ent = get(it)
|
ent = get(it)
|
||||||
it = nil
|
it = nil
|
||||||
ent.hurt_by(role)
|
ent.hurt_by(role)
|
||||||
role.hurt_by(ent)
|
role.hurt_by(ent)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if not contains_monster then
|
if not contains_monster then
|
||||||
if ipt = "w" and bit_and(n.valid_dirs, dirs.left_dir) then
|
if ipt = "w" and bit_and(n.valid_dirs, dirs.left_dir) then
|
||||||
role.pos.x = role.pos.x - 1
|
role.pos.x = role.pos.x - 1
|
||||||
|
|
||||||
return true
|
return true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ipt = "e" and bit_and(n.valid_dirs, dirs.right_dir) then
|
if ipt = "e" and bit_and(n.valid_dirs, dirs.right_dir) then
|
||||||
role.pos.x = role.pos.x + 1
|
role.pos.x = role.pos.x + 1
|
||||||
|
|
||||||
return true
|
return true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ipt = "n" and bit_and(n.valid_dirs, dirs.up_dir) then
|
if ipt = "n" and bit_and(n.valid_dirs, dirs.up_dir) then
|
||||||
role.pos.y = role.pos.y + 1
|
role.pos.y = role.pos.y + 1
|
||||||
|
|
||||||
return true
|
return true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ipt = "s" and bit_and(n.valid_dirs, dirs.down_dir) then
|
if ipt = "s" and bit_and(n.valid_dirs, dirs.down_dir) then
|
||||||
role.pos.y = role.pos.y - 1
|
role.pos.y = role.pos.y - 1
|
||||||
|
|
||||||
return true
|
return true
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
print "Invalid input.";
|
print "Invalid input.";
|
||||||
|
|
||||||
return false
|
return false
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
@ -1,95 +1,95 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
import "utils.bas"
|
import "utils.bas"
|
||||||
|
|
||||||
class dirs
|
class dirs
|
||||||
var none_dir = 0
|
var none_dir = 0
|
||||||
var left_dir = 1
|
var left_dir = 1
|
||||||
var right_dir = 2
|
var right_dir = 2
|
||||||
var up_dir = 4
|
var up_dir = 4
|
||||||
var down_dir = 8
|
var down_dir = 8
|
||||||
endclass
|
endclass
|
||||||
|
|
||||||
class map_node
|
class map_node
|
||||||
var pos = new(point)
|
var pos = new(point)
|
||||||
var valid_dirs = dirs.none_dir
|
var valid_dirs = dirs.none_dir
|
||||||
var entities = list()
|
var entities = list()
|
||||||
|
|
||||||
def tostring()
|
def tostring()
|
||||||
s = pos.tostring()
|
s = pos.tostring()
|
||||||
return "Map Node " + s
|
return "Map Node " + s
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def set_valid_dirs(...)
|
def set_valid_dirs(...)
|
||||||
dir = 0
|
dir = 0
|
||||||
while len(...)
|
while len(...)
|
||||||
dir = bit_or(dir, ...)
|
dir = bit_or(dir, ...)
|
||||||
wend
|
wend
|
||||||
valid_dirs = dir
|
valid_dirs = dir
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def add_entity(ent)
|
def add_entity(ent)
|
||||||
if exist(entities, ent) then
|
if exist(entities, ent) then
|
||||||
log.w("Already added " + ent.name)
|
log.w("Already added " + ent.name)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
push(entities, ent)
|
push(entities, ent)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def get_entities(y)
|
def get_entities(y)
|
||||||
ret = list()
|
ret = list()
|
||||||
it = iterator(entities)
|
it = iterator(entities)
|
||||||
while move_next(it)
|
while move_next(it)
|
||||||
ent = get(it)
|
ent = get(it)
|
||||||
if ent is y and ent.alive then
|
if ent is y and ent.alive then
|
||||||
push(ret, ent);
|
push(ret, ent);
|
||||||
endif
|
endif
|
||||||
wend
|
wend
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
|
||||||
class map
|
class map
|
||||||
var width = 0
|
var width = 0
|
||||||
var height = 0
|
var height = 0
|
||||||
|
|
||||||
var nodes = dict()
|
var nodes = dict()
|
||||||
|
|
||||||
def tostring()
|
def tostring()
|
||||||
return "Map"
|
return "Map"
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def hash_pos(x, y)
|
def hash_pos(x, y)
|
||||||
return x + y * width
|
return x + y * width
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def set_size(w, h)
|
def set_size(w, h)
|
||||||
width = w
|
width = w
|
||||||
height = h
|
height = h
|
||||||
|
|
||||||
clear(nodes)
|
clear(nodes)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def set_node(x, y, n)
|
def set_node(x, y, n)
|
||||||
h = hash_pos(x, y)
|
h = hash_pos(x, y)
|
||||||
n.pos.x = x
|
n.pos.x = x
|
||||||
n.pos.y = y
|
n.pos.y = y
|
||||||
nodes(h) = n
|
nodes(h) = n
|
||||||
|
|
||||||
return n
|
return n
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def get_node(x, y)
|
def get_node(x, y)
|
||||||
h = hash_pos(x, y)
|
h = hash_pos(x, y)
|
||||||
|
|
||||||
return nodes(h)
|
return nodes(h)
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
import "entity.bas"
|
import "entity.bas"
|
||||||
|
|
||||||
class monster(entity)
|
class monster(entity)
|
||||||
def tostring()
|
def tostring()
|
||||||
return "Monster [" + name + "]"
|
return "Monster [" + name + "]"
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
import "entity.bas"
|
import "entity.bas"
|
||||||
|
|
||||||
class npc(entity)
|
class npc(entity)
|
||||||
var talk_handler = nil
|
var talk_handler = nil
|
||||||
|
|
||||||
def tostring()
|
def tostring()
|
||||||
return "NPC [" + name + "]"
|
return "NPC [" + name + "]"
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def talk(e)
|
def talk(e)
|
||||||
if talk_handler <> nil then
|
if talk_handler <> nil then
|
||||||
talk_handler(me)
|
talk_handler(me)
|
||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
import "entity.bas"
|
import "entity.bas"
|
||||||
import "utils.bas"
|
import "utils.bas"
|
||||||
|
|
||||||
class player(entity)
|
class player(entity)
|
||||||
var pos = new(point)
|
var pos = new(point)
|
||||||
|
|
||||||
def tostring()
|
def tostring()
|
||||||
return "Player [" + name + "]"
|
return "Player [" + name + "]"
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
import "level.bas"
|
import "level.bas"
|
||||||
import "player.bas"
|
import "player.bas"
|
||||||
|
|
||||||
cls()
|
cls()
|
||||||
print "Welcome to Yet Another RPG Dungeon!";
|
print "Welcome to Yet Another RPG Dungeon!";
|
||||||
|
|
||||||
level.create()
|
level.create()
|
||||||
_role = new(player)
|
_role = new(player)
|
||||||
_role.init(10, 2, 1)
|
_role.init(10, 2, 1)
|
||||||
_role.dead_handler = lambda (_)
|
_role.dead_handler = lambda (_)
|
||||||
(
|
(
|
||||||
print "- You are dead";
|
print "- You are dead";
|
||||||
level.status = game_status.lose
|
level.status = game_status.lose
|
||||||
)
|
)
|
||||||
level.start(_role)
|
level.start(_role)
|
||||||
_turn = 1
|
_turn = 1
|
||||||
while _role.alive
|
while _role.alive
|
||||||
print "[---- Turn ", _turn, ", HP ", _role.hp, ", ATK ", _role.atk, " ----]";
|
print "[---- Turn ", _turn, ", HP ", _role.hp, ", ATK ", _role.atk, " ----]";
|
||||||
level.format()
|
level.format()
|
||||||
input _i$
|
input _i$
|
||||||
cls()
|
cls()
|
||||||
if level.update(_i$) then
|
if level.update(_i$) then
|
||||||
_turn = _turn + 1
|
_turn = _turn + 1
|
||||||
endif
|
endif
|
||||||
wend
|
wend
|
||||||
level.format()
|
level.format()
|
||||||
|
@ -1,92 +1,92 @@
|
|||||||
' Yet Another RPG Dungeon is a text based game.
|
' Yet Another RPG Dungeon is a text based game.
|
||||||
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
' It's aimed to be a comprehensive example and or a tutorial of MY-BASIC.
|
||||||
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
' Copyright (C) 2016 Wang Renxin. All rights reserved.
|
||||||
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
' For more information about MY-BASIC, see https://github.com/paladin-t/my_basic/
|
||||||
|
|
||||||
def cls()
|
def cls()
|
||||||
if os() = "WIN" then
|
if os() = "WIN" then
|
||||||
sys("cls")
|
sys("cls")
|
||||||
else
|
else
|
||||||
sys("clear")
|
sys("clear")
|
||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def to_lower_case(c)
|
def to_lower_case(c)
|
||||||
_asc = asc(c)
|
_asc = asc(c)
|
||||||
if _asc >= asc("A") and _asc <= asc("Z") then
|
if _asc >= asc("A") and _asc <= asc("Z") then
|
||||||
_asc = _asc + asc("a") - asc("A")
|
_asc = _asc + asc("a") - asc("A")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return chr(_asc)
|
return chr(_asc)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def bit_and(a, b)
|
def bit_and(a, b)
|
||||||
c = 0
|
c = 0
|
||||||
for i = 0 to 31
|
for i = 0 to 31
|
||||||
if (a mod 2) and (b mod 2) then
|
if (a mod 2) and (b mod 2) then
|
||||||
t = 1
|
t = 1
|
||||||
else
|
else
|
||||||
t = 0
|
t = 0
|
||||||
endif
|
endif
|
||||||
c = c + t * (2 ^ i)
|
c = c + t * (2 ^ i)
|
||||||
a = fix(a / 2)
|
a = fix(a / 2)
|
||||||
b = fix(b / 2)
|
b = fix(b / 2)
|
||||||
next
|
next
|
||||||
|
|
||||||
return c
|
return c
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def bit_or(a, b)
|
def bit_or(a, b)
|
||||||
c = 0
|
c = 0
|
||||||
for i = 0 to 31
|
for i = 0 to 31
|
||||||
if (a mod 2) or (b mod 2) then
|
if (a mod 2) or (b mod 2) then
|
||||||
t = 1
|
t = 1
|
||||||
else
|
else
|
||||||
t = 0
|
t = 0
|
||||||
endif
|
endif
|
||||||
c = c + t * (2 ^ i)
|
c = c + t * (2 ^ i)
|
||||||
a = fix(a / 2)
|
a = fix(a / 2)
|
||||||
b = fix(b / 2)
|
b = fix(b / 2)
|
||||||
next
|
next
|
||||||
|
|
||||||
return c
|
return c
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def bit_xor(a, b)
|
def bit_xor(a, b)
|
||||||
c = 0
|
c = 0
|
||||||
for i = 0 to 31
|
for i = 0 to 31
|
||||||
if (a mod 2) <> (b mod 2) then
|
if (a mod 2) <> (b mod 2) then
|
||||||
t = 1
|
t = 1
|
||||||
else
|
else
|
||||||
t = 0
|
t = 0
|
||||||
endif
|
endif
|
||||||
c = c + t * (2 ^ i)
|
c = c + t * (2 ^ i)
|
||||||
a = fix(a / 2)
|
a = fix(a / 2)
|
||||||
b = fix(b / 2)
|
b = fix(b / 2)
|
||||||
next
|
next
|
||||||
|
|
||||||
return c
|
return c
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
class point
|
class point
|
||||||
var x = 0
|
var x = 0
|
||||||
var y = 0
|
var y = 0
|
||||||
|
|
||||||
def tostring()
|
def tostring()
|
||||||
return "[" + str(x) + ", " + str(y) + "]"
|
return "[" + str(x) + ", " + str(y) + "]"
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
|
||||||
class log
|
class log
|
||||||
def m(msg)
|
def m(msg)
|
||||||
print "Message: " + msg;
|
print "Message: " + msg;
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def w(msg)
|
def w(msg)
|
||||||
print "Warning: " + msg;
|
print "Warning: " + msg;
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def e(msg)
|
def e(msg)
|
||||||
print "Error: " + msg;
|
print "Error: " + msg;
|
||||||
enddef
|
enddef
|
||||||
endclass
|
endclass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user