adapter

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package adapter implements the Adapter design pattern. The space ship uses the default KeyPanel controller which conforms to a common Controller interface to receive the input from the pilot. A new joystick-style controller, SpaceStick, is introduced with its own incompatible interface. The StickToKeysAdapter adapts the SpaceStick to the legacy Controller interface, allowing the pilot to control the ship as if using the original controls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type Controller

type Controller interface {
	Up()
	Down()
	Left()
	Right()
}

Controller is the common interface expected for the ship's controller

type KeyPanel

type KeyPanel struct{}

KeyPanel is the standard main controller for the ship

func (*KeyPanel) Down

func (kp *KeyPanel) Down()

Down moves ship backward

func (*KeyPanel) Left

func (kp *KeyPanel) Left()

Left tilts ship to the left

func (*KeyPanel) Right

func (kp *KeyPanel) Right()

Right tilts ship to the right

func (*KeyPanel) Up

func (kp *KeyPanel) Up()

Up moves ship forward

type Ship

type Ship struct {
	Name    string
	Control Controller
}

Ship represents a space ship

type SpaceStick

type SpaceStick struct{}

SpaceStick is the new modern controller with the custom interface

func (*SpaceStick) Touch

func (s *SpaceStick) Touch(direction uint)

Touch moves the object in the corresponding direction

type StickToKeysAdapter

type StickToKeysAdapter struct {
	// contains filtered or unexported fields
}

StickToKeysAdapter is the interface, that implements Controller interface for the new type of joystick controllers

func (*StickToKeysAdapter) Down

func (a *StickToKeysAdapter) Down()

Down moves ship backward

func (*StickToKeysAdapter) Left

func (a *StickToKeysAdapter) Left()

Left tilts ship to the left

func (*StickToKeysAdapter) Right

func (a *StickToKeysAdapter) Right()

Right tilts ship to the right

func (*StickToKeysAdapter) Up

func (a *StickToKeysAdapter) Up()

Up moves ship forward

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL