private async void TappedElementExecute(int pos) { //button.State = movement; if (GameArray[pos] == "") { GameArray[pos] = movement; dataWriter.WriteString(movement); dataWriter.WriteInt16(Convert.ToInt16(pos)); await dataWriter.StoreAsync(); MyTurn = false; LogMessage("Sent my movement!"); LogMessage("Waiting for peer movement!"); if (GameArray.IsWinner()) { LogMessage("WINNER!"); dispatcherService.CallDispatcher(() => { GameStarted = false; MyTurn = false; isInitiator = false; }); LogMessage("Starting new game"); ResetBoard(); HandShake(); return; } WaitForMovement(); } }
private async void WaitForMovement() { var bytesRead = await dataReader.LoadAsync(3); if (bytesRead > 0) { string peerMovement = dataReader.ReadString(1); int position = dataReader.ReadInt16(); if (peerMovement == "R") { LogMessage("Game has been reset"); dispatcherService.CallDispatcher(() => ResetBoard()); HandShake(); } else { LogMessage("Received movement, your turn!"); dispatcherService.CallDispatcher(() => { GameArray[position] = peerMovement; if (GameArray.IsWinner()) { LogMessage("LOSER!"); dispatcherService.CallDispatcher(() => { GameStarted = false; MyTurn = false; isInitiator = false; }); LogMessage("Starting new game"); ResetBoard(); HandShake(); return; } }); MyTurn = true; } } }