# Nathan Hinton 2 Oct 2025 # This class will be the container for ships. For now they are all the same class Ship def initialize(x_pos, y_pos) @position = [x_pos, y_pos] @speed = 0.1 end # Called every game tick def tick if @moving != [0, 0] end end # Move function. This will move a ship. For now you can only move one hop, # there is no way to move more than one at the moment. This position should # be only *one* spot away from where we are. # # @param x_pos [Integer] The target x position # @param y_pos [Integer] The target y position def move(x_pos, y_pos) #Validate coordinates: if (x_pos + y_pos).odd? raise ArgumentError.new('The x, y coordinate for movement must add to be even!') end # Ensure we are not too far: if ((x_pos + y_pos) - @position.sum).abs != 2 raise ArgumentError.new('The x, y coordinates for moevement must be to an adjcent space!') end end # Function move # Move_direction. Takes a direction and then sets the moving variable equal that direction. # # @param direction [Integer] A value between (0, 5) that determines the direction (think unit circle) def move_direction(direction) if (direction < 0 || direction > 5) raise ArgumentError.new('When moving using direction based movement, x must be between (0..5)!') end # This means that the direction can range from 0 to 5 (think of unit circle) case direction when 0 @moving = [2, 0] # Right when 1 @moving = [1, 1] # Right up when 2 @moving = [-1, 1] # Left up when 3 @moving = [-2, 0] # Left when 4 @moving = [-1, -1] # Left down when 5 @moving = [1, -1] # Right down end end # Function move_direction end