From 7b6452c695e408ecebfca1c9d810baf6eca03620 Mon Sep 17 00:00:00 2001 From: Eugene Blikh Date: Tue, 28 Apr 2026 04:21:30 +0300 Subject: [PATCH] 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 --- ship.go | 13 +++++++++++++ ship_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 ship_test.go diff --git a/ship.go b/ship.go index 4b78b4986b3971fcb408351bf0983bd227c5011d..35d5338bc84c73a75093c7992128141bfdf3cb24 100644 --- a/ship.go +++ b/ship.go @@ -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. diff --git a/ship_test.go b/ship_test.go new file mode 100644 index 0000000000000000000000000000000000000000..72bb4f35aa58dc904a889831d515806e76db6078 --- /dev/null +++ b/ship_test.go @@ -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) + } + } +}