Skip to content

Commit 55727cf

Browse files
authored
example
1 parent ac91065 commit 55727cf

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

examples/functional.oni

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use "std"
2+
3+
new = ldef (func) {
4+
print(func("Hello, world!"))
5+
}
6+
7+
main = ldef(str) {
8+
return str
9+
}
10+
11+
new(main)
12+
13+
stop()

examples/game.oni

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
use "std"
2+
use "random"
3+
use "winapi"
4+
5+
clear()
6+
7+
player = "*"
8+
yabloko = "@"
9+
10+
visota = 20
11+
shirina_b_sten = 20
12+
shirina_s_sten = 18
13+
14+
player_x = 10
15+
player_y = 9
16+
yabloko_x = randint(1, 19)
17+
yabloko_y = randint(1, 17)
18+
19+
var ochki
20+
var fps
21+
var kadrov
22+
23+
def check_player_pos() {
24+
if (player_x == 20 || player_y == 18 || player_x == 0 || player_y == 0) {
25+
player_x = 10
26+
player_y = 9
27+
}
28+
}
29+
30+
mainloop = ldef () {
31+
i_input = get_key()
32+
33+
for i = 0; i <= visota; i++ {
34+
if i == 0 || i == 20 {
35+
for j = 0; j <= shirina_b_sten; j++ {
36+
sout "#"
37+
}
38+
}
39+
else {
40+
sout "#"
41+
for c = 0; c <= shirina_s_sten; c++ {
42+
sout " "
43+
}
44+
sout "#"
45+
}
46+
sout "\n"
47+
}
48+
49+
while (true) {
50+
sleep(50)
51+
52+
set_cursor_position(yabloko_x, yabloko_y)
53+
sout yabloko
54+
55+
check_player_pos()
56+
57+
set_cursor_position(player_x, player_y)
58+
sout " " + "\b"
59+
60+
if (yabloko_x == player_x && yabloko_y == player_y) {
61+
set_cursor_position(yabloko_x, yabloko_y)
62+
sout " "
63+
ochki += 1
64+
yabloko_x = randint(1, 19)
65+
yabloko_y = randint(1, 17)
66+
}
67+
68+
i_input = get_key()
69+
70+
switch as_var("i_input") {
71+
case "d" {
72+
player_x += 1
73+
}
74+
case "w" {
75+
player_y -= 1
76+
}
77+
case "s" {
78+
player_y += 1
79+
}
80+
case "a" {
81+
player_x -= 1
82+
}
83+
case "x" {
84+
exit()
85+
}
86+
}
87+
88+
check_player_pos()
89+
90+
set_cursor_position(player_x, player_y)
91+
sout player
92+
93+
set_cursor_position(10, 21)
94+
sout ochki
95+
}
96+
}
97+
98+
mainloop()

examples/jscalc.oni

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//This program needs JsEval.dll
2+
use "std"
3+
4+
while(true)
5+
print(eval(input("Enter expression: ")))

examples/simple_calculator.oni

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use "std"
2+
3+
fnum = to_int(input("Enter first number: "))
4+
snum = to_int(input("Enter second number: "))
5+
op = input("Enter operation (+, -, /, *): ")
6+
var result
7+
8+
switch as_var("op") {
9+
case "+" {
10+
result = fnum + snum
11+
}
12+
13+
case "-" {
14+
result = fnum - snum
15+
}
16+
17+
case "*" {
18+
result = fnum * snum
19+
}
20+
21+
case "/" {
22+
result = fnum / snum
23+
}
24+
}
25+
26+
if (op != "+" && op != "-" && op != "*" && op != "/") {
27+
throw_new_exception("Invalid operation!")
28+
}
29+
30+
print(result)
31+
stop()

0 commit comments

Comments
 (0)