public void requestMove(NetworkMessage boardMsg) { byte[] bytes = boardMsg.reader.ReadBytesAndSize(); string msg = Game.ClientController.Deserialize <Game.CommProtocol.StringMessage> (bytes).msg; TCPLocalConnection.sendMessage(msg); }
public void restartGame() { foreach (GameObject g in discs) { Destroy(g); } discs.Clear(); foreach (TowerPole tp in poles) { tp.amountOfDiscs = 0; } board.Clear(); board.Add(new List <int> ()); board.Add(new List <int> ()); board.Add(new List <int> ()); for (int i = 0; i < (int)amountSlider.value; i++) { discs.Add(Instantiate(discPrefab, poles [0].addDisc(), Quaternion.identity)); discs [discs.Count - 1].GetComponent <TowerDisc> ().init(materials [i], i); board [0].Add(i); } moveCounter = 0; wonGame = false; TCPLocalConnection.sendMessage(formatBoard()); }
private void simulateFree(List <MemorySegment> allocList) { int freePos = allocList [Random.Range(0, allocList.Count - 1)].pos; TCPLocalConnection.sendMessage("Free " + freePos); print("Free " + freePos); }
public void handleGameStatus(NetworkMessage gameStatusMsg) { byte[] bytes = gameStatusMsg.reader.ReadBytesAndSize(); GameInfo msg = ClientController.Deserialize <GameInfo> (bytes); if (msg.gameOver) { string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver; TCPLocalConnection.sendMessage(gameOverString); gameOver(); waitingForInput = false; string gameOverMsg; if (msg.winnerColor == PlayerColor.None) { gameOverMsg = "It's a draw!"; } else { gameOverMsg = msg.winnerColor + " won"; } CurrentGame.gameOver(gameOverMsg); } }
public void handleGameInfo(NetworkMessage msg) { byte[] bytes = msg.reader.ReadBytesAndSize(); GameInfo infoMsg = Game.ClientController.Deserialize <GameInfo> (bytes);; if (infoMsg.gameOver) { string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver; TCPLocalConnection.sendMessage(gameOverString); isGameOver = true; UnetRoomConnector.shutdownCurrentConnection(); string gameOverMsg; if (infoMsg.winnerColor == Game.PlayerColor.None) { gameOverMsg = "It's a draw!"; } else { gameOverMsg = infoMsg.winnerColor + " won"; } CurrentGame.gameOver(gameOverMsg); } }
private void simulateMalloc(List <MemorySegment> freeList) { int allocationSize = calcAllocSize(); TCPLocalConnection.sendMessage("Malloc " + allocationSize); print("Malloc " + allocationSize); }
public void handleGameInfoMsg(NetworkMessage initMsg) { GameInfo msg = Deserialize <GameInfo> (initMsg.reader.ReadBytesAndSize()); if (msg.gameOver) { isGameOver = true; canSendServerMsg = false; isListeningForTCP = false; UnetRoomConnector.shutdownCurrentConnection(); string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver; string gameOverMsg; //Debug.LogError ("Winner: " + msg.winnerColor); if (msg.winnerColor == Game.PlayerColor.None) { gameOverMsg = "It's a draw!"; TCPLocalConnection.sendMessage(gameOverString + ": 0"); } else { gameOverMsg = msg.winnerColor + " won"; TCPLocalConnection.sendMessage(gameOverString + ": " + (msg.winnerColor == PlayerColor.Blue ? "1" : "-1")); } CurrentGame.gameOver(gameOverMsg); } }
public void handleGameState(NetworkMessage gameStateMsg) { byte[] bytes = gameStateMsg.reader.ReadBytesAndSize(); GameState stateMsg = Game.ClientController.Deserialize <GameState> (bytes); localRenderer.updatePlayerPosition(stateMsg.currentPos, stateMsg.currentTarget, stateMsg.time); TCPLocalConnection.sendMessage(stateMsg.currentPos.ToString()); }
public void gameOver() { moveQ.Clear(); playing = false; string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver; TCPLocalConnection.sendMessage(gameOverString + ": " + logic.getCurrentScore()); //restartGame (); }
public void freeButtonPressed() { MemorySegment selectedSeg = segmentClicker.getSelectedSegment(); if (selectedSeg != null) { TCPLocalConnection.sendMessage("Free " + selectedSeg.pos); } }
private void sendStartMsg(SortingVisualNumber[] numbers) { string s = ""; foreach (SortingVisualNumber n in numbers) { s += n.value + " "; } TCPLocalConnection.sendMessage(s); }
private void instantReadTCPMsg(ReceivedLocalMessage msg) { if (msg.message == "JUMP") { localPlayer.activateJump(); } MainThread.fireEventAtMainThread(() => { print("Sending msg"); TCPLocalConnection.sendMessage(formatBoard()); }); }
private void playMove() { if (moveQ.Count == 0) { TCPLocalConnection.sendMessage(logic.formatBoard()); } else { int tempMove = moveQ [0]; moveQ.RemoveAt(0); logic.playMove(tempMove); } }
private void requestBoard() { if (initBoard) { console.text = "Invalid start board"; } else { console.text = "Waiting for board"; } TCPLocalConnection.sendMessage("InitBoard"); initBoard = true; }
public void handleGameStatus(NetworkMessage gameStatusMsg) { byte[] bytes = gameStatusMsg.reader.ReadBytesAndSize(); GameInfo msg = Deserialize <GameInfo> (bytes); if (msg.gameOver && isGameOver == false) { BoardState finalState = getFinalState(msg.winnerColor); TCPLocalConnection.sendMessage(Connect4JsonParser.formatBoardMsgFromServer(lastRawBoard, msg.myColor, finalState)); localRenderer.onGameOver(msg.winnerColor == PlayerColor.Yellow ? Piece.Yellow : Piece.Red); gameOver(); CurrentGame.gameOver(getGameOverText(msg.winnerColor)); } }
public void takeInput(string msg) { if (isMainPlayer()) { TCPLocalConnection.sendMessage(msg); } else if (NPC) { bot.onReceiveInput(msg); } else if (Human) { onHumanTakeInput(); } //Do nothing if us human }
private static void onBotConnected(ConnectionStatus status) { if (status == ConnectionStatus.Disconnected) { TCPLocalConnection.restartServer(); return; } if (status != ConnectionStatus.Connected) { return; } onStartFunc(); TCPLocalConnection.sendMessage(currentGameType + " API session started."); }
private void playMove() { if (wonGame) { return; } if (moveQ.Count == 0) { TCPLocalConnection.sendMessage(formatBoard(currentBoard)); } else { int tempMove = moveQ [0]; moveQ.RemoveAt(0); logic.playMove(tempMove); } }
public void newGameButtonClicked() { victory = false; initBoard = false; moveQ.Clear(); console.text = ""; string[,] newBoard = new string[(int)sizeSlider.slider.value, (int)sizeSlider.slider.value]; if (generate.isOn) { newBoard = generateNewBoard(); currentBoard = logic.resetGame((int)sizeSlider.slider.value, newBoard); TCPLocalConnection.sendMessage(formatBoard(currentBoard)); } else { requestBoard(); } }
private void readTCPMessage(ReceivedLocalMessage msg) { try { string[] words = msg.message.Split(' '); int x = int.Parse(words[0]); int y = int.Parse(words[1]); if (gameController.isInRange(x, y)) { bool hit = gameController.samplePixel(x, y); TCPLocalConnection.sendMessage(hit ? "HIT" : "MISS"); } else { TCPLocalConnection.sendMessage("OUT OF BOUNDS"); } } catch (Exception e) { Debug.LogError(e.Message); TCPLocalConnection.sendMessage("Invalid Message"); } }
private void playMove() { if (wonGame) { return; } if (moveQ.Count == 0) { TCPLocalConnection.sendMessage(formatBoard()); } else { int[] tempMove = moveQ [0]; moveQ.RemoveAt(0); makeMove(tempMove[0], tempMove[1]); } if (moveQ.Count == 0 && wonGame == false) { TCPLocalConnection.sendMessage(formatBoard()); } }
public void victory() { wonGame = true; TCPLocalConnection.sendMessage("Victory " + moveCounter); }
private IEnumerator sendBoardToPlayer() { yield return(new WaitForSeconds(1)); TCPLocalConnection.sendMessage(formatBoard(currentBoard)); }
public void sendFreePressed() { TCPLocalConnection.sendMessage("Free " + freeInputField.text); }
public void sendNextSim() { TCPLocalConnection.sendMessage(simList[simCounter++]); print(simCounter); }
private IEnumerator sendBoardToPlayer() { yield return(new WaitForSeconds(1)); TCPLocalConnection.sendMessage("Welcome"); }
private void readTCPMsg(ReceivedLocalMessage inMsg) { APIMsgConclusion outMsg = APIRouter.handleIncomingMsg(inMsg.message); TCPLocalConnection.sendMessage(outMsg.msg); }
private void handlePing(NetworkMessage msg) { TCPLocalConnection.sendMessage("PING Response"); }
public void gameOver(int moves) { console.text = "Victory!\nSteps: " + moves.ToString(); TCPLocalConnection.sendMessage("Victory " + moves.ToString()); victory = true; }
private void victory() { wonGame = true; consoleText.text = "Victory in " + moveCounter + " moves!"; TCPLocalConnection.sendMessage("Victory " + moveCounter); }