some bugfixes. reverse counting now fully working

This commit is contained in:
Maximilian Keßler 2022-09-16 10:21:32 +02:00
parent 7b2022c0a3
commit b7ac1ddaaa

View file

@ -99,6 +99,7 @@ var OnlineTichuCounter = {
totalPlayed: [], totalPlayed: [],
exchangedTo: {}, exchangedTo: {},
exchangedFrom: {}, exchangedFrom: {},
smartFold: false,
util: { util: {
displayCardsHtmlString: function(cards) { displayCardsHtmlString: function(cards) {
@ -127,10 +128,10 @@ var OnlineTichuCounter = {
} }
} }
otc.allCards[1] = [ otc.allCards[1] = [
{ Shape: 4, Value: 1 }, { Shape: 4, Value: 1 }, // mahjong
{ Shape: 5, Value: 0 }, { Shape: 5, Value: 0 }, // dog
{ Shape: 6, Value: 15}, { Shape: 6, Value: 15}, // dragon
{ Shape: 7, Value: 14 } { Shape: 7, Value: 14 } // phoenix
]; ];
}, },
@ -140,20 +141,23 @@ var OnlineTichuCounter = {
if (array[i].Shape == card.Shape && array[i].Value == card.Value) { if (array[i].Shape == card.Shape && array[i].Value == card.Value) {
contained = true; contained = true;
} }
return contained;
} }
return contained;
} }
}, },
action: { action: {
handlePlayedCard: function(card) { handlePlayedCard: function(card) {
// console.log('Handling a card:');
// console.log(card);
// console.log(otc.played);
index = 0; index = 0;
// special cards have Shapes 4,5,6,7. We group them at value 1
if(card.Shape >= 4) { if(card.Shape >= 4) {
index = 1; index = 1;
if (card.Shape == 7) {
// Treat phoenix as if it had value 14
// This is important for comparisons later
card.Value = 14;
}
} else { } else {
index = card.Value; index = card.Value;
} }
@ -166,24 +170,14 @@ var OnlineTichuCounter = {
}, },
handlePlayedCards: function(cards) { handlePlayedCards: function(cards) {
if (cards.length > 0) { if (cards.length === 0) {
contained = false; return;
// console.log(message.Table.TableCards[0].Shape);
// console.log(message.Table.TableCards[0].Value);
$(otc.totalPlayed).each(function (index, item) {
if (item.Shape == cards[0].Shape) {
if (item.Value == cards[0].Value) {
contained = true;
} }
} if (!otc.util.cardInArray(cards[0], otc.totalPlayed)) {
});
if(!contained) {
$(message.Table.TableCards).each( $(message.Table.TableCards).each(
(index, card) => otc.action.handlePlayedCard(card) (index, card) => otc.action.handlePlayedCard(card)
); );
} }
}
}, },
resetPlayedCards: function() { resetPlayedCards: function() {
@ -194,23 +188,18 @@ var OnlineTichuCounter = {
}, },
drawPlayedCards: function() { drawPlayedCards: function() {
console.log('drawing played cards');
console.log(otc.playedCards);
console.log(otc.allCards);
for(let i = 1; i < 15; i++) { for(let i = 1; i < 15; i++) {
cards = []; cards = [];
for(let j=0; j < otc.allCards[i].length; j ++) { for(let j=0; j < otc.allCards[i].length; j ++) {
if(!otc.util.cardInArray(otc.allCards[i][j], otc.playedCards[i])) { if(!otc.util.cardInArray(otc.allCards[i][j], otc.playedCards[i])) {
cards.push(otc.allCards[i][j]); cards.push(otc.allCards[i][j]);
} }
}
// cards = otc.allCards[i].filter(x => otc.util.cardInArray(x, otc.playedCards[i]));
console.log(cards);
otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards)); otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards));
} }
} }
} }
} }
}
if (!window.otc) { if (!window.otc) {
window.otc = OnlineTichuCounter; window.otc = OnlineTichuCounter;