Example #1
0
        private static MovesSetting GetMovesSetting()
        {
            var defaultFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "moves.txt");

            var          path    = GetFilePath(defaultFile, "Move");
            MovesSetting setting = null;

            if (path != null)
            {
                setting = new MovesSetting(path);;
                setting.Load();
            }
            return(setting);
        }
Example #2
0
        private static void Play(MovesSetting moves)
        {
            foreach (var mv in moves.Moves)
            {
                GameIsFinished = false;

                game.Reset();
                processResultDesc = "In Danger";
                bool Error = false;;
                foreach (char chr in mv)
                {
                    if (GameIsFinished)
                    {
                        break;
                    }

                    if (chr == 'r')
                    {
                        try
                        {
                            System.Console.ForegroundColor = ConsoleColor.Green;
                            game.Rotate();
                        }
                        catch (Exception ex) { WriteError(" => Error: " + ex.Message); Error = true; break; }
                    }
                    else if (chr == 'm')
                    {
                        try
                        {
                            System.Console.ForegroundColor = ConsoleColor.Yellow;
                            game.Move();
                        }
                        catch (Exception ex) { WriteError(" => Error: " + ex.Message); Error = true; break; }
                    }
                    System.Console.Write(chr);
                }

                System.Console.ForegroundColor = ConsoleColor.White;
                if (!Error)
                {
                    System.Console.WriteLine(" =>   " + processResultDesc);
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            BoardSetting board = null;
            MovesSetting moves = null;

            try
            {
                board = GetBoardSetting();
                moves = GetMovesSetting();
            }
            catch (InvalidSettingException ex)
            {
                foreach (var item in ex.Errors)
                {
                    WriteError(item.ToString());
                }
            }

            game = null;
            if (board != null && moves != null)
            {
                try
                {
                    game = Game
                           .Create(board.BoardWithd, board.BoardHeight)
                           .LayMine(board.Mines)
                           .SetExitPoint(board.ExitPoint)
                           .AddTurtle(board.StartPoint, board.Direction, G_TurtleStatusChanged);
                }
                catch (Exception ex)
                {
                    WriteError(ex.Message);
                }
            }
            if (game != null)
            {
                Play(moves);
            }
            else
            {
                WriteError("Failur in running application!");
            }
            System.Console.ReadLine();
        }
Example #4
0
        private void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                movesSetting = new MovesSetting(moveFile);
                movesSetting.Load();



                boardSetting = new BoardSetting(boardFile);
                boardSetting.Load();
                current = boardSetting.StartPoint;
                CreateBoard(boardSetting);

                this.Width  = boardSetting.BoardWithd * 52 + 220;
                this.Height = boardSetting.BoardHeight * 52 + 40 + panel1.Height;
                this.Update();
                game = Engine.Game
                       .Create(boardSetting.BoardWithd, boardSetting.BoardHeight)
                       .LayMine(boardSetting.Mines)
                       .SetExitPoint(boardSetting.ExitPoint)
                       .AddTurtle(boardSetting.StartPoint, boardSetting.Direction, this.G_TurtleStatusChanged);

                ThreadPool.QueueUserWorkItem(s => Play());
            }
            catch (InvalidSettingException ex)
            {
                StringBuilder strb = new StringBuilder();
                strb.AppendLine(ex.Message);
                foreach (var item in ex.Errors)
                {
                    strb.AppendLine(item.ToString());
                }
                ShowError(strb.ToString());
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
        }