Gambas France BETA


Pas de compte ? Incription

Games

BeastScroll



Concent



DeepSpace



GameOfLife



GNUBoxWorld



Invaders


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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
' Gambas module file

' TODO: Make real setup for playing
' TODO: There is an occasional flickering when shooting and the ships are already near the player and few

PUBLIC X AS INTEGER
PUBLIC Y AS INTEGER
' Hardcoded corresponding to the strings in Draw() below!
PUBLIC Width AS INTEGER = 3
PUBLIC Height AS INTEGER = 2

PRIVATE $hEnemies AS Timer
PRIVATE $hMissiles AS Timer

PUBLIC SUB Main()
' Debug aid. Watch /tmp/pipe with "tail -f"
' Dim hPipe As Stream
'
' hPipe = Pipe "/tmp/pipe" For Write
' Error To #hPipe

Screen.Cursor = Cursor.Hidden
Screen.Echo = FALSE
Window.Attributes = Attr.Bold
Object.Attach(Window, ME, "Window")
Window.SetFocus()

X = (Window.Width - Width) \ 2
Y = Window.Height - Height

Object.Attach(Enemies, ME, "Enemies")

Draw()
' Populate ca. 1/3 of the screen with enemies. It will actually look more
' because of the enemy arrangement. But that's good :-)
Enemies.Init(Window, Window.Width * Window.Height / 3 / Enemy.AverageWidth)
Missiles.Init(Window)
Window.Buffered = TRUE

$hEnemies = NEW Timer AS "Enemies"
' TODO: The Timers are made for a 80*24 terminal.
' Make it 100 and you'll likely win, 75 really depends on the amount of Borg for me...
$hEnemies.Delay = 75
$hMissiles = NEW Timer AS "Missiles"
$hMissiles.Delay = 50

$hEnemies.Start()
$hMissiles.Start()

END

PUBLIC SUB Window_Read()

SELECT Window.Read()
' Navigate left/right
CASE Key.Left
IF X = 0 THEN RETURN
Undraw()
DEC X
Draw()
CASE Key.Right
IF X + Width >= Window.Width THEN RETURN
Undraw()
INC X
Draw()
' Navigate up/down
CASE Key.Up
IF Y <= 0 THEN RETURN
Undraw()
DEC Y
Draw()
CASE Key.Down
IF Y >= Window.Height - Height THEN RETURN
Undraw()
INC Y
Draw()
' Shoot normal missile
CASE Key[" "]
Missiles.Shoot(Missile.Normal, X, Y - 1)
'If Not $hMissiles.Enabled Then $hMissiles.Start()
' Shoot super missile
CASE Key["v"]
Missiles.Shoot(Missile.Super, X, Y - 1)
'If Not $hMissiles.Enabled Then $hMissiles.Start
' Of course, manipulate the timers
CASE Key["+"]
$hEnemies.Delay -= 10
$hMissiles.Delay -= 5
CASE Key["-"]
$hEnemies.Delay += 10
$hMissiles.Delay += 5
END SELECT

END

PUBLIC SUB Enemies_Triumph()

End("TRIUMPH!", Color.Yellow)

END

PUBLIC SUB Enemies_GameOver()

End("GAME OVER!", Color.Blue)

END

PRIVATE SUB End(sMessage AS STRING, iColor AS INTEGER)

$hEnemies.Stop()
$hMissiles.Stop()
'' TODO: The message display is glitchy
Window.Buffered = FALSE
Window.PrintCenter(sMessage,, Pair[iColor, Window.Background])
'' TODO: What now? Note that the user can still interact at this point...

END

PRIVATE SUB Draw()

Window.Print(" | ", X, Y)
Window.Print("^'^", X, Y + 1)

END

PRIVATE SUB Undraw()

Window.Print(Space$(Width), X, Y)
Window.Print(Space$(Width), X, Y + 1)

END

PUBLIC SUB Enemies_Timer()

Enemies.Move()
IF NOT $hMissiles.Enabled THEN
Enemies.Draw()
Screen.Refresh()
ENDIF

END

PUBLIC SUB Missiles_Timer()

IF Missiles.Move() AND Missiles.Count = 0 THEN
'$hMissiles.Stop()
RETURN
ENDIF
' Missiles draw at a higher rate so we can safely redraw everything
' here. Note that, thanks to ncurses' buffering, only the changed
' parts are redrawn so that there is no overhead in more frequent
' Screen.Refresh()es here.
Enemies.Draw()
Screen.Refresh()

END

MineSweeper



Pong


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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
' Gambas module file

PRIVATE $hConfig AS Window
PRIVATE $hTimer AS Timer
' Scores
PRIVATE $iS1 AS INTEGER
PRIVATE $iS2 AS INTEGER
' Players' paddles
PRIVATE $hP1 AS Paddle
PRIVATE $hP2 AS Paddle
' If Paddle2 shall be controlled by an NPC object
PRIVATE $bNPC AS BOOLEAN
PRIVATE $hNPC AS NPC
' The ball
PRIVATE $hBall AS Ball

PUBLIC SUB Main()

' Make our Window raise events
Object.Attach(Window, ME, "Window")
Window.SetFocus()

Screen.Cursor = Cursor.Hidden
Screen.Echo = FALSE
Screen.Input = Input.CBreak

Window.Border = Border.Ascii
Window.Caption = Subst$(("Pong v&1 - gb.ncurses Example"), Application.Version)
Window.Clear()

$hConfig = NEW Window(TRUE, 0, 0, 30, 5)
$hConfig.Border = Border.Ascii
$hConfig.Center()

$hTimer = NEW Timer AS "Timer"

$iS1 = 0
$iS2 = 0

$bNPC = TRUE
GameInit()

END

PRIVATE SUB Configure()

$hConfig.Show()
$hConfig.Clear()
$hConfig.PrintCenter(("What to do?\nPlay again: [P]\nChange opponent: [o]\n\nQuit [q]"))
SELECT CASE Window.Ask(("Poq"))
CASE ("o")
Configure_Opponent()
CASE ("q")
QUIT
END SELECT
$hConfig.Hide()

END

PRIVATE SUB Configure_Opponent()

$hConfig.Clear()
$hConfig.PrintCenter(("Play against whom?\n[h]uman, [N]ormal, [m]aster"))
$bNPC = TRUE
SELECT CASE Window.Ask(("hNm"))
CASE ("h")
$bNPC = FALSE
CASE ("n")
$hNPC.Mode = NPC.Normal
CASE ("m")
$hNPC.Mode = NPC.Master
END SELECT

END

PRIVATE SUB GameInit()

' If both as 'master' NPCs we could make a screensaver out of it :-)
$hP1 = NEW Paddle(Window, 1)
$hP2 = NEW Paddle(Window, -1)
$hBall = NEW Ball(Window)
$hNPC = NEW NPC(Window, $hBall, $hP2)
GameStart()

END

PRIVATE SUB GameStart()

Window.Buffered = FALSE
Configure()
$hP1.Reset()
$hP2.Reset()
$hBall.Reset()
$hNPC.Init()
Window.Buffered = TRUE
Redraw()
' See SPEED. The width means actually the intra-paddle width:
$hTimer.Delay = 4000 / Sqr(2 * (Window.Width - 4) ^ 2)
$hTimer.Start()

END

PUBLIC SUB Timer_Timer()

IF $bNPC THEN $hNPC.Move()
SELECT CASE $hBall.Move($hP1, $hP2)
CASE -1
INC $iS2
GOTO _NewGame
CASE 1
INC $iS1
GOTO _NewGame
END SELECT
' I suppose that this does not go down to zero
IF $hBall.HitPaddle THEN DEC $hTimer.Delay
Redraw()
RETURN

_NewGame:
' We want to see it
Redraw()
$hTimer.Stop()
' FIXME: Makes stack overflow eventually
GameStart()

END

PUBLIC SUB Window_Read()

DIM iKey AS INTEGER

iKey = Window.Read()
Window.Drain()
' Go two steps per keystroke
' FIXME: Can't reach some coordinate with odd Window.Height
SELECT CASE iKey
' Player 1
CASE Key.Up
IF $hP1.Y > 0 THEN $hP1.Y -= 2
CASE Key.Down
IF $hP1.Y + $hP1.Height < Window.Height THEN $hP1.Y += 2
' Human player 2
CASE Asc("j")
IF NOT $bNPC AND $hP2.Y > 0 THEN $hP2.Y -= 2
CASE Asc("k")
IF NOT $bNPC AND $hP2.Y + $hP2.Height < Window.Height THEN $hP2.Y += 2
' Change ball speed :-)
CASE Asc("+")
IF $hTimer.Delay > 10 THEN $hTimer.Delay -= 10
CASE Asc("-")
$hTimer.Delay += 10
' Pause
CASE Asc(("p"))
Pause()
' Quit
CASE Asc(("q"))
QUIT
CASE ELSE
RETURN
END SELECT
Redraw()

END

PRIVATE SUB Redraw()

DIM iX AS INTEGER = Window.Width / 4

' Scores and net
Window.Print(" " & Str$($iS1) & " ", iX, 1, Attr.Reverse)
Window.Print(" " & Str$($iS2) & " ", iX * 3, 1, Attr.Reverse)
Window.DrawVLine(Window.Width / 2 + 1, 0, Window.Height, ".")
' Players and ball may overwrite the unimportant stuff above
$hP1.Draw()
$hP2.Draw()
$hBall.Draw()
Screen.Refresh()

END

PRIVATE SUB Pause()

$hTimer.Stop()
Window.PrintCenter(("PAUSE"))
Screen.Refresh()
Window.Ask(("p"))
Window.Clear()
Redraw()
$hTimer.Start()

END

Puzzle1To8



RobotFindsKitten



Snake



Solitaire



StarField




====================

Navigation :



<-- Accueil du WIKI : <--

====================

Documentation :



==============================