CAPE ELIZABETH — The players waited patiently in the hallway for someone to open their locker room so they could change for practice.

A few minutes later, Coach Jim Ray arrived and the players lined up for him to unlock the steel receptacle where the basketballs are stored. One by one, each player took a ball, then stepped onto the court to shoot before the start of practice.

Order, discipline: That’s the Cape way. No one player is above the team. There are no egos. It doesn’t matter who scores. Defense sets the tone. Admirers refer to the team’s style as “Ray ball.”

The Capers’ unrelenting defense – along with their willingness to share the basketball – will be on display Friday night in the Class B boys’ state championship game at Cross Insurance Arena.

Cape Elizabeth (18-3) will play Medomak Valley (19-2) of Waldoboro at 9 p.m.

With all five starters back from last season, the Capers knew they had the potential for a very good season. But it didn’t happen overnight. It’s been a gradual process with plenty of trial and error and tweaks before Ray molded the type of team he wanted.

“I was more optimistic going into this season than I usually am,” said Ray, who is in his 21st season. “The emphasis was on ‘could be good.’ ”

Preparation for the season doesn’t start on the first day of practice in November. It begins in the summer with practices and games against other local high schools.

Cape was very impressive against Class A opponents, losing only twice in approximately a dozen games.

Early in the summer league, Cape played weekend games against Bonny Eagle and Biddeford. The players said that’s when it all clicked.

“We were diving for loose balls, taking charges and trusting one another,” said point guard Ethan Murphy, one of the two senior starters. “We realized we had the potential to be very good.”

Those games impressed their hard-to-impress coach.

“I’m not a ‘wow’ type of guy,” said Ray. “But during those games I said, ‘Wow,’ to them during a timeout. All of a sudden we’re running and pressing, and nobody cares who puts the ball in the basket. It was a pleasure to watch them play team basketball. We’ve had to bust our butt to get where we are.”

Still, there were some bumps this winter. Midway through the season, Cape beat Gray-New Gloucester 71-58 at home. “We were OK but not great,” said Ray. “I told the players we have to be better.”

After that lackluster effort, Cape avenged a loss to Yarmouth – the eventual top seed in the Western Class B playoffs – by beating the Clippers 65-52 on the road.

“I knew we were one of the best teams after that win,” said junior guard Jack O’Rourke.

Cape won nine straight before losing 69-62 at Falmouth on Feb. 3. Both teams played well so the loss was easier to accept.

But not for Ray, who strives for excellence. Players know if they fall short, they’ll have a place on the bench.

“It starts with defense for us,” said Eddie Galvin, the other starting senior. “If I don’t take a charge when I have a chance, I know Coach Ray will take me out.”

The players have seen plenty of game film on Medomak Valley.

“They’re a lot like us. They share the basketball and don’t care who scores or gets the credit,” said Murphy.

At Wednesday’s practice, Ray emphasized how Medomak likes to take the charge, just like his team. “So you better be ready,” he said.

As Cape’s opponents have found out, it’s tough to concentrate on one or two of the starters and expect to shut them down.

Galvin is the leading scorer at 11.2 points per game. Murphy, junior center Justin Guerette and sophomore forward Quinn Hewitt are at 9.5 points per game while O’Rourke averages 7.7. Guerrette is the leading rebounder at 9.9 per game.

Here’s one indication of Cape’s balance: Murphy, who scored 20 points against Lake Region in the regional final en route to being named the tourney’s MVP, hadn’t scored that many points since a career-high 29 as a sophomore. Several of the Cape starters have scored at least 20 this season.

Cape has a deep bench that Ray isn’t hesitant to use. Freshman Finn Bowe, and juniors Marcus Donnelly and James Bottomley have received plenty of minutes in the tournament.

This is Cape’s fourth trip to the state final since 2008. The previous three ended in losses, twice to Camden Hills and once to Maranacook.

Galvin watched his stepbrother, John Messina, play for Cape in the first two losses. The school’s last basketball state title was in 1988 with a 70-54 victory against Ellsworth.

“We want to get some revenge,” said Galvin. “We want to bring one back.”