예제 #1
0
 /// <summary>
 /// Mevcut oyunu bitirir.
 /// </summary>
 private void FinishGame(bool isWin, GameFinishType finishType, bool isAborted = false)
 {
     if (!IsGameStarted)
     {
         return;
     }
     IsGameStarted = false;
     OnGameFinished(isWin, finishType, isAborted);
 }
예제 #2
0
        public void RunCode(string[] firstPlayerCode, string[] secondPlayerCode, string pathToField, GameFinishType finishType, IEnumerable <BLL.Models.Bot> bots1, IEnumerable <BLL.Models.Bot> bots2, int finalX = 0, int finalY = 0)
        {
            CompilationResult compResult1 = compiler.CompileCode(TaskParameters.Build(firstPlayerCode.Length), firstPlayerCode);
            CompilationResult compResult2 = compiler.CompileCode(TaskParameters.Build(secondPlayerCode.Length), secondPlayerCode);

            if (!compResult1.IsCodeCorrect || !compResult2.IsCodeCorrect)
            {
                throw new ArgumentException("Unable to compile code");
            }

            FieldBuilder fieldBuilder = new FieldBuilder(pathToField);

            Runner.CodeRunners.Models.Field field = fieldBuilder.GetFieldForRunner();
            field = fieldBuilder.PlaceBots(field, bots1.Select(b => new Models.Bot(b.X, b.Y, b.Name)), 1);
            field = fieldBuilder.PlaceBots(field, bots2.Select(b => new Models.Bot(b.X, b.Y, b.Name)), 2);

            FinishGameCondition finishCondition = null;

            if (finishType == GameFinishType.CommandsNumber)
            {
                finishCondition = new CommandNumberCondition();
            }
            else
            {
                finishCondition = new BotOnPointCondition(finalX, finalY);
            }

            IEnumerable <Runner.CodeRunners.Models.Bot> runnerBots1 = bots1.Select(mapper.Map <Runner.CodeRunners.Models.Bot>);
            IEnumerable <Runner.CodeRunners.Models.Bot> runnerBots2 = bots2.Select(mapper.Map <Runner.CodeRunners.Models.Bot>);

            runner.RunCodeGame(compResult1.InformationForCodeRunner, compResult2.InformationForCodeRunner, field, runnerBots1, runnerBots2, finishCondition);

            runner.GameFinished += Runner_GameFinished;
        }
예제 #3
0
 public GameFinishedEventArgs(bool isWin, GameFinishType finishType, bool isAborted)
 {
     this.IsWin      = isWin;
     this.FinishType = finishType;
     this.IsAborted  = isAborted;
 }
예제 #4
0
 /// <summary>
 /// Oyunun bitiş olayını tetiklettirir.
 /// </summary>
 private void OnGameFinished(bool isWin, GameFinishType finishType, bool isAborted)
 {
     GameFinished?.Invoke(this, new GameFinishedEventArgs(isWin, finishType, isAborted));
 }