public void ExecuteInstructions_Works_Correctly(string str, string separator, int result) { var ship = new Ship2(); ship.ExecuteInstructions(Parser.ParseInstructions(str, separator)); Assert.That(ship.ManhattanDistance, Is.EqualTo(result)); }
public void Part_2_example() { var ship = new Ship2(); Assert.Equal((0, 0), (ship.Position.EastWestPosition, ship.Position.NorthSouthPosition)); Assert.Equal((10, 1), (ship.Waypoint.EastWestPosition, ship.Waypoint.NorthSouthPosition)); ship.Move('F', 10); Assert.Equal((100, 10), (ship.Position.EastWestPosition, ship.Position.NorthSouthPosition)); Assert.Equal((10, 1), (ship.Waypoint.EastWestPosition, ship.Waypoint.NorthSouthPosition)); ship.Move('N', 3); Assert.Equal((100, 10), (ship.Position.EastWestPosition, ship.Position.NorthSouthPosition)); Assert.Equal((10, 4), (ship.Waypoint.EastWestPosition, ship.Waypoint.NorthSouthPosition)); ship.Move('F', 7); Assert.Equal((170, 38), (ship.Position.EastWestPosition, ship.Position.NorthSouthPosition)); Assert.Equal((10, 4), (ship.Waypoint.EastWestPosition, ship.Waypoint.NorthSouthPosition)); ship.Move('R', 90); Assert.Equal((170, 38), (ship.Position.EastWestPosition, ship.Position.NorthSouthPosition)); Assert.Equal((4, -10), (ship.Waypoint.EastWestPosition, ship.Waypoint.NorthSouthPosition)); ship.Move('F', 11); Assert.Equal((214, -72), (ship.Position.EastWestPosition, ship.Position.NorthSouthPosition)); Assert.Equal((4, -10), (ship.Waypoint.EastWestPosition, ship.Waypoint.NorthSouthPosition)); Assert.Equal(286, Part2(Example)); }
/// <summary> /// Initializes a new instance of the <see cref="LevelOne" /> class. /// </summary> public LevelOne() { // Backgrounds FileName = @"Assets\LevelOne.png"; // Enemies for (int i = 0; i < 7; i++) { var ship = new Ship(this); int positionY = ship.Height + 10; int positionX = 150 + i * (ship.Width + 50); ship.Position = new Point(positionX, positionY); Actors.Add(ship); } // Enemies2 for (int i = 0; i < 5; i++) { var ship2 = new Ship2(this); int positionY1 = ship2.Height + 30; int positionX1 = 180 + i * (ship2.Width + 50); ship2.Position = new Point(positionX1, positionY1); Actors.Add(ship2); } for (int i = 0; i < 4; i++) { var ship3 = new Ship3(this); int positionY = ship3.Height + 70; int positionX = 180 + i * (ship3.Width + 50); ship3.Position = new Point(positionX, positionY); //присваиваем значение Ship куда он должен лететь true false ship3.Movement = i < 2; Actors.Add(ship3); } // Player Player = new PlayerShip(this); int playerPositionX = Size.Width / 2 - Player.Width / 2; int playerPositionY = Size.Height - Player.Height - 50; Player.Position = new Point(playerPositionX, playerPositionY); Actors.Add(Player); var superm = new Superman(this); int positionYS = superm.Height + 10; int positionXS = superm.Width + 10; superm.Position = new Point(positionXS, positionYS); Actors.Add(superm); }
public override void Update() { Count += Time.deltaTime; if (Count >= 5 && !exit) { Ship2.GetComponent <SteeringBehaviours>().turnOffAll(); Ship2.SetActive(false); Ship2.gameObject.SetActive(false); //Ship2.renderer.enabled = false; exit = true; } }
private static long Part2(ReadOnlyMemory <string> input) { var ship = new Ship2(); foreach (var line in input) { var(action, value) = Parse(line); ship.Move(action, value); } return(Math.Abs(ship.Position.EastWestPosition) + Math.Abs(ship.Position.NorthSouthPosition)); }
/// <summary> /// Initializes a new instance of the <see cref="LevelOne" /> class. /// </summary> public LevelOne() { // Backgrounds FileName = @"Assets\LevelOne.png"; //// Enemies for (int i = 0; i < 5; i++) { var ship = new Ship(this); int positionY = ship.Height + 10; int positionX = 150 + i * (ship.Width + 50); ship.Position = new Point(positionX, positionY); Actors.Add(ship); } for (int i = 0; i < 1; i++) { var Thunderbolt = new Thunderbolt(this); int positionY = Thunderbolt.Height + 200; int positionX = 170 + i * (Thunderbolt.Width + 100); Thunderbolt.Position = new Point(positionX, positionY); Actors.Add(Thunderbolt); } for (int i = 0; i < 4; i++) { var ship2 = new Ship2(this); int positionY = ship2.Height + 50; int positionX = 170 + i * (ship2.Width + 100); ship2.Position = new Point(positionX, positionY); Actors.Add(ship2); } for (int i = 0; i < 3; i++) { var starOfDeathShip = new StarOfDeathShip(this); int positionY = starOfDeathShip.Height + 90; int positionX = 160 + i * (starOfDeathShip.Width + 120); starOfDeathShip.Position = new Point(positionX, positionY); Actors.Add(starOfDeathShip); } // Player Player = new PlayerShip(this); int playerPositionX = Size.Width / 2 - Player.Width / 2; int playerPositionY = Size.Height - Player.Height - 50; Player.Position = new Point(playerPositionX, playerPositionY); Actors.Add(Player); }
public static Port fromDynamic(dynamic json) { Port port = new Port(); port.material = Material.fromDynamic(json.api_material); port.deck_port = Deck.fromDynamic(json.api_deck_port); port.ndock = NDock.fromDynamic(json.api_ndock); port.ship = Ship2.fromDynamic(json.api_ship); port.basic = Basic.fromDynamic(json.api_basic); port.log = Log.fromDynamic(json.api_log); port.combined_flag = (int)json.api_combined_flag == 1; port.p_bgm_id = (int)json.api_p_bgm_id; return(port); }
private void StartGameButtonHandler(object sender, EventArgs e) //кнопка для начала игры { //скрытие всех начальных элементов формы StartGameButton.Hide(); Ship1.Hide(); Ship2.Hide(); Ship3.Hide(); Ship4.Hide(); Ship5.Hide(); Ship6.Hide(); MartianBattleLabel.Hide(); //определение управляющего объекта m_controlGame = new Controller(this, NumbersOfLives, Platform, new TextBox[] { Ship1, Ship2, Ship3, Ship4, Ship5, Ship6 }); m_controlGame.StartGame(); //запуск игры }
static void Main(string[] args) { IEnumerable <Move> moves = File.ReadLines("../../../input.txt") .Select(Move.Parse); Ship final = moves.Aggregate(new Ship() { Heading = new Point(1, 0), Pos = new Point(0, 0) }, (ship, move) => ship.Move(move)); Console.WriteLine(Math.Abs(final.Pos.X) + Math.Abs(final.Pos.Y)); Ship2 final2 = moves.Aggregate(new Ship2() { Waypoint = new Point(10, -1), Pos = new Point(0, 0) }, (ship, move) => ship.Move(move)); Console.WriteLine(Math.Abs(final2.Pos.X) + Math.Abs(final2.Pos.Y)); }
public override void Start() { Params.Load("default.txt"); // Setting the inital starting position of the leader ship leader = CreateBoid(new Vector3(-87, 2.4f, 386), leaderPrefab); // Setting the scale of the ship leader.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); // Setting the initial starting position of the random walk target leader.GetComponent <SteeringBehaviours> ().randomWalkTarget = leader.transform.position; leader.GetComponent <SteeringBehaviours> ().RandomWalkEnabled = true; leader.GetComponent <SteeringBehaviours> ().ObstacleAvoidanceEnabled = true; // The same as above for different ship and different location Ship2 = CreateBoid(new Vector3(-85.0f, 2.4f, 386), Ship2Prefab); Ship2.transform.localScale = new Vector3(0.015f, 0.015f, 0.015f); Ship2.GetComponent <SteeringBehaviours> ().randomWalkTarget = Ship2.transform.position; Ship2.GetComponent <SteeringBehaviours> ().RandomWalkEnabled = true; Ship2.GetComponent <SteeringBehaviours> ().ObstacleAvoidanceEnabled = true; //CreateCamFollower(boid, new Vector3(0, 5, -10)); }
/// <summary> /// Initializes a new instance of the <see cref="LevelOne" /> class. /// </summary> public LevelOne() { // Backgrounds FileName = @"Assets\LevelOne.png"; // Enemies for (int i = 0; i < 5; i++) { var ship = new Ship(this); int positionY = ship.Height + 10; int positionX = 150 + i * (ship.Width + 50); ship.Position = new Point(positionX, positionY); Actors.Add(ship); } // Enemies2 for (int i = 0; i < 5; i++) { var ship2 = new Ship2(this); int positionY = ship2.Height + 30; int positionX = 180 + i * (ship2.Width + 50); ship2.Position = new Point(positionX, positionY); Actors.Add(ship2); } // Player Player = new PlayerShip(this); int playerPositionX = Size.Width / 2 - Player.Width / 2; int playerPositionY = Size.Height - Player.Height - 50; Player.Position = new Point(playerPositionX, playerPositionY); Actors.Add(Player); }
public override void Start() { Params.Load("default.txt"); leader = CreateBoid(new Vector3(-20, 5, 50), leaderPrefab); Ship2 = CreateBoid(new Vector3(-100, 0, 100), Ship2Prefab); GameObject ship3 = CreateBoid(new Vector3(-100, 0, 0), Ship2Prefab); if (initialPos == Vector3.zero && initialPos2 == Vector3.zero) { initialPos = leader.transform.position; Debug.Log(initialPos); initialPos2 = Ship2.transform.position; } Path path = leader.GetComponent <SteeringBehaviours>().path; Path path2 = Ship2.GetComponent <SteeringBehaviours>().path; Path path3 = ship3.GetComponent <SteeringBehaviours> ().path; leader.GetComponent <SteeringBehaviours>().path.Waypoints.Add(initialPos); Ship2.GetComponent <SteeringBehaviours>().path.Waypoints.Add(initialPos2); //path.Waypoints.Add(initialPos + new Vector3(-50, 0, 80)); //path.Waypoints.Add(initialPos + new Vector3(0, 0, 160)); //path.Waypoints.Add(initialPos + new Vector3(200, 0, 80)); path.Waypoints.Add(initialPos + new Vector3(0, 0, 80)); path.Waypoints.Add(initialPos + new Vector3(20, 0, 120)); path.Waypoints.Add(initialPos + new Vector3(20, 0, 200)); path.Waypoints.Add(initialPos + new Vector3(0, 0, 240)); path.Waypoints.Add(initialPos + new Vector3(0, 0, 320)); path.Waypoints.Add(initialPos + new Vector3(20, 0, 360)); path.Waypoints.Add(initialPos + new Vector3(150, 0, 380)); path.Waypoints.Add(initialPos + new Vector3(150, 0, 0)); path.Looped = true; path.draw = true; leader.GetComponent <SteeringBehaviours>().turnOffAll(); leader.GetComponent <SteeringBehaviours> ().FollowPathEnabled = true; leader.GetComponent <SteeringBehaviours> ().ObstacleAvoidanceEnabled = true; path2.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 0)); path2.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 100)); path2.Waypoints.Add(initialPos2 + new Vector3(-40, 0, 120)); path2.Waypoints.Add(initialPos2 + new Vector3(-40, 0, 200)); path2.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 240)); path2.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 320)); path2.Waypoints.Add(initialPos2 + new Vector3(-40, 0, 360)); path2.Waypoints.Add(initialPos2 + new Vector3(-20, 0, 380)); path2.Waypoints.Add(initialPos2 + new Vector3(40, 0, 0)); path2.Looped = true; path2.draw = true; Ship2.GetComponent <SteeringBehaviours>().turnOffAll(); Ship2.GetComponent <SteeringBehaviours> ().FollowPathEnabled = true; Ship2.GetComponent <SteeringBehaviours> ().ObstacleAvoidanceEnabled = true; path3.Waypoints.Add(initialPos2 + new Vector3(40, 0, 0)); path3.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 0)); path3.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 100)); path3.Waypoints.Add(initialPos2 + new Vector3(-40, 0, 120)); path3.Waypoints.Add(initialPos2 + new Vector3(-40, 0, 200)); path3.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 240)); path3.Waypoints.Add(initialPos2 + new Vector3(-60, 0, 320)); path3.Waypoints.Add(initialPos2 + new Vector3(-40, 0, 360)); path3.Waypoints.Add(initialPos2 + new Vector3(-20, 0, 380)); path3.Waypoints.Add(initialPos2 + new Vector3(40, 0, 0)); path3.Looped = true; path3.draw = true; ship3.GetComponent <SteeringBehaviours>().turnOffAll(); ship3.GetComponent <SteeringBehaviours> ().FollowPathEnabled = true; ship3.GetComponent <SteeringBehaviours> ().ObstacleAvoidanceEnabled = true; /*int fleetSize = 5; * float xOff = 12; * float zOff = -12; * for (int i = 2; i < fleetSize; i++) * { * for (int j = 0; j < i; j++) * { * float z = (i - 1) * zOff; * Vector3 offset = new Vector3((xOff * (-i / 2.0f)) + (j * xOff), 0, z); * GameObject fleet = CreateBoid(Ship2.transform.position + offset, Ship2Prefab); * fleet.GetComponent<SteeringBehaviours>().Ship2 = Ship2; * fleet.GetComponent<SteeringBehaviours>().offset = offset; * fleet.GetComponent<SteeringBehaviours>().turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); * fleet.GetComponent<SteeringBehaviours>().seekTargetPos = new Vector3(0, 0, 450); * fleet.GetComponent<SteeringBehaviours>().turnOn(SteeringBehaviours.behaviour_type.offset_pursuit); * fleet.GetComponent<SteeringBehaviours>().turnOn(SteeringBehaviours.behaviour_type.separation); * fleet.GetComponent<SteeringBehaviours>().turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); * } * }*/ if (Application.loadedLevel == 5) { CreateCamFollower(leader, new Vector3(0, 50, -70)); } GroundEnabled(true); }
void Awake() { Index = PlayerPrefs.GetInt("ShipSelection"); Ship0 = GameObject.Find("Ship0"); Ship1 = GameObject.Find("Ship1"); Ship2 = GameObject.Find("Ship2"); Ship3 = GameObject.Find("Ship3"); Ship4 = GameObject.Find("Ship4"); Ship5 = GameObject.Find("Ship5"); if (Index == 0) { Ship0.SetActive(true); Ship1.SetActive(false); Ship2.SetActive(false); Ship3.SetActive(false); Ship4.SetActive(false); Ship5.SetActive(false); Player = GameObject.Find("Ship0"); } if (Index == 1) { Ship0.SetActive(false); Ship1.SetActive(true); Ship2.SetActive(false); Ship3.SetActive(false); Ship4.SetActive(false); Ship5.SetActive(false); Player = GameObject.Find("Ship1"); } if (Index == 2) { Ship0.SetActive(false); Ship1.SetActive(false); Ship2.SetActive(true); Ship3.SetActive(false); Ship4.SetActive(false); Ship5.SetActive(false); Player = GameObject.Find("Ship2"); } if (Index == 3) { Ship0.SetActive(false); Ship1.SetActive(false); Ship2.SetActive(false); Ship3.SetActive(true); Ship4.SetActive(false); Ship5.SetActive(false); Player = GameObject.Find("Ship3"); } if (Index == 4) { Ship0.SetActive(false); Ship1.SetActive(false); Ship2.SetActive(false); Ship3.SetActive(false); Ship4.SetActive(true); Ship5.SetActive(false); Player = GameObject.Find("Ship4"); } if (Index == 5) { Ship0.SetActive(false); Ship1.SetActive(false); Ship2.SetActive(false); Ship3.SetActive(false); Ship4.SetActive(false); Ship5.SetActive(true); Player = GameObject.Find("Ship5"); } }