~bigbes/game-prototype-ftl

7b6452c695e408ecebfca1c9d810baf6eca03620 — Eugene Blikh 30 days ago cbe6e62
combat: NewEnemyShip layout

PH2 of combat task: enemy ship layout.

- ship.go: NewEnemyShip() returns same 5 rooms as NewPlayerShip
  with each GridX shifted +24 tiles. Pure data; no Ebitengine (IV1).
- ship_test.go: 2 tests covering room count and per-room shift
  (GridX +24, all other fields preserved).

Refs: docs/tasks/combat.md PH2
2 files changed, 61 insertions(+), 0 deletions(-)

M ship.go
A ship_test.go
M ship.go => ship.go +13 -0
@@ 31,6 31,19 @@ type Ship struct {
	Rooms []Room
}

// NewEnemyShip returns a 5-room layout that mirrors NewPlayerShip but with
// every room shifted +24 tiles along the X axis so the enemy ship sits on
// the right half of the virtual screen.
func NewEnemyShip() Ship {
	player := NewPlayerShip()
	rooms := make([]Room, len(player.Rooms))
	for i, r := range player.Rooms {
		r.GridX += 24
		rooms[i] = r
	}
	return Ship{Rooms: rooms}
}

// NewPlayerShip returns a hard-coded 5-room placeholder layout:
// Pilot front-left, Weapons mid-upper, Shields mid-center,
// MedBay mid-lower, Engines rear-right.

A ship_test.go => ship_test.go +48 -0
@@ 0,0 1,48 @@
package main

import "testing"

// TestNewEnemyShip_roomCount verifies that NewEnemyShip returns exactly 5 rooms.
func TestNewEnemyShip_roomCount(t *testing.T) {
	enemy := NewEnemyShip()
	if len(enemy.Rooms) != 5 {
		t.Fatalf("expected 5 rooms, got %d", len(enemy.Rooms))
	}
}

// TestNewEnemyShip_shifted verifies that each enemy room has GridX shifted by +24
// relative to the corresponding player room, while GridY/GridW/GridH/Role/Name
// are unchanged.
func TestNewEnemyShip_shifted(t *testing.T) {
	player := NewPlayerShip()
	enemy := NewEnemyShip()

	if len(enemy.Rooms) != len(player.Rooms) {
		t.Fatalf("room count mismatch: enemy %d, player %d", len(enemy.Rooms), len(player.Rooms))
	}

	for i := range player.Rooms {
		p := player.Rooms[i]
		e := enemy.Rooms[i]

		wantGridX := p.GridX + 24
		if e.GridX != wantGridX {
			t.Errorf("rooms[%d] GridX = %d, want %d (player %d + 24)", i, e.GridX, wantGridX, p.GridX)
		}
		if e.GridY != p.GridY {
			t.Errorf("rooms[%d] GridY = %d, want %d", i, e.GridY, p.GridY)
		}
		if e.GridW != p.GridW {
			t.Errorf("rooms[%d] GridW = %d, want %d", i, e.GridW, p.GridW)
		}
		if e.GridH != p.GridH {
			t.Errorf("rooms[%d] GridH = %d, want %d", i, e.GridH, p.GridH)
		}
		if e.Role != p.Role {
			t.Errorf("rooms[%d] Role = %v, want %v", i, e.Role, p.Role)
		}
		if e.Name != p.Name {
			t.Errorf("rooms[%d] Name = %q, want %q", i, e.Name, p.Name)
		}
	}
}