public void Update(double timePassed, EasyErgsocket.Erg givenParent = null) { if (givenParent != null) { thisErg.distance = givenParent.distance; thisErg.exerciseTime = givenParent.exerciseTime; } }
void mainLoop(object sender, EventArgs e) { //Update all the players //This loop tries to update at least 1 player in each iteration, if it fails the loop is either over or there is a failed parent/child link List <string> alreadyUpdatedPlayers = new List <string>(); while (alreadyUpdatedPlayers.Count < players.Count) { //see if there's a player that we could update bool hasPlayerBeenUpdated = false; foreach (IPlayer player in players.Values) { //do not update the same player twice if (alreadyUpdatedPlayers.Contains(player.GetErg().ergId)) { continue; } //update all the player without parents or whose parents have already been updated if (player.ParentId == "") { player.Update(null); alreadyUpdatedPlayers.Add(player.GetErg().ergId); hasPlayerBeenUpdated = true; } else if (alreadyUpdatedPlayers.Contains(player.ParentId)) { EasyErgsocket.Erg parent = players[player.ParentId].GetErg(); player.Update(parent); alreadyUpdatedPlayers.Add(player.GetErg().ergId); hasPlayerBeenUpdated = true; } else { //This lane has a parent that does not exist yet... continue; } } if (!hasPlayerBeenUpdated) { //no player updated... there seems to be a problem? //TODO: What should we do? This typically means there is a erg without parent or a circular dependency... break; } } IList <IPlayer> playerList = players.Values.ToList(); //update the GUI laneList.UpdatePlayer(playerList); //send the bots foreach (IErgSender ergSender in ergSenders) { ergSender.SendErgs(playerList); } }
public bool TryReceive() { if (!IsConnected) { return(false); } EasyErgsocket.Erg newErg = new EasyErgsocket.Erg(); newErg.name = "ReceivedPlayer"; OnErgReceived(this, new ErgEventArgs(newErg)); return(true); }
public SimpleBot(string givenName) { thisErg = new EasyErgsocket.Erg(); thisErg.cadence = 1; thisErg.calories = 1; thisErg.distance = 0.0; thisErg.ergtype = EasyErgsocket.ErgType.ROW; thisErg.exerciseTime = 0.0; thisErg.heartrate = 0; thisErg.name = givenName; thisErg.paceInSecs = 120; thisErg.playertype = EasyErgsocket.PlayerType.BOT; thisErg.power = 0; thisErg.ergId = NameToId(givenName); }
public ErgEventArgs(EasyErgsocket.Erg givenErg) { this.Erg = givenErg; }