-
Notifications
You must be signed in to change notification settings - Fork 8
/
Beginners - Stack.monkey2
44 lines (34 loc) · 882 Bytes
/
Beginners - Stack.monkey2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#Import "<std>"
#Import "<mojo>"
Using std..
Using mojo..
Class MyWindow Extends Window
Field mystack:= New Stack<String>
Method New()
For Local i:=0 To 10
mystack.Push(i)
Next
mystack.Add(500) ' add is like push
mystack.Insert(0,1000) ' insert at any point (0) = at starting point of list
End Method
Method OnRender( canvas:Canvas ) Override
App.RequestRender() ' Activate this method
If Keyboard.KeyReleased(Key.Space)
mystack.Erase(0)
Print mystack.Length
End if
For Local i:=0 until mystack.Length
canvas.DrawText(mystack.Get(i),10,i*20)
Next
'
' top reads the last value added
canvas.DrawText("Stack.Top value :"+mystack.Top,320,40)
' if key escape then quit
If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()
End Method
End Class
Function Main()
New AppInstance
New MyWindow
App.Run()
End Function