public string LocalState(int roundId) { lock (this) { if (_GameToSend != null) { Console.WriteLine("already asked for state"); return("You already asked for Local state of " + _GameToSend.RoundId + " round"); } if (roundId == _game.RoundId) { Console.WriteLine("great timing"); return(LogLocalGlobal.LocalState(_game, _pId)); } if (roundId > _game.RoundId) { _GameToSend = new Game(); _GameToSend.RoundId = roundId; Console.WriteLine("going to wait for state: " + _GameToSend.RoundId); Monitor.Wait(this); Console.WriteLine("Woke up"); return(LogLocalGlobal.LocalState(_GameToSend, _pId)); } string r = "Too late, you want game from round " + roundId + " and I am already in round: " + _game.RoundId; Console.WriteLine(r); return(r); } }
internal string LocalState(int roundId) { if (_getStateOfRound != -1) { return("You already asked for Local state of " + _getStateOfRound + " round"); } lock (this) { if (roundId == _game.RoundId) { return(LogLocalGlobal.LocalState(_game, _pId)); } if (roundId > _game.RoundId) { _getStateOfRound = roundId; Monitor.Wait(this); return(LogLocalGlobal.LocalState(_game, _pId)); } return("Too late, you want game from round " + roundId + " and I am already in round: " + _game.RoundId); } }
internal void GlobalStatus() { Console.WriteLine(LogLocalGlobal.LocalState(_game, _pId)); }