Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
c642c091
Commit
c642c091
authored
14 years ago
by
mcmlxxix
Browse files
Options
Downloads
Patches
Plain Diff
Use time_t for game timer, add revision info
parent
c35cc6ee
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
xtrn/synchronetris/tetris.js
+17
-19
17 additions, 19 deletions
xtrn/synchronetris/tetris.js
xtrn/synchronetris/tetrisobj.js
+7
-6
7 additions, 6 deletions
xtrn/synchronetris/tetrisobj.js
xtrn/synchronetris/timer.js
+5
-3
5 additions, 3 deletions
xtrn/synchronetris/timer.js
with
29 additions
and
28 deletions
xtrn/synchronetris/tetris.js
+
17
−
19
View file @
c642c091
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
For Synchronet v3.15+
For Synchronet v3.15+
Matt Johnson(2009)
Matt Johnson(2009)
*/
*/
//$Id$
const
VERSION
=
"
$Revision$
"
.
split
(
'
'
)[
1
];
load
(
"
chateng.js
"
);
load
(
"
chateng.js
"
);
load
(
"
graphic.js
"
);
load
(
"
graphic.js
"
);
...
@@ -308,8 +310,7 @@ function lobby()
...
@@ -308,8 +310,7 @@ function lobby()
break
;
break
;
case
0
:
case
0
:
if
(
!
t
.
timer
.
countdown
)
t
.
loadGame
();
if
(
!
t
.
timer
.
countdown
)
t
.
loadGame
();
var
current
=
time
();
var
difference
=
time
()
-
t
.
timer
.
lastupdate
;
var
difference
=
current
-
t
.
timer
.
lastupdate
;
if
(
!
difference
>=
1
)
break
;
if
(
!
difference
>=
1
)
break
;
if
(
!
t
.
timer
.
countDown
(
difference
))
{
if
(
!
t
.
timer
.
countDown
(
difference
))
{
startGame
(
t
);
startGame
(
t
);
...
@@ -353,7 +354,7 @@ function lobby()
...
@@ -353,7 +354,7 @@ function lobby()
game
.
status
=
0
;
game
.
status
=
0
;
var
file
=
new
File
(
game
.
dataFile
);
var
file
=
new
File
(
game
.
dataFile
);
file
.
open
(
'
r+
'
,
true
);
file
.
open
(
'
r+
'
,
true
);
file
.
iniSetValue
(
null
,
"
created
"
,
system
.
time
r
);
file
.
iniSetValue
(
null
,
"
created
"
,
""
+
time
()
);
file
.
iniSetValue
(
null
,
"
status
"
,
0
);
file
.
iniSetValue
(
null
,
"
status
"
,
0
);
file
.
close
();
file
.
close
();
}
}
...
@@ -438,7 +439,7 @@ function lobby()
...
@@ -438,7 +439,7 @@ function lobby()
function
playGame
(
game
)
function
playGame
(
game
)
{
{
var
menu
;
var
menu
;
var
lastupdate
=
system
.
time
r
;
var
lastupdate
=
time
()
;
/* lines per level */
/* lines per level */
var
lines
=
10
;
var
lines
=
10
;
...
@@ -471,13 +472,6 @@ function playGame(game)
...
@@ -471,13 +472,6 @@ function playGame(game)
}
}
currentPlayer
=
game
.
players
[
currentPlayerID
];
currentPlayer
=
game
.
players
[
currentPlayerID
];
}
}
function
initChat
()
{
chat
.
init
(
38
,
15
,
42
,
8
);
chat
.
input_line
.
init
(
42
,
24
,
38
,
""
,
"
\
1n
"
);
chat
.
partChan
(
"
tetris lobby
"
,
user
.
alias
);
chat
.
joinChan
(
"
tetris game
"
+
game
.
gameNumber
,
user
.
alias
,
user
.
name
);
}
function
main
()
function
main
()
{
{
redraw
();
redraw
();
...
@@ -573,9 +567,11 @@ function playGame(game)
...
@@ -573,9 +567,11 @@ function playGame(game)
}
}
killPlayer
(
currentPlayerID
);
killPlayer
(
currentPlayerID
);
send
(
"
DEAD
"
);
send
(
"
DEAD
"
);
if
(
game
.
status
==
2
&&
game
.
winner
==
currentPlayerID
)
{
if
((
game
.
status
==
2
&&
game
.
winner
==
currentPlayerID
)
||
countMembers
(
game
.
players
)
==
1
)
{
if
(
file_exists
(
game
.
dataFile
.
name
))
if
(
file_exists
(
game
.
dataFile
))
file_remove
(
game
.
dataFile
.
name
);
file_remove
(
game
.
dataFile
);
if
(
file_exists
(
game
.
dataFile
+
"
.bck
"
))
file_remove
(
game
.
dataFile
+
"
.bck
"
);
}
}
return
true
;
return
true
;
}
}
...
@@ -587,10 +583,10 @@ function playGame(game)
...
@@ -587,10 +583,10 @@ function playGame(game)
if
(
!
currentPlayer
||
!
currentPlayer
.
active
)
return
;
if
(
!
currentPlayer
||
!
currentPlayer
.
active
)
return
;
var
update
=
false
;
var
update
=
false
;
var
difference
=
system
.
time
r
-
lastupdate
;
var
difference
=
time
()
-
lastupdate
;
if
(
difference
<
pause
)
return
;
if
(
difference
<
pause
)
return
;
lastupdate
=
system
.
time
r
;
lastupdate
=
time
()
;
getLines
();
getLines
();
...
@@ -645,6 +641,7 @@ function playGame(game)
...
@@ -645,6 +641,7 @@ function playGame(game)
game
.
players
[
packet
.
player
].
drawNext
();
game
.
players
[
packet
.
player
].
drawNext
();
break
;
break
;
case
"
HOLD
"
:
case
"
HOLD
"
:
game
.
players
[
packet
.
player
].
unDrawPiece
();
game
.
players
[
packet
.
player
].
holdPiece
=
packet
.
piece
;
game
.
players
[
packet
.
player
].
holdPiece
=
packet
.
piece
;
game
.
players
[
packet
.
player
].
drawHold
();
game
.
players
[
packet
.
player
].
drawHold
();
break
;
break
;
...
@@ -700,6 +697,8 @@ function playGame(game)
...
@@ -700,6 +697,8 @@ function playGame(game)
break
;
break
;
case
"
UPDATE
"
:
case
"
UPDATE
"
:
break
;
break
;
case
"
PLAYER
"
:
break
;
case
"
GRID
"
:
case
"
GRID
"
:
data
.
grid
=
currentPlayer
.
grid
;
data
.
grid
=
currentPlayer
.
grid
;
break
;
break
;
...
@@ -843,14 +842,14 @@ function playGame(game)
...
@@ -843,14 +842,14 @@ function playGame(game)
currentPlayer
.
drawPiece
();
currentPlayer
.
drawPiece
();
currentPlayer
.
drawNext
();
currentPlayer
.
drawNext
();
currentPlayer
.
drawHold
();
currentPlayer
.
drawHold
();
send
(
"
HOLD
"
);
send
(
"
PIECE
"
);
send
(
"
PIECE
"
);
send
(
"
NEXT
"
);
send
(
"
NEXT
"
);
send
(
"
HOLD
"
);
}
else
{
}
else
{
currentPlayer
.
holdPiece
=
currentPlayer
.
currentPiece
.
id
;
currentPlayer
.
holdPiece
=
currentPlayer
.
currentPiece
.
id
;
send
(
"
HOLD
"
);
getNewPiece
();
getNewPiece
();
currentPlayer
.
drawHold
();
currentPlayer
.
drawHold
();
send
(
"
HOLD
"
);
}
}
}
}
function
getNewPiece
()
function
getNewPiece
()
...
@@ -1017,7 +1016,6 @@ function playGame(game)
...
@@ -1017,7 +1016,6 @@ function playGame(game)
}
}
initGame
();
initGame
();
//initChat();
main
();
main
();
}
}
...
...
This diff is collapsed.
Click to expand it.
xtrn/synchronetris/tetrisobj.js
+
7
−
6
View file @
c642c091
...
@@ -3,7 +3,7 @@ function Tetris(dataFile)
...
@@ -3,7 +3,7 @@ function Tetris(dataFile)
this
.
timer
=
new
Timer
(
"
\
1y
\
1h
"
);
this
.
timer
=
new
Timer
(
"
\
1y
\
1h
"
);
this
.
players
=
[];
this
.
players
=
[];
this
.
status
=-
1
;
this
.
status
=-
1
;
this
.
lastupdate
=
0
;
this
.
lastupdate
=
-
1
;
this
.
garbage
=
true
;
this
.
garbage
=
true
;
this
.
update
=
true
;
this
.
update
=
true
;
this
.
winner
=
false
;
this
.
winner
=
false
;
...
@@ -41,19 +41,20 @@ function Tetris(dataFile)
...
@@ -41,19 +41,20 @@ function Tetris(dataFile)
var
created
=
file
.
iniGetValue
(
null
,
"
created
"
);
var
created
=
file
.
iniGetValue
(
null
,
"
created
"
);
if
(
created
>
0
)
{
if
(
created
>
0
)
{
var
current
=
system
.
time
r
;
var
current
=
time
()
;
var
difference
=
current
-
created
;
var
difference
=
current
-
created
;
this
.
timer
.
init
(
20
-
difference
);
this
.
timer
.
init
(
20
-
difference
);
}
}
this
.
gameNumber
=
Number
(
file
.
iniGetValue
(
null
,
"
gameNumber
"
));
this
.
gameNumber
=
Number
(
file
.
iniGetValue
(
null
,
"
gameNumber
"
));
this
.
status
=
file
.
iniGetValue
(
null
,
"
status
"
);
this
.
status
=
file
.
iniGetValue
(
null
,
"
status
"
);
this
.
players
=
file
.
iniGetObject
(
"
players
"
);
var
plist
=
file
.
iniGetObject
(
"
players
"
);
for
(
var
p
in
this
.
players
)
{
for
(
var
p
in
plist
)
{
this
.
players
[
p
]
=
new
Player
(
players
.
getAlias
(
p
),
this
.
players
[
p
]);
if
(
!
this
.
players
[
p
])
this
.
players
[
p
]
=
new
Player
(
players
.
getAlias
(
p
),
plist
[
p
]);
else
this
.
players
[
p
].
active
=
plist
[
p
];
}
}
this
.
update
=
true
;
this
.
update
=
true
;
log
(
"
loaded game:
"
+
this
.
gameNumber
);
file
.
close
();
file
.
close
();
}
}
this
.
redraw
=
function
()
this
.
redraw
=
function
()
...
...
This diff is collapsed.
Click to expand it.
xtrn/synchronetris/timer.js
+
5
−
3
View file @
c642c091
...
@@ -10,7 +10,7 @@ function Timer(color)
...
@@ -10,7 +10,7 @@ function Timer(color)
this
.
init
=
function
(
length
)
this
.
init
=
function
(
length
)
{
{
this
.
countdown
=
length
;
this
.
countdown
=
length
;
this
.
lastupdate
=
time
();
this
.
lastupdate
=
""
+
time
();
}
}
this
.
redraw
=
function
()
this
.
redraw
=
function
()
{
{
...
@@ -35,11 +35,13 @@ function Timer(color)
...
@@ -35,11 +35,13 @@ function Timer(color)
console
.
putmsg
(
this
.
color
+
time
);
console
.
putmsg
(
this
.
color
+
time
);
console
.
attributes
=
ANSI_NORMAL
;
console
.
attributes
=
ANSI_NORMAL
;
}
}
this
.
countDown
=
function
(
difference
)
this
.
countDown
=
function
()
{
{
var
difference
=
time
()
-
this
.
lastupdate
;
this
.
countdown
-=
difference
;
this
.
countdown
-=
difference
;
if
(
this
.
countdown
<=
0
)
return
false
;
if
(
this
.
countdown
<=
0
)
return
false
;
this
.
lastupdate
=
time
();
this
.
lastupdate
=
""
+
time
();
return
true
;
return
true
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment