示例#1
0
    public void Destroy()
    {
        SessionTimer timer = GetComponent <SessionTimer>();

        timer.Stop();
        Destroy(gameObject);
    }
示例#2
0
 /// <summary>
 /// Called when paused status changes.
 /// </summary>
 /// <param name="isPaused">Paused status.</param>
 private void OnPausedChanged(bool isPaused)
 {
     if (isPaused)
     {
         SessionTimer.Stop();
     }
     else
     {
         SessionTimer.Start();
     }
 }
示例#3
0
 /// <summary>
 /// Called when the recording status changes.
 /// </summary>
 /// <param name="isRecording">Recording status.</param>
 private void OnRecordingChanged(bool isRecording)
 {
     if (!isRecording)
     {
         SessionTimer.Stop();
         Duration = 0;
     }
     else
     {
         SessionTimer.Start();
     }
 }
示例#4
0
        public virtual void Start()
        {
            Logger?.SetFileName(_logFileName);
            CurrentPlayer = Players[CurrentIndexer];
            NextPlayer    = Players[CurrentIndexer == 0 ? 1 : 0];

            DrawTable();

            string command = string.Empty;

            if (StartingCommands.Count != 0)
            {
                command = StartingCommands[0];
            }



            return;

            while (command != "quit" && command != "exit")
            {
                if (string.IsNullOrEmpty(command))
                {
                    ShowInfo();
                }
                else
                {
                    string[] commandArr = command.Split(' ');
                    if (commandArr.Length == 2 && commandArr[0].Length == 2 && commandArr[1].Length == 2)
                    {
                        command = $"play {command}";
                    }

                    if (command == "draw")
                    {
                        DrawTable();
                        if (Checkmate)
                        {
                            WriteError("Checkmate !!!");
                        }
                    }

                    if (command == "undo")
                    {
                        if (Checkmate)
                        {
                            WriteError("Checkmate !!!");
                        }

                        if (Checkmate == false && MovementInstructions.Keys.Count != 0)
                        {
                            var lastInstraction = GetLastMovement();
                            var lastResult      = MovementInstructions[lastInstraction];

                            if (lastResult.Eated != null)
                            {
                                CurrentPlayer.Stones.Add(lastResult.Eated);
                                PreviousPlayer.Eats.Remove(lastResult.Eated);
                            }

                            lastInstraction.MovingStone.ForceMove(lastInstraction.FromLocation);

                            SetPlayerReturn();

                            MovementInstructions.Remove(lastInstraction);
                            DrawTable();

                            SessionTimer.Restart();
                        }
                    }

                    if (Checkmate == false && command.StartsWith("play"))
                    {
                        var commandDetail = CommandResolver.Resolve(command);
                        if (commandDetail.IsCorrect == false)
                        {
                            WriteError(commandDetail.ReturnMessage);
                            command = WaitCommand();
                            continue;
                        }

                        var fromLocation = Table.GetLocation(commandDetail.From_X, commandDetail.From_Y);

                        var stone          = Table.Stones.GetFromLocation(fromLocation);
                        var targetLocation = Table.GetLocation(commandDetail.To_X, commandDetail.To_Y);

                        if (targetLocation == null)
                        {
                            WriteError("Location is not found!");
                            command = WaitCommand();
                            continue;
                        }

                        if (stone == null)
                        {
                            WriteError("Stone is not found at given location!");
                            command = WaitCommand();
                            continue;
                        }

                        var instraction = Instruction.CreateOne(stone, targetLocation, this, command);

                        var result = instraction.TryDo();
                        if (result.IsOK)
                        {
                            MovementInstructions.Add(instraction, result);

                            if (result.Eated != null)
                            {
                                CurrentPlayer.Eat(result.Eated);
                                Table.Stones.Remove(result.Eated);
                            }

                            if (result.CheckRemoved)
                            {
                                Check = false;
                            }

                            WriteMessage(result.Message);
                            IsCheck(stone);

                            SessionTimer.Stop();
                            CurrentPlayer.Duration += SessionTimer.ElapsedMilliseconds;

                            if (Checkmate)
                            {
                                DrawTable();
                                WriteEmpty();
                                WriteError("Checkmate !!!");
                            }
                            else
                            {
                                SetPlayerReturn();
                                DrawTable();

                                SessionTimer.Restart();
                            }
                        }
                        else
                        {
                            WriteError(result.Message);
                        }
                    }

                    if (command == "stat")
                    {
                        DrawStatistics();
                    }
                }

                if (StartingCommands.Count == 0)
                {
                    var lastMovementInstaction = GetLastMovement();
                    if (lastMovementInstaction != null)
                    {
                        WriteLastCommand(lastMovementInstaction.Log);
                    }

                    command = WaitCommand();
                }
                else
                {
                    var current = StartingCommands.First();
                    StartingCommands.Remove(current);
                    if (StartingCommands.Count != 0)
                    {
                        command = StartingCommands[0];
                    }
                    else
                    {
                        var lastMovementInstaction = GetLastMovement();
                        if (lastMovementInstaction != null)
                        {
                            WriteLastCommand(lastMovementInstaction.Log);
                        }
                        command = WaitCommand();
                    }
                }
            }

            Logger?.SaveInstructions(MovementInstructions.Where(m => m.Value.IsOK).Select(m => m.Key));
        }