Ejemplo n.º 1
0
 public void DrawRover(int _x, int _y, Rover.Direction _dir)
 {
     PosX = _x;
     PosY = _y;
     Dir  = _dir;
     transform.position = new Vector3(PosX, transform.position.y, PosY);
     if (Dir == Rover.Direction.N)
     {
         transform.localEulerAngles = Vector3.zero;
     }
     else if (Dir == Rover.Direction.E)
     {
         transform.localEulerAngles = new Vector3(0, 90, 0);
     }
     else if (Dir == Rover.Direction.W)
     {
         transform.localEulerAngles = new Vector3(0, -90, 0);
     }
     else if (Dir == Rover.Direction.S)
     {
         transform.localEulerAngles = new Vector3(0, 180, 0);
     }
 }
Ejemplo n.º 2
0
    void InitMars()
    {
        Debug.Log(configFile.text);

        bool hasReadFirstLine = false;
        bool hasNewRover      = false;

        foreach (var line in configFile.text.Split('\n'))
        {
//			Debug.Log("line:" + line);
            string trimedLine = line.Trim();
            if (!hasReadFirstLine)
            {
                Width  = int.Parse(trimedLine.Split(',')[0]);
                Height = int.Parse(trimedLine.Split(',')[1]);
                Map    = new int[Width, Height];
                for (int i = 0; i < Width; ++i)
                {
                    for (int j = 0; j < Height; ++j)
                    {
                        Map[i, j] = FLOOR;
                    }
                }
                hasReadFirstLine = true;
            }
            else
            {
                if (!hasNewRover)
                {
                    hasNewRover = true;
                    string[]        roverDetails = trimedLine.Split(',');
                    int             x            = int.Parse(roverDetails[0]);
                    int             y            = int.Parse(roverDetails[1]);
                    Rover.Direction dir          = (Rover.Direction)Enum.Parse(typeof(Rover.Direction), roverDetails[2]);

                    GameObject newRover = Instantiate(roverPrefab) as GameObject;
                    newRover.name = "Rover" + (Rovers.Count + 1);
                    Rover newRoverScript = newRover.GetComponent <Rover>();
                    newRoverScript.DrawRover(x, y, dir);
                    Rovers.Add(newRoverScript);
                    Map[x, y] = ROVER;
                }
                else
                {
                    Rover.Command[] commands = new Rover.Command[trimedLine.Length];
                    for (int i = 0; i < trimedLine.Length; ++i)
                    {
                        //						Debug.Log(trimedLine[i]);
                        commands[i] = (Rover.Command)Enum.Parse(typeof(Rover.Command), trimedLine[i].ToString());
                    }
                    Rovers[Rovers.Count - 1].SetRoverCommands(commands);
                    hasNewRover = false;
                }
            }
        }

        if (hasNewRover)
        {
            Debug.LogError("Config file format error!");
            return;
        }
    }