@@ -34,9 +34,11 @@ Onion is open-source project. You can throw pull requests and I'll look through
3434
3535<h1 align =" center " > Examples </h1 >
3636
37- "Hello world":
37+ < a href = " https://github.com/bas1c1/Onion/tree/main/examples " >(More examples)</ a >
3838
39- ```
39+ Simple "Hello world":
40+
41+ ``` py
4042use " std"
4143
4244print (" Hello, world!" )
@@ -45,143 +47,3 @@ stop()
4547
4648// Output: Hello, world!
4749```
48-
49- Calculator:
50-
51- ```
52- use "std"
53-
54- fnum = to_int(input("Enter first number: "))
55- snum = to_int(input("Enter second number: "))
56- op = input("Enter operation (+, -, /, *): ")
57- var result
58-
59- if (op == "+") {
60- result = fnum + snum
61- }
62-
63- if (op == "-") {
64- result = fnum - snum
65- }
66-
67- if (op == "*") {
68- result = fnum * snum
69- }
70-
71- if (op == "/") {
72- result = fnum / snum
73- }
74-
75- if (op != "+" && op != "-" && op != "*" && op != "/") {
76- throw_new_exception("Invalid operation!")
77- }
78-
79- print(result)
80- stop()
81- ```
82-
83- Simple console game:
84-
85- ```
86- use "std"
87- use "random"
88- use "winapi"
89-
90- clear()
91-
92- player = "*"
93- yabloko = "@"
94-
95- visota = 20
96- shirina_b_sten = 20
97- shirina_s_sten = 18
98-
99- player_x = 10
100- player_y = 9
101- yabloko_x = randint(1, 19)
102- yabloko_y = randint(1, 17)
103-
104- ochki = 0
105-
106- fps = 0
107- kadrov = 0
108-
109- def mainloop() {
110- i_input = get_key()
111-
112- for i = 0; i <= visota; i++ {
113- if i == 0 || i == 20 {
114- for j = 0; j <= shirina_b_sten; j++ {
115- sout "#"
116- }
117- }
118- else {
119- sout "#"
120- for c = 0; c <= shirina_s_sten; c++ {
121- sout " "
122- }
123- sout "#"
124- }
125- sout "\n"
126- }
127-
128-
129- while (true) {
130- sleep(50)
131-
132- set_cursor_position(yabloko_x, yabloko_y)
133- sout yabloko
134-
135- if (player_x == 20 || player_y == 18 || player_x == 0 || player_y == 0) {
136- player_x = 10
137- player_y = 9
138- }
139-
140- set_cursor_position(player_x, player_y)
141- sout " " + "\b"
142-
143- if (yabloko_x == player_x && yabloko_y == player_y) {
144- set_cursor_position(yabloko_x, yabloko_y)
145- sout " "
146- ochki += 1
147- yabloko_x = randint(1, 19)
148- yabloko_y = randint(1, 17)
149- }
150-
151- i_input = get_key()
152-
153- if i_input == "w" || i_input == "ц" {
154- player_y -= 1
155- }
156-
157- if i_input == "s" || i_input == "ы" {
158- player_y += 1
159- }
160-
161- if i_input == "a" || i_input == "ф" {
162- player_x -= 1
163- }
164-
165- if i_input == "d" || i_input == "в" {
166- player_x += 1
167- }
168-
169- if i_input == "x" || i_input == "ч" {
170- exit()
171- }
172-
173- if (player_x == 20 || player_y == 18 || player_x == 0 || player_y == 0) {
174- player_x = 10
175- player_y = 9
176- }
177-
178- set_cursor_position(player_x, player_y)
179- sout player
180-
181- set_cursor_position(10, 21)
182- sout ochki
183- }
184- }
185-
186- mainloop()
187- ```
0 commit comments