Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amateur golden point #76

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions resources/menus/number_of_deuces.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<menu id="DeucesMenu" title="Deuces">
<menu-item id="deuces_1" label="At 1st - Default" />
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
<menu-item id="deuces_2" label="At 2nd - Amateur" />
</menu>
10 changes: 8 additions & 2 deletions source/delegates/menu/menuGoldenPointDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ class MenuGoldenPointDelegate extends WatchUi.MenuInputDelegate {
}

Application.getApp().getMatchConfig().setGoldenPoint(goldenPoint);
WatchUi.pushView(new Rez.Menus.SetsMenu(), new MenuNumberSetsDelegate(), WatchUi.SLIDE_BLINK);

if (goldenPoint == false) {
WatchUi.pushView(new Rez.Menus.SetsMenu(), new MenuNumberSetsDelegate(), WatchUi.SLIDE_BLINK);
} else {
WatchUi.pushView(new Rez.Menus.DeucesMenu(), new MenuGoldenPointDeuceSettingsDelegate(), WatchUi.SLIDE_BLINK);
}

}

}
}
31 changes: 31 additions & 0 deletions source/delegates/menu/menuGoldenPointDeuceSettingsDelegate.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;

class MenuGoldenPointDeuceSettingsDelegate extends WatchUi.MenuInputDelegate {

function initialize() {
MenuInputDelegate.initialize();
}

function onMenuItem(item as Symbol) as Void {

var nbrDeuces = 1;

switch (item) {
case :deuces_1: {
nbrDeuces = 1;
break;
}
case :deuces_2: {
nbrDeuces = 2;
break;
}
}

Application.getApp().getMatchConfig().setNumberOfDeuces(nbrDeuces);
WatchUi.pushView(new Rez.Menus.SetsMenu(), new MenuNumberSetsDelegate(), WatchUi.SLIDE_BLINK);

}

}
78 changes: 70 additions & 8 deletions source/model/PadelMatch.mc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class PadelMatch {
private var numberOfSets;
private var superTie;
private var goldenPoint;
private var numberOfDeuces;

private var historicalScores;

Expand All @@ -17,6 +18,7 @@ class PadelMatch {
numberOfSets = config.getNumberOfSets();
superTie = config.getSuperTie();
goldenPoint = config.getGoldenPoint();
numberOfDeuces = config.getNumberOfDeuces();

matchStatus = MatchStatus.New();
prevMatchStatus = MatchStatus.New();
Expand Down Expand Up @@ -63,11 +65,41 @@ class PadelMatch {
// (mid game)

if (self.goldenPoint) {
// mid game
if (self.matchStatus.getP1Score() != 40) {
if (self.matchStatus.getP1Idx() > 3) { // winning phase
return incP1Game();
}

if (self.matchStatus.getP1Idx() < 3) { // less than 40
self.matchStatus.incP1Score();

if (self.matchStatus.getP1Score() == 40 && self.matchStatus.getP2Score() == 40) {
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
self.matchStatus.setGolden();
}
}
return false;
} else {
} else { // we are 40
if (self.matchStatus.getP2Idx() < 3) { // less than 40
return incP1Game();
}

if (self.matchStatus.getP2Idx() == 3) { // 40
self.matchStatus.incP1Score();
return false;
}

if (self.matchStatus.getP2Idx() > 3) { // Advantage
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
self.matchStatus.setGolden();
} else {
self.matchStatus.setDeuce();
}
return false;
}
return incP1Game();
}
} else {
Expand Down Expand Up @@ -143,11 +175,41 @@ class PadelMatch {
// (mid game)

if (self.goldenPoint) {
// mid game
if (self.matchStatus.getP2Score() != 40) {
if (self.matchStatus.getP2Idx() > 3) { // winning phase
return incP2Game();
}

if (self.matchStatus.getP2Idx() < 3) { // less than 40
self.matchStatus.incP2Score();

if (self.matchStatus.getP2Score() == 40 && self.matchStatus.getP1Score() == 40) {
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
self.matchStatus.setGolden();
}
}
return false;
} else {
} else { // we are 40
if (self.matchStatus.getP1Idx() < 3) { // less than 40
return incP2Game();
}

if (self.matchStatus.getP1Idx() == 3) { // 40
self.matchStatus.incP2Score();
return false;
}

if (self.matchStatus.getP1Idx() > 3) { // Advantage
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
self.matchStatus.setGolden();
} else {
self.matchStatus.setDeuce();
}
return false;
}
return incP2Game();
}
} else {
Expand Down Expand Up @@ -221,7 +283,7 @@ class PadelMatch {
totalPlayedSets == self.numberOfSets ||
abs(self.matchStatus.getP1Sets() - self.matchStatus.getP2Sets()) > self.numberOfSets - totalPlayedSets;

}
}

function finishSuperTie() as Boolean {
var result = "" + self.matchStatus.getP1TieScore() + "-" + self.matchStatus.getP2TieScore();
Expand All @@ -245,4 +307,4 @@ class PadelMatch {
function resetAfterGameFinish() {
self.matchStatus.resetScores();
}
}
}
15 changes: 12 additions & 3 deletions source/model/matchConfig.mc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class MatchConfig {
private var superTie;
private var numberOfSets;
private var goldenPoint;
private var numberOfDeuces;

function initialize() {
superTie = false;
numberOfSets = UNLIMITED_SETS;
goldenPoint = true;
goldenPoint = true;
}

function setGoldenPoint(goldenPoint as Boolean) as Void {
Expand All @@ -34,12 +35,20 @@ class MatchConfig {
self.numberOfSets = sets;
}

function setNumberOfDeuces(deuces as Number) as Void {
self.numberOfDeuces = deuces;
}

function getNumberOfDeuces() as Number {
return self.numberOfDeuces;
}

function getNumberOfSets() as Number {
return self.numberOfSets;
}

function toString() as Lang.String {
return "matchConfig: " + "superTie: " + self.superTie + ", sets: " + self.numberOfSets + ", golden: " + self.goldenPoint;
return "matchConfig: " + "superTie: " + self.superTie + ", sets: " + self.numberOfSets + ", golden: " + self.goldenPoint + ", deuces: " + self.numberOfDeuces;
}

}
}
22 changes: 18 additions & 4 deletions source/model/matchStatus.mc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class MatchStatus {
private var p1TieBreakScore;
private var p2TieBreakScore;

private var totalDeuces;

static function New() {
return new MatchStatus(0,0,0,0,0,0,0,0);
return new MatchStatus(0,0,0,0,0,0,0,0,0);
}

function initialize(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore) {
function initialize(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore, totalDeuces) {
self.p1Sets = p1Sets;
self.p2Sets = p2Sets;

Expand All @@ -30,6 +32,8 @@ class MatchStatus {

self.p1TieBreakScore = p1TieBreakScore;
self.p2TieBreakScore = p2TieBreakScore;

self.totalDeuces = totalDeuces;
}


Expand Down Expand Up @@ -97,6 +101,14 @@ class MatchStatus {
self.p2TieBreakScore++;
}

function getTotalOfDeuces() {
return self.totalDeuces;
}

function incTotalOfDeuces() {
self.totalDeuces++;
}

function setDeuce() {
self.p1ScoreIdx = 3;
self.p2ScoreIdx = 3;
Expand All @@ -113,9 +125,11 @@ class MatchStatus {

self.p2ScoreIdx = 0;
self.p2TieBreakScore = 0;

self.totalDeuces = 0;
}

function copy() as MatchStatus {
return new MatchStatus(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore);
return new MatchStatus(p1Sets, p2Sets, p1Games, p2Games, p1ScoreIdx, p2ScoreIdx, p1TieBreakScore, p2TieBreakScore, totalDeuces);
}
}
}