O.C.P

This code is following O.C.P?
 avatar
unknown
php
a year ago
726 B
21
Indexable
<?php

class Game
{
    private function move(string $direction)
    {
        // loop logic that needs a index for different directions
    }

    private function getIndexFromDirection(int $counter1, int $counter2): int
    {
        return match ($direction) {
            'up' => , // logic
            'down' => , // logic
            'left' => , // logic
            'right' => , // logic
            default => , // exception
        };
    }

    public function up()
    {
        $this->move('up');
    }

    public function down()
    {
        $this->move('down');
    }

    public function left()
    {
        $this->move('left');
    }

    public function right()
    {
        $this->move('right');
    }
}
Editor is loading...
Leave a Comment