-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
299 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
extends Resource | ||
class_name Game | ||
|
||
var data := {} | ||
var data := {"DisplayName": "New Game"} | ||
var turns := [Turn.new()] | ||
var path := "" | ||
|
||
func _to_string() -> String: | ||
var string = "" | ||
for elem in data: | ||
string += '["{elem}" "{data}"]\n'.format({"elem":elem, "data":data[elem]}) | ||
string += "\n" | ||
var capture: String | ||
var promote: String | ||
var currTurn: Turn | ||
for turn in range(1, len(turns), 2): | ||
string += "{turn}. ".format({"turn":(turn/2)+1}) | ||
currTurn = turns[turn] | ||
string += currTurn.to_string()+" " | ||
if turn+1 < len(turns): | ||
currTurn = turns[turn+1] | ||
string += currTurn.to_string()+" " | ||
|
||
string += data.get("Result", "0-0") | ||
|
||
return string | ||
|
||
func nTurns() -> int: | ||
return len(self.turns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
extends Node | ||
|
||
signal sync_games(id) | ||
|
||
const PLAYERS = 2 | ||
const HOST_ID = 1 | ||
var pw: String = "" | ||
var my_id: int | ||
var targetIP: String | ||
var targetPort: int | ||
|
||
func _ready() -> void: | ||
get_tree().connect("network_peer_connected", self, "_player_connected") | ||
get_tree().connect("network_peer_disconnected", self, "_close_connection") | ||
get_tree().connect("connection_failed", self, "_connection_failed") | ||
get_tree().connect("server_disconnected", self, "_server_disconnected") | ||
self._close_connection() | ||
|
||
func host(port: int, pwIn: String): | ||
_close_connection() # In case of restart | ||
var peer = NetworkedMultiplayerENet.new() | ||
peer.create_server(port, PLAYERS) | ||
get_tree().set_network_peer(peer) | ||
my_id = HOST_ID | ||
self.pw = pwIn | ||
|
||
func client(ip: String, port: int, pwIn: String): | ||
_close_connection() # In case of restart | ||
self.targetIP = ip | ||
self.targetPort = port | ||
self.pw = pwIn | ||
get_tree().connect("connected_to_server", self, "_connected_to_server") | ||
var peer = NetworkedMultiplayerENet.new() | ||
peer.create_client(self.targetIP, self.targetPort) | ||
get_tree().set_network_peer(peer) | ||
|
||
func _check_pw(id, pwIn): | ||
if pwIn != pw: | ||
rpc_id(id, "error", "Cannot join", "Passwords don't match") | ||
get_tree().network_peer.disconnect_peer(id) | ||
|
||
remote func _close_connection(): | ||
if get_tree().network_peer: | ||
get_tree().network_peer.close_connection() | ||
var peer = NetworkedMultiplayerENet.new() | ||
peer.create_server(10000, 1) | ||
get_tree().set_network_peer(peer) | ||
|
||
func _player_connected(id: int): | ||
emit_signal("sync_games", id) | ||
|
||
func _connection_failed(): | ||
_close_connection() | ||
error("Connection failed", "Could not establish connection to %s:%d" % [self.targetIP, self.targetPort]) | ||
|
||
func _connected_to_server(): | ||
self.my_id = get_tree().get_network_unique_id() | ||
rpc_id(HOST_ID, "check_pw", self.my_id, self.pw) | ||
|
||
func error(title, message): | ||
get_parent().error(title, message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.