Skip to content

Commit

Permalink
Bug fix for hand wait check
Browse files Browse the repository at this point in the history
  • Loading branch information
EmeraldCoder committed Feb 14, 2014
1 parent 585d48f commit b5273d8
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/gui/RiichiMahjongPointerViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
function RiichiMahjongPointerViewModel() {
var self = this;

/**
* Title of the current active view on the interface
*/
self.title = ko.observable('Your hand');

/**
* Id of the current active view on the interface
* Main, TileSuitSelection, TileValueSelection, Result
Expand Down Expand Up @@ -36,19 +41,10 @@ function RiichiMahjongPointerViewModel() {
self.winningSecondaryType = ko.observable('');

/**
* indicate if the player won with a riichi
*/
self.isRiichi = ko.observable(false);

/**
* indicate if the player riichi was put on the first round
* indicate if the player won with riichi circonstance
* riichi / riichi ippatsu / double riichi / double riichi ippatsu
*/
self.isDoubleRiichi = ko.observable(false);

/**
* indicate if the player won in the first round after declaring his riichi
*/
self.isIppatsu = ko.observable(false);
self.winningRiichiType = ko.observable('');

/**
* list of the dora tiles
Expand Down Expand Up @@ -132,14 +128,13 @@ function RiichiMahjongPointerViewModel() {
});

self.reset = function() {
self.title('Your hand');
self.currentView('Main');
self.prevalentWind('east');
self.seatWind('east');
self.winningType('tsumo');
self.winningSecondaryType('');
self.isRiichi(false);
self.isDoubleRiichi(false);
self.isIppatsu(false);
self.winningRiichiType('');
self.doraTiles([]);
self.uraDoraTiles([]);
self.winningTile = null;
Expand All @@ -166,6 +161,7 @@ function RiichiMahjongPointerViewModel() {
self.addForDora = true;
self.addIsUraDora = isUraDora;
self.currentView('TileSelection');
self.title('Select a tile');
};

self.removeDora = function(index, isUraDora) {
Expand All @@ -188,6 +184,7 @@ function RiichiMahjongPointerViewModel() {
self.addIsConcealed = isConcealed;
self.addType(type);
self.currentView('TileSelection');
self.title('Select a tile');
};

self.remove = function(index, isOpen) {
Expand Down Expand Up @@ -237,13 +234,19 @@ function RiichiMahjongPointerViewModel() {
}, combinaison);
self.openCombinaisons.push(combinaison);
}

combinaison.tiles.forEach(function(tile) {
tile._combinaison = combinaison;
tile._index = combinaison.tiles.indexOf(tile);
});
}

self.addForDora = null;
self.addIsConcealed = null;
self.addType(null);
self.addIsUraDora = null;
self.currentView('Main');
self.title('Your hand');
};

/**
Expand All @@ -264,6 +267,7 @@ function RiichiMahjongPointerViewModel() {
*/
self.returnToMain = function(){
self.currentView('Main');
self.title('Your hand');
};

/**
Expand All @@ -277,8 +281,8 @@ function RiichiMahjongPointerViewModel() {
return false;
}

var winningCombinaisonIndex = 0;
var winningTileIndex = 0;
var winningCombinaisonIndex = self.winningTile._combinaison._index();
var winningTileIndex = self.winningTile._index;

var hand = new Hand(
self.concealedCombinaisons(),
Expand All @@ -292,9 +296,12 @@ function RiichiMahjongPointerViewModel() {
self.doraTiles(),
self.uraDoraTiles()
);
hand.isRiichi = self.isRiichi() || self.isDoubleRiichi();
hand.isDoubleRiichi = self.isDoubleRiichi();
hand.isIppatsu = self.isIppatsu();

hand.isRiichi = self.winningRiichiType() !== '';
hand.isDoubleRiichi = self.winningRiichiType() === 'double riichi' ||
self.winningRiichiType() === 'double riichi ippatsu';
hand.isIppatsu = self.winningRiichiType() === 'riichi ippatsu' ||
self.winningRiichiType() === 'double riichi ippatsu';

var patterns = [
new TanyaouChuu(),
Expand Down Expand Up @@ -367,6 +374,7 @@ function RiichiMahjongPointerViewModel() {
self.pointsTotal(pointHtml);

self.currentView('Result');
self.title('Hand points');
};

}

0 comments on commit b5273d8

Please sign in to comment.