예제 #1
0
 void Awake()
 {
     exitGate = FindObjectOfType <ExitGate>();
     if (exitGate == null)
     {
         Debug.LogError("No ExitGate found.");
     }
 }
예제 #2
0
        public void DoWork()
        {
            List <Mine>   mines       = new List <Mine>();
            List <string> commandList = new List <string>();
            List <Result> resultList  = new List <Result>();

            var textRows = _readFile.GetFile(_pathSetting.Value.GameCommandTextPath);

            if (textRows.Length == 0)
            {
                throw new FileNotFoundException("File not found or file is empty, please check");
            }

            var boardPosition    = Array.ConvertAll(textRows[0].Split(' '), int.Parse);
            var minesPositions   = textRows[1].Split(' ').ToList();
            var exitGatePosition = Array.ConvertAll(textRows[2].Split(' '), int.Parse);
            var turtlePosition   = textRows[3].Split(' ').ToList();

            for (int i = 4; i < textRows.Length; i++)
            {
                commandList.Add(textRows[i]);
            }


            var board = _boardService.CreateBoard(boardPosition[0], boardPosition[1]);

            foreach (var minePosition in minesPositions)
            {
                var mine = _mineService.CreateMine(Convert.ToInt32(minePosition.Split(',')[0]), Convert.ToInt32(minePosition.Split(',')[1]));

                if (!_boardService.CheckIfPointInsideTheBoard(board, mine.Location))
                {
                    throw new MineOutOfBoardException("Mines can not be out of minefield, please correct the command text file and retry!");
                }

                mines.Add(mine);
            }

            var exitGate = new ExitGate(exitGatePosition[0], exitGatePosition[1]);
            var turtle   = _turtleService.CreateTurtle(Convert.ToInt32(turtlePosition[0]), Convert.ToInt32(turtlePosition[1]), turtlePosition[2]);

            if (!board.CheckIfPointInside(turtle.Position.Location))
            {
                Console.WriteLine("Turtle can not be out of minefield, please correct the command text file and retry!");
                return;
            }
            foreach (var command in commandList)
            {
                resultList.Add(_turtleService.ApplyCommand(command, exitGate, mines, board, turtle));
                turtle = new Turtle(Convert.ToInt32(turtlePosition[0]), Convert.ToInt32(turtlePosition[1]), turtlePosition[2]);
            }


            foreach (var result in resultList)
            {
                Console.WriteLine(result);
            }
        }
예제 #3
0
파일: Gates.cs 프로젝트: psydox/OpenMU
        private EnterGate CreateEnterGate(short number, ExitGate targetGate, byte x1, byte y1, byte x2, byte y2, short levelRequirement)
        {
            var enterGate = this.Context.CreateNew <EnterGate>();

            enterGate.Number           = number;
            enterGate.LevelRequirement = levelRequirement;
            enterGate.TargetGate       = targetGate;
            enterGate.X1 = x1;
            enterGate.Y1 = y1;
            enterGate.X2 = x2;
            enterGate.Y2 = y2;
            enterGate.LevelRequirement = levelRequirement;
            return(enterGate);
        }
예제 #4
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.name == "player")
     {
         xa.goal1 = 1;
         if (xa.levelNumber == 1)
         {
             reinforcements = GameObject.FindGameObjectsWithTag("Reinforce");
             foreach (GameObject obj in reinforcements)
             {
                 obj.tag = "Enemy";
                 obj.GetComponent <SpriteRenderer> ().enabled = true;
             }
         }
         //4-23
         goalSound.Play();
         showMsg = true;
         if (GameObject.Find("F") != null)
         {
             //4-23
             goalSound.Play();
             GameObject.Find("F").GetComponent <SpriteRenderer> ().enabled = true;
             GameObject.Find("F").GetComponent <BoxCollider> ().enabled    = true;
         }
         if (GameObject.Find("G") != null)
         {
             //4-23
             goalSound.Play();
             GameObject.Find("G").GetComponent <SpriteRenderer> ().enabled = true;
             GameObject.Find("G").GetComponent <BoxCollider> ().enabled    = true;
         }
         if (GameObject.Find("S") != null)
         {
             //4-23
             goalSound.Play();
             GameObject.Find("S").GetComponent <SpriteRenderer> ().enabled = true;
             GameObject.Find("S").GetComponent <BoxCollider> ().enabled    = true;
         }
         ExitGate.Show();
         Destroy(gameObject);
         enemymovement.enemy_moveSpeed = 6f;
     }
 }
예제 #5
0
        /// <inheritdoc/>
        protected override void DoHandleCommand(Player gameMaster, TraceChatCommandArgs arguments)
        {
            var player    = this.GetPlayerByCharacterName(gameMaster, arguments.CharacterName ?? string.Empty);
            var character = player.SelectedCharacter;

            if (character != null)
            {
                var characterLocation = new ExitGate
                {
                    Map = character.CurrentMap,
                    X1  = character.PositionX,
                    X2  = (byte)(character.PositionX + 2),
                    Y1  = character.PositionY,
                    Y2  = (byte)(character.PositionY + 2),
                };

                gameMaster.WarpTo(characterLocation);
            }
        }
예제 #6
0
        public Result ApplyCommand(string commandString, ExitGate exitGate, List <Mine> mines, Board board, Turtle turtle)
        {
            List <ICommand> commandList = new List <ICommand>();

            var commands = commandString.Split(' ').ToList().ConvertAll(x => (Action)Enum.Parse(typeof(Action), x));

            foreach (var item in commands)
            {
                switch (item)
                {
                case Action.L:
                    commandList.Add(new TurnLeft());
                    break;

                case Action.R:
                    commandList.Add(new TurnRight());
                    break;

                case Action.M:
                    commandList.Add(new Move(board));
                    break;

                default:
                    break;
                }
            }

            foreach (var command in commandList)
            {
                turtle.Position = command.Apply(turtle.Position);
                if (mines.Any(x => x.Location.X == turtle.Position.Location.X && x.Location.Y == turtle.Position.Location.Y))
                {
                    return(Result.MineHit);
                }
            }

            if (turtle.Position.Location.X == exitGate.Location.X && turtle.Position.Location.Y == exitGate.Location.Y)
            {
                return(Result.Success);
            }

            return(Result.StillInDanger);
        }
예제 #7
0
파일: Gates.cs 프로젝트: psydox/OpenMU
        private WarpInfo CreateWarpInfo(ushort index, string name, int costs, int levelRequirement, ExitGate gate)
        {
            var warpInfo = this.Context.CreateNew <WarpInfo>();

            warpInfo.Index            = index;
            warpInfo.Name             = name;
            warpInfo.Costs            = costs;
            warpInfo.LevelRequirement = levelRequirement;
            warpInfo.Gate             = gate;
            return(warpInfo);
        }