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);

}

}
40 changes: 37 additions & 3 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,11 +18,13 @@ class PadelMatch {
numberOfSets = config.getNumberOfSets();
superTie = config.getSuperTie();
goldenPoint = config.getGoldenPoint();
numberOfDeuces = config.getNumberOfDeuces();

matchStatus = MatchStatus.New();
prevMatchStatus = MatchStatus.New();

historicalScores = [];

}

// returns a boolean indicating wether the match has ended.
Expand Down Expand Up @@ -65,10 +68,24 @@ class PadelMatch {
if (self.goldenPoint) {
// mid game
if (self.matchStatus.getP1Score() != 40) {
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
if (self.matchStatus.getP1Score() == 'A') {
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
return incP1Game();
}
self.matchStatus.incP1Score();
return false;
} else {
return incP1Game();
if (self.matchStatus.getP2Score() == 40) {
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
return incP1Game();
} else {
self.matchStatus.incP1Score();
return false;
}
} else {
return incP1Game();
}
}
} else {
// P2 was in Adv, revert to deuce
Expand Down Expand Up @@ -145,10 +162,27 @@ class PadelMatch {
if (self.goldenPoint) {
// mid game
if (self.matchStatus.getP2Score() != 40) {
if (self.matchStatus.getP2Score() == 'A') {
return incP2Game();
}
self.matchStatus.incP2Score();
return false;
} else {
return incP2Game();
if (self.matchStatus.getP1Score() == 40) {
self.matchStatus.incTotalOfDeuces();

if (self.matchStatus.getTotalOfDeuces() == self.numberOfDeuces) {
return incP2Game();
} else {
self.matchStatus.incP2Score();
return false;
}
} else if (self.matchStatus.getP1Score() == 'A') {
self.matchStatus.setDeuce();
return false;
} else {
return incP2Game();
}
}
} else {
// P1 was in Adv, revert to deuce
Expand Down Expand Up @@ -245,4 +279,4 @@ class PadelMatch {
function resetAfterGameFinish() {
self.matchStatus.resetScores();
}
}
}
16 changes: 13 additions & 3 deletions source/model/matchConfig.mc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ 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;
//numberOfDeuces = 1;
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
}

function setGoldenPoint(goldenPoint as Boolean) as Void {
Expand All @@ -34,12 +36,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;
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved

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) {
pedrorijo91 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
}