public void endTurn() { if (CurrentTurn + 1 <= maxTurn) { CurrentTurn++; HudManager.textCurrentTurn.GetComponent <TextMeshPro>().text = CurrentTurn.ToString(); for (int i = 0; i < virusList.Count; i++) { virusList[i].setOutOfAction(false); virusList[i].setHasExplored(false); } } else { lose(); } }
public string Serialize() { string state = GameOn.ToString() + '\n'; state += CurrentTurn.ToString() + '\n'; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (Board[j, i] != null) { Checker c = Board[j, i]; state += $"{c.color}|{c.King}|{c.Coords.x}|{c.Coords.y}\n"; } } } return(state); }
public string Serialize() { string state = GameOn.ToString() + "\n"; state += CurrentTurn.ToString() + "\n"; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { if (Board[x, y] != null) { Checker checker = Board[x, y]; state += $"{checker.Color}|{checker.King}|{checker.Coords.X}|{checker.Coords.Y}\n"; } } } return(state); }
public string Serialize() { StringBuilder sb = new StringBuilder(); sb.AppendLine(GameOn.ToString()); sb.AppendLine(CurrentTurn.ToString()); for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { if (Board[x, y] != null) { sb.AppendLine(Board[x, y].ToString()); } } } return(sb.ToString()); }
public string Serialize() { string state = GameOn.ToString() + "\n"; state += CurrentTurn.ToString() + "\n"; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (Board[i, j] != null) { Checker checker = Board[i, j]; state += $"{checker.Color}|{checker.King}|{checker.Coords.X}|{checker.Coords.Y}\n"; } } } return(state); }
private void ProcessTurns() { List <GameMessage> messages; while (true) { InfoLog.WriteInfo("Waiting for new turn", EPrefix.SimulationInfo); _nextTurnSemaphore.WaitOne(); //wait for MessageTurn if (_abort) { Thread.CurrentThread.IsBackground = true; this._turnProcessor = null; return; } lock (_turns.SyncRoot) { _currentTurn++; messages = _currentMessages.Dequeue(); } InfoLog.WriteInfo("Turn: " + CurrentTurn.ToString(), LogFiles.ProcessMsgLog); turnAsk = Environment.TickCount; if (onTurnBegin != null) { onTurnBegin(); } int turnStart = Environment.TickCount; foreach (GameMessage gm in messages) { InfoLog.WriteInfo(gm.ToString(), LogFiles.ProcessMsgLog); if (gm.Type == MessageType.CreateUnit) { this.onMessageCreate((CreateUnitMessage)gm); } else if (gm.Type == MessageType.Build) { this.OnMessageBuild((BuildMessage)gm); } else if (gm.Type == MessageType.Move) { this.onMessageMove((MoveMessage)gm); } else if (gm.Type == MessageType.Attack) { this.onMessageAttack((AttackMessage)gm); } else if (gm.Type == MessageType.Destroy) { this.onMessageDestroy((DestroyMessage)gm); } else if (gm.Type == MessageType.Harvest) { this.onMessageHarvest((HarvestMessage)gm); } else if (gm.Type == MessageType.DeployMCV) { this.onMessageDeployMCV((GMDeployMCV)gm); } else if (gm.Type == MessageType.BuildUnitMessage) { this.onMessageBuildUnit((BuildUnitMessage)gm); } else if (gm.Type == MessageType.PlayerDisconnected) { this.onMessagePlayerDisconnected((GameNumericMessage)gm); } else { throw new NotImplementedException("This message type is not supported! Refer to Simulation.cs"); } } //process all units & building & animations foreach (Player p in players.Values) { List <Ammo> ammos = p.GetAllAmmos(); foreach (Ammo a in ammos) { a.DoAI(); } } foreach (Player p in players.Values) { //get copy of buildings' list buildingsToProcess = p.GetAllBuildings(); //while there are unprocessed buildings while (buildingsToProcess.Count != 0) { Building b = buildingsToProcess[0]; buildingsToProcess.RemoveAt(0); handleBuilding(b); } unitsToProcess = p.GetAllUnits(); while (unitsToProcess.Count != 0) { Unit u = unitsToProcess[0]; unitsToProcess.RemoveAt(0); handleUnit(u); } } sandwormToProcess = new List <Unit>(sandworms.Values); while (sandwormToProcess.Count != 0) { Unit u = sandwormToProcess[0]; sandwormToProcess.RemoveAt(0); handleUnit(u); } //this.fastTurnProcessing = true; int remainingTime = Simulation.turnLength - (Environment.TickCount - turnStart); //if (!this._fastTurnProcessing) { //in server - just do turn, don't wait if (SpeedUp) { --_speedUpLength; remainingTime = (int)(remainingTime * 0.8); } if (remainingTime > 0) { Thread.Sleep(remainingTime); } //} //InfoLog.WriteInfo((Environment.TickCount - turnStart).ToString(), EPrefix.SimulationInfo); InfoLog.WriteInfo("OnTurnEnd begin", EPrefix.SimulationInfo); if (this.onTurnEnd != null) { this.onTurnEnd(); } StringBuilder sb = new StringBuilder(""); foreach (Player p in players.Values) { sb.Append(" Player " + p.Id + " : " + p.Credits); } InfoLog.WriteInfo(sb.ToString(), EPrefix.BMan); InfoLog.WriteInfo("OnTurnEnd end", EPrefix.SimulationInfo); InfoLog.WriteInfo("********* TURN " + this.CurrentTurn + " END *********", EPrefix.Test); recordFullSimulationState(_currentTurn); } // writer.Close(); // fs.Close(); }