diff --git a/Games/Go-fish-master/.gitignore b/Games/Go-fish-master/.gitignore new file mode 100644 index 0000000000..d5cc28426a --- /dev/null +++ b/Games/Go-fish-master/.gitignore @@ -0,0 +1 @@ +audio diff --git a/Games/Go-fish-master/README.md b/Games/Go-fish-master/README.md new file mode 100644 index 0000000000..d8115bec54 --- /dev/null +++ b/Games/Go-fish-master/README.md @@ -0,0 +1,27 @@ +# Go Fish +--------- + +An emulator for the card game 'Go Fish'. Choose how many opponents you want to play against and see who is better! + + +## Rules: + +- Each player starts with 7 cards (2/3 players) or 5 cards (4 or more players). +- Play begins with you, then each of your opponents from left to right. +- During their turn, each player 'goes fishing' by selecting a value of a card in their hand and another player, in the game this is done by clicking a card and an opponent, then clicking 'Take Turn'. If the selected player has any cards of that value the 'fisher' has made a 'catch'. The selected player must give the 'fisher' all their cards of that value. If the selected player has no cards of that value, the selector has not made a 'catch' and must 'Go Fish!' and draws a new card from the deck. +- If, during their turn, a player ends up with all 4 cards then they have collected a full set. The player then must immediately declare this and play their set face up, in front of them. +- If during play a player ends up with no cards in their hand they must draw a card from the deck, rather than 'going fishing' for cards from other people. +- The winner is the player with the most sets at the end. +- Once all 13 sets have been completed, play ends. + + +## Tools +- **HTML** +- **CSS** +- **JavaScript** +- **JQuery** +- **Atom Development Environment** +- **SourceTree Source Control** + +## Screenshot +![image](../../assets/images/Go-fish-master.png) \ No newline at end of file diff --git a/Games/Go-fish-master/css/master.css b/Games/Go-fish-master/css/master.css new file mode 100644 index 0000000000..515e4be716 --- /dev/null +++ b/Games/Go-fish-master/css/master.css @@ -0,0 +1,105 @@ +/* *{ + border: 1px solid red; +} */ + + + +body { + font-family: "Open Sans", "Trebuchet MS", Helvetica, sans-serif; + margin: 0px; + background-color: green; + color: white; + border: 5px solid gold; +} + +a { + text-decoration: none; + color: white; +} + +a:visited { + color: white; +} + +a:active { + color: red; +} + +a:hover { + color: gold; +} + +button { + height: 30px; + width: 100px; + border-radius: 10%; + background-color: ivory; + border-color: ivory; + border-style: outset; + border-width: 5px; +} + +button:active { + border-style: inset; +} + +button:focus { + outline: none; +} + +ul { + text-align: left; + padding-left: 5%; + padding-right: 5%; +} + +.center { + /* display: block; */ + text-align: center; +} + +.tracker { + padding-left: 5px; + padding-right: 5px; + width: 200px; + margin: 5px; + border: 5px ridge black; + /* justify-content: space-around; */ +} + +.card { + width: 100px; + /* height: 200px; */ + border: 1px solid black; + justify-content: space-around; +} + +.card:hover { + position: relative; + top: -10px; +} + +.title { + margin-top: 40%; +} + +#cardContainer { + /* display: flex; */ + flex-wrap: nowrap; + border: 3px solid gold; + border-bottom: 0px; +} + +#opponentContainer { + display: flex; + flex-direction: row; + justify-content: space-around; +} + +.search { + display: flex; + flex-direction: row; + justify-content: space-around; + padding-left: 25%; + padding-right: 25%; +} diff --git a/Games/Go-fish-master/images/cardsjpg/10C.jpg b/Games/Go-fish-master/images/cardsjpg/10C.jpg new file mode 100644 index 0000000000..9a4580351d Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/10C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/10D.jpg b/Games/Go-fish-master/images/cardsjpg/10D.jpg new file mode 100644 index 0000000000..69d2a61b8c Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/10D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/10H.jpg b/Games/Go-fish-master/images/cardsjpg/10H.jpg new file mode 100644 index 0000000000..da4b4acbeb Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/10H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/10S.jpg b/Games/Go-fish-master/images/cardsjpg/10S.jpg new file mode 100644 index 0000000000..7d61f5b075 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/10S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/2C.jpg b/Games/Go-fish-master/images/cardsjpg/2C.jpg new file mode 100644 index 0000000000..c59aa5e3d9 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/2C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/2D.jpg b/Games/Go-fish-master/images/cardsjpg/2D.jpg new file mode 100644 index 0000000000..ed3bdcfb2b Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/2D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/2H.jpg b/Games/Go-fish-master/images/cardsjpg/2H.jpg new file mode 100644 index 0000000000..000cced39a Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/2H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/2S.jpg b/Games/Go-fish-master/images/cardsjpg/2S.jpg new file mode 100644 index 0000000000..9652423dcb Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/2S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/3C.jpg b/Games/Go-fish-master/images/cardsjpg/3C.jpg new file mode 100644 index 0000000000..018ef280a2 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/3C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/3D.jpg b/Games/Go-fish-master/images/cardsjpg/3D.jpg new file mode 100644 index 0000000000..f50631b55b Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/3D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/3H.jpg b/Games/Go-fish-master/images/cardsjpg/3H.jpg new file mode 100644 index 0000000000..fe91f05cdc Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/3H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/3S.jpg b/Games/Go-fish-master/images/cardsjpg/3S.jpg new file mode 100644 index 0000000000..bce70b050f Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/3S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/4C.jpg b/Games/Go-fish-master/images/cardsjpg/4C.jpg new file mode 100644 index 0000000000..fb9f4df527 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/4C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/4D.jpg b/Games/Go-fish-master/images/cardsjpg/4D.jpg new file mode 100644 index 0000000000..ece8296879 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/4D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/4H.jpg b/Games/Go-fish-master/images/cardsjpg/4H.jpg new file mode 100644 index 0000000000..8f1b5a193d Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/4H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/4S.jpg b/Games/Go-fish-master/images/cardsjpg/4S.jpg new file mode 100644 index 0000000000..9c4c817b05 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/4S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/5C.jpg b/Games/Go-fish-master/images/cardsjpg/5C.jpg new file mode 100644 index 0000000000..72fb8db48e Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/5C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/5D.jpg b/Games/Go-fish-master/images/cardsjpg/5D.jpg new file mode 100644 index 0000000000..ebba5f22b9 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/5D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/5H.jpg b/Games/Go-fish-master/images/cardsjpg/5H.jpg new file mode 100644 index 0000000000..7a125ada67 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/5H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/5S.jpg b/Games/Go-fish-master/images/cardsjpg/5S.jpg new file mode 100644 index 0000000000..87897a23d9 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/5S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/6C.jpg b/Games/Go-fish-master/images/cardsjpg/6C.jpg new file mode 100644 index 0000000000..8578b4b639 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/6C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/6D.jpg b/Games/Go-fish-master/images/cardsjpg/6D.jpg new file mode 100644 index 0000000000..fd6ebc9c21 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/6D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/6H.jpg b/Games/Go-fish-master/images/cardsjpg/6H.jpg new file mode 100644 index 0000000000..87c0e89d9b Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/6H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/6S.jpg b/Games/Go-fish-master/images/cardsjpg/6S.jpg new file mode 100644 index 0000000000..33ac347eee Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/6S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/7C.jpg b/Games/Go-fish-master/images/cardsjpg/7C.jpg new file mode 100644 index 0000000000..bb4777d815 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/7C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/7D.jpg b/Games/Go-fish-master/images/cardsjpg/7D.jpg new file mode 100644 index 0000000000..9e271363c4 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/7D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/7H.jpg b/Games/Go-fish-master/images/cardsjpg/7H.jpg new file mode 100644 index 0000000000..beb036895a Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/7H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/7S.jpg b/Games/Go-fish-master/images/cardsjpg/7S.jpg new file mode 100644 index 0000000000..957bbf7fd0 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/7S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/8C.jpg b/Games/Go-fish-master/images/cardsjpg/8C.jpg new file mode 100644 index 0000000000..41a7a6b46f Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/8C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/8D.jpg b/Games/Go-fish-master/images/cardsjpg/8D.jpg new file mode 100644 index 0000000000..b9401f73b8 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/8D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/8H.jpg b/Games/Go-fish-master/images/cardsjpg/8H.jpg new file mode 100644 index 0000000000..02e5040050 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/8H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/8S.jpg b/Games/Go-fish-master/images/cardsjpg/8S.jpg new file mode 100644 index 0000000000..28ade6226e Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/8S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/9C.jpg b/Games/Go-fish-master/images/cardsjpg/9C.jpg new file mode 100644 index 0000000000..865cbc6b74 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/9C.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/9D.jpg b/Games/Go-fish-master/images/cardsjpg/9D.jpg new file mode 100644 index 0000000000..85a17c4efb Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/9D.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/9H.jpg b/Games/Go-fish-master/images/cardsjpg/9H.jpg new file mode 100644 index 0000000000..f1e177f7fc Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/9H.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/9S.jpg b/Games/Go-fish-master/images/cardsjpg/9S.jpg new file mode 100644 index 0000000000..f5590fddbd Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/9S.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/AC.jpg b/Games/Go-fish-master/images/cardsjpg/AC.jpg new file mode 100644 index 0000000000..24750aacea Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/AC.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/AD.jpg b/Games/Go-fish-master/images/cardsjpg/AD.jpg new file mode 100644 index 0000000000..5a1b0e9a4c Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/AD.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/AH.jpg b/Games/Go-fish-master/images/cardsjpg/AH.jpg new file mode 100644 index 0000000000..ffd1372ce4 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/AH.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/AS.jpg b/Games/Go-fish-master/images/cardsjpg/AS.jpg new file mode 100644 index 0000000000..ff4ff48c24 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/AS.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/JC.jpg b/Games/Go-fish-master/images/cardsjpg/JC.jpg new file mode 100644 index 0000000000..19e16133a8 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/JC.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/JD.jpg b/Games/Go-fish-master/images/cardsjpg/JD.jpg new file mode 100644 index 0000000000..d6ae10a12a Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/JD.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/JH.jpg b/Games/Go-fish-master/images/cardsjpg/JH.jpg new file mode 100644 index 0000000000..6fabafed00 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/JH.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/JS.jpg b/Games/Go-fish-master/images/cardsjpg/JS.jpg new file mode 100644 index 0000000000..070a1a00ce Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/JS.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/KC.jpg b/Games/Go-fish-master/images/cardsjpg/KC.jpg new file mode 100644 index 0000000000..004a0a8a03 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/KC.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/KD.jpg b/Games/Go-fish-master/images/cardsjpg/KD.jpg new file mode 100644 index 0000000000..94138fd6dc Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/KD.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/KH.jpg b/Games/Go-fish-master/images/cardsjpg/KH.jpg new file mode 100644 index 0000000000..62073ac8d4 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/KH.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/KS.jpg b/Games/Go-fish-master/images/cardsjpg/KS.jpg new file mode 100644 index 0000000000..d3e9da74a3 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/KS.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/QC.jpg b/Games/Go-fish-master/images/cardsjpg/QC.jpg new file mode 100644 index 0000000000..0ad7d4d277 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/QC.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/QD.jpg b/Games/Go-fish-master/images/cardsjpg/QD.jpg new file mode 100644 index 0000000000..f385eab72e Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/QD.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/QH.jpg b/Games/Go-fish-master/images/cardsjpg/QH.jpg new file mode 100644 index 0000000000..3080de265e Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/QH.jpg differ diff --git a/Games/Go-fish-master/images/cardsjpg/QS.jpg b/Games/Go-fish-master/images/cardsjpg/QS.jpg new file mode 100644 index 0000000000..9c8501e755 Binary files /dev/null and b/Games/Go-fish-master/images/cardsjpg/QS.jpg differ diff --git a/Games/Go-fish-master/index.html b/Games/Go-fish-master/index.html new file mode 100644 index 0000000000..4198f51a95 --- /dev/null +++ b/Games/Go-fish-master/index.html @@ -0,0 +1,19 @@ + + + + + Go Fish + + + +
+

Let's Play Go Fish!

+ Play + Instructions +
+
+ + +
+ + diff --git a/Games/Go-fish-master/js/scripts.js b/Games/Go-fish-master/js/scripts.js new file mode 100644 index 0000000000..7c657a0fcf --- /dev/null +++ b/Games/Go-fish-master/js/scripts.js @@ -0,0 +1,687 @@ +var gameActive = false; +var dealer; +var searchValue = "x"; +var searchPlayer = "x"; + +$(document).ready(function () { + $("#startButton").click(buttonPress); + $("#continue").click(moveOn); + $("#cardContainer").on("click", ".card", function () { + cardPress(this); + }); + $("#opponentContainer").on("click", ".opponent", function() { + opponentPress(this); + }); +}); + +function buttonPress() { + // var element = document.getElementById("sven"); + // var playDeck = new Deck(); + if(!gameActive) { + dealer = new Dealer(requestPlayers()); + sounds = new Sounds(); + gameActive = true; + alert("Hands dealt, ready to play.\n Click to begin."); + } +} + +function moveOn() { + if(gameActive) { + playGame(searchValue, searchPlayer); + } +} + +function cardPress(press) { + var value = $(press).attr('value'); + searchValue = value; + + switch (value) { + case "11": + value = "Jack"; + break; + case "12": + value = "Queen"; + break; + case "13": + value = "King"; + break; + case "1": + value = "Ace"; + break; + default: + } + + $("#searchValue").html(value); +} + +function opponentPress(press) { + var value = $(press).attr('number'); + searchPlayer = value; + $("#searchPlayer").html("Opponent: " + searchPlayer); +} + +function resetSearchValues() { + $("#searchValue").html(""); + $("#searchPlayer").html(""); + searchValue = "x"; + searchPlayer = "x"; +} + +// Gameplay cycle runs here after setup +function playGame(playerInputValue, playerInputOpponent) { + if(playerInputValue === "x" || playerInputOpponent === "x") { + $("playerInfo").html("Select opponent and card value to fish!"); + return; + } + + // For each player: + for (var i = 0; i < dealer.players.length; i++) { + var playerTakingTurn = dealer.players[i]; + + var canTakeTurn = playerTakingTurn.takeTurn(); + + // Overrides autoplay with human interraction + if (canTakeTurn === 2) { + if(playerTakingTurn.getHand() > 1) { + // If player cannot draw a card because deck is empty + if(!dealer.dealCard(playerTakingTurn)) { + // Skip player, there is nothing else they can do + $("#playerInfo").html("Deck is empty. Please continue to end.") + $("#continue").html("Continue"); + continue; + } + } + + // Switch value to int (collected as string from image) + var valueToSearch = parseInt(playerInputValue); + var opponentToSearch = dealer.players[playerInputOpponent]; + instigateCall(valueToSearch, opponentToSearch, playerTakingTurn); + resetSearchValues(); + + if(playerTakingTurn.getHand() > 1) { + $("#continue").html("Draw Card"); + } + continue; + } + + // If the player has no cards, draw a card + if(canTakeTurn === 0) { + // If player cannot draw a card because deck is empty + if(!dealer.dealCard(playerTakingTurn)) { + // Skip player, there is nothing else they can do + continue; + } + // Else pick a card and player to fish + } else { + // An array containing: + // [0] = direct reference to a card + // [1] = index of a player + var cardAndPlayerInt = playerTakingTurn.callCardAndPlayer(dealer.players.length); + + // Card value + var cardToFind = cardAndPlayerInt[0].value; + + // Direct reference to a player (from index) + var playerToFish = dealer.players[cardAndPlayerInt[1]]; + + instigateCall(cardToFind, playerToFish, playerTakingTurn); + } + } + + if(!dealer.checkWinCondition()) { + var winnersArray = []; + var winValue = 0; + for (var i = 0; i < dealer.players.length; i++) { + if(dealer.players[i].getNumSets() > winValue) { + winValue = dealer.players[i].getNumSets(); + winnersArray = []; + winnersArray.push(i); + } + else if (dealer.players[i].getNumSets() === winValue) { + winnersArray.push(i); + } + } + + $("#cardContainer").empty(); + for (var i = 0; i < winnersArray.length; i++) { + if(dealer.players[winnersArray[i]].id > 1) { + $("#cardContainer").append("

OPPONENT " + (dealer.players[winnersArray[i]].id - 1) + " WINS!

"); + } else { + $("#cardContainer").append("

YOU WIN!

"); + } + } + gameActive = false; + } +} + +function instigateCall(cardToFind, playerToFish, playerTakingTurn) { + // Array of index values point to search matches + var matchingValueIndicies = dealer.findCardInPlayer(cardToFind, playerToFish); + + // If no matches + if(matchingValueIndicies.length < 1) { + // If player cannot draw a card because deck is empty + if(!dealer.dealCard(playerTakingTurn)) { + // Skip player, there is nothing else they can do + } + // continue; + } + + // Cards to pass to fishing player + var cardsToPass = playerToFish.removeCards(matchingValueIndicies); + for (var j = 0; j < cardsToPass.length; j++) { + playerTakingTurn.addCard(cardsToPass[j]); + } + + switch (cardToFind) { + case 11: + cardToFind = "Jack"; + break; + case 12: + cardToFind = "Queen"; + break; + case 13: + cardToFind = "King"; + break; + case 1: + cardToFind = "Ace"; + break; + default: + } + + var num = playerToFish.id; + if(!playerTakingTurn.human) { + if(num === 1) { + num = "YOU" + } else { + num = "Opponent " + (playerToFish.id - 1); + } + + if(matchingValueIndicies < 1) { + $(".actionExplain").eq((playerTakingTurn.id - 2)).html("Hunted " + cardToFind + " from " + num + ".
GO FISH!"); + } else { + $(".actionExplain").eq(playerTakingTurn.id - 2).html("Hunted " + cardToFind + " from " + num + ".
Gained " + matchingValueIndicies.length + " cards!"); + } + + } else { + num = "Opponent " + (playerToFish.id - 1); + if(matchingValueIndicies < 1) { + $("#playerInfo").html("Hunted " + cardToFind + " from " + num + ". GO FISH!"); + } else { + $("#playerInfo").html("Hunted " + cardToFind + " from " + num + ". Gained " + matchingValueIndicies.length + " cards!"); + } + } +} + +// Get number of players +function requestPlayers() { + do { + var players = prompt("Choose a number of players, between 2 and 7!"); + players = parseInt(players); + } while (players === NaN || players < 2 || players > 7); + return players; +} + +// Manages cards +class Deck { + constructor() { + this.deck = []; + this.initialise(); + this.printDeck(); + } + + // Build and shuffle standard deck of 52 cards + initialise() { + const SUITS_QUANTITY = 4; + const SUIT_SIZE = 13; + + var suits = [4,3,2,1]; + + // Build a sorted deck in suits descending order - S,H,C,D + for(var i = 0; i < SUITS_QUANTITY; i++) { + for(var j = 0; j < SUIT_SIZE; j++) { + + /* + Objects are passed by reference in JS, therefore duplicating the global variable 'card' and editing it edits ALL deriviatives of card. + Thus creating a deck of cards that are ALL THE SAME! + Therefore variable must be instantiated each time. + CAN YOU TELL I SPENT A LONG TIME WORKING THIS OUT?!? + */ + + // Template for each card + var card = {suit: 0, value: 0, image: ""}; + + card.suit = suits[i]; + card.value = (j+1); + // Apply reference to corresponding card image: + // ../images/cardsjpg/card.image.jpg + var imageRef = ""; + switch (card.value) { + case 11: + imageRef += "J"; + break; + case 12: + imageRef += "Q"; + break; + case 13: + imageRef += "K"; + break; + case 1: + imageRef += "A"; + break; + default: + imageRef += String(card.value); + } + + switch (card.suit) { + case 4: + imageRef += "S"; + break; + case 3: + imageRef += "H"; + break; + case 2: + imageRef += "C"; + break; + case 1: + imageRef += "D"; + break; + default: + imageRef += "HELP I DON'T HAVE A SUIT!" + } + card.image = "../images/cardsjpg/" + imageRef + ".jpg"; + this.deck.push(card); + } + } + this.shuffleDeck(); + } + + // Could randomly grab a single card from the deck rather than suffle + // BUT a shuffled deck allows for reusable code in other card games + shuffleDeck() { + + // Shuffles using the Fisher-Yates method, an 'in-place, O(n) algorithm' + var m = this.deck.length, t, i; + + // While there remain elements to shuffle… + while (m) { + + // Pick a remaining element… + i = Math.floor(Math.random() * m--); + + // And swap it with the current element. + t = this.deck[m]; + this.deck[m] = this.deck[i]; + this.deck[i] = t; + } + } + + printDeck() { + $("#deckSize").html(this.deck.length); + } + + getCard() { + var drawnCard = this.deck.pop(); + this.printDeck() + return drawnCard; + } +} + +// Manages interractions between deck and players +class Dealer { + constructor(players) { + // Number of players + this.playerCount = players; + // Array of players + this.players = []; + + // Can't play by yourself + this.MIN_PLAYERS = 2; + // Number of players necessary for 5 cards rather than 7 to be dealt + this.DEAL_THRESHOLD = 4 + // Max 7 players for now (technically 10 can play) + this.MAX_PLAYERS = 7; + + // The deck for this game + this.playDeck = new Deck(); + + this.createPlayers(); + this.dealHands(); + } + + // Create necessary number of player objects + createPlayers () { + // Create player class for each player + $("#opponentContainer").empty(); + for (var i = 0; i < this.playerCount; i++) { + var newPlayer = new Player(); + newPlayer.id = i+1; + if (i === 0) { + newPlayer.setHuman(); + } else { + var opponentNumber = i; + $("#opponentContainer").append("
\n\n
Sets:
\n

0

\n
==========
\n
"); + } + this.players.push(newPlayer); + } + this.playerNum = this.players.length; + } + + // Deal hand of correct size to each player + dealHands () { + var toDeal = 0; + if (this.playerCount >= this.MIN_PLAYERS && this.playerCount < this.DEAL_THRESHOLD) { + toDeal = 7; + } + else if (this.playerCount >= this.DEAL_THRESHOLD && this.playerCount <= this.MAX_PLAYERS) { + toDeal = 5; + } + else { + throw "invalidPlayerNumberException"; + } + + for (var i = 0; i < toDeal; i++) { + for (var j = 0; j < this.players.length; j++) { + this.dealCard(this.players[j]); + } + } + // + // for (var i = 0; i < this.players.length; i++) { + // console.log(this.players[i].getHand()); + // } + } + + // Send a single card from the deck to a player + dealCard (player) { + if(this.playDeck.deck.length < 1) { + return false + } else { + player.addCard(this.getCardFromDeck()); + } + return true; + } + + // TAKE a card value and a player + // RETURN array of matching cards + findCardInPlayer(card, opponent) { + var cardsOfMatchingValue = []; + // For each card in oppenent's hand + for (var i = 0; i < opponent.hand.length; i++) { + // If card value matches value searched for + if(opponent.hand[i].value === card) { + // Add index to cardsOfMatchingValue + cardsOfMatchingValue.push(i); + } + } + return cardsOfMatchingValue; + } + + // Returns a card from the deck + getCardFromDeck() { + return this.playDeck.getCard(); + } + + // Checks if all sets are down + // If true + // Player with most sets wins + checkWinCondition () { + var totalSets = 0; + for (var i = 0; i < this.players.length; i++) { + totalSets += this.players[i].getNumSets(); + } + + if(totalSets === 13) { + return false; + } + return true; + } + + // Returns length of players array + getPlayersLength() { + return this.players.length; + } +} + +// The players +class Player { + constructor () { + // Player id (index 1) + this.id = 0; + // Array of cards in hand + this.hand = []; + // Is this player controlled by a human? + this.human = false; + // An array of the sets a player has + this.sets = []; + // Human controller + this.humanController; + } + + // Add card to hand + addCard (card) { + this.hand.push(card); + this.sortHand(); + this.checkHand(); + } + + // Returns player hand + getHand () { + return this.hand; + } + + setHuman () { + this.human = true; + this.humanController = new Human(this); + } + + // TAKES array of index values for cards to remove + // Removes cards from hand by interating from end to beginning + // This avoids incorrect references after splice + // RETURN the removed cards + removeCards (indexArray) { + var removedCards = []; + for (var i = (indexArray.length - 1); i >= 0; i--) { + + // Capture card in singlecard variable + var singleCard = this.hand[indexArray[i]]; + + // Delete card from array + this.hand.splice(indexArray[i], 1); + + // Push singleCard to removedCards array + removedCards.push(singleCard); + } + + if(this.human) { + this.humanController.populateCardContainer(this.getHand()); + } + + // Checks hand again to ensure there are cards still in hand + this.checkHand(); + return removedCards; + } + + // If hand empty, get card ELSE call a card + takeTurn () { + if(this.human) { + if(this.hand.length < 1) { + return 0; + } else { + return 2; + } + + } else { + if(this.hand.length < 1) { + return 0; + } else { + return 1; + } + } + } + + // Takes: total number of players from Dealer + // Returns: + // A card to find + // An integer value for the player to 'fish' from + callCardAndPlayer (playerTot) { + // Randomly generated values for the player and card value being fished + do { + var rand1 = Math.floor(Math.random() * this.hand.length); + var rand2 = Math.floor(Math.random() * playerTot); + } while (rand2 === this.id-1); + + return [this.hand[rand1], rand2]; + } + + // Organise hand S,H,C,D, value ascending + sortHand () { + this.hand.sort(function (a,b) {return a.value - b.value}); + + if(this.human) { + this.humanController.populateCardContainer(this.getHand()); + } + } + + // Checks this player's hand for any sets + checkHand() { + var currentValue = 0; + var valueCount = 1; + if(this.hand.length < 1 && this.human) { + this.humanController.emptyHand(); + return; + } else if(this.human) { + this.humanController.fullHand(); + } + + // Checks for sets of 4 + for (var i = 0; i < this.hand.length; i++) { + if (this.hand[i].value !== currentValue) { + currentValue = this.hand[i].value; + valueCount = 1; + } else { + valueCount++; + } + + // If 4 matching values are FOUND + // Removes the latest value, and the 3 preceding + // This works because the deck is always sorted + if(valueCount === 4) { + var set = this.hand[i].value; + this.playSet(set); + + // Remove set from hand + this.removeCards([i-3, i-2, i-1, i]); + } + } + } + + // TAKES a complete set + playSet(set) { + this.sets.push(set); + this.updateSetsUI(); + } + + updateSetsUI() { + var setsString = ""; + if(this.human) { + for (var i = 0; i < this.sets.length; i++) { + var toAdd = " |" + this.sets[i] + "s| "; + + switch (this.sets[i]) { + case 11: + toAdd = " |Jacks| "; + break; + case 12: + toAdd = " |Queens| "; + break; + case 13: + toAdd = " |Kings| "; + break; + case 1: + toAdd = " |Aces| "; + break; + default: + } + setsString += toAdd; + } + $('#humanSets').html(setsString); + } else { + for (var i = 0; i < this.sets.length; i++) { + var toAdd = " |" + this.sets[i] + "s| "; + + switch (this.sets[i]) { + case 11: + toAdd = " |Jacks| "; + break; + case 12: + toAdd = " |Queens| "; + break; + case 13: + toAdd = " |Kings| "; + break; + case 1: + toAdd = " |Aces| "; + break; + default: + } + setsString += toAdd; + } + $('#opponentContainer').children("[number=" + (this.id-1) + "]").eq(0).children(".opponentSets").eq(0).html(setsString); + } + } + + getNumSets() { + return this.sets.length; + } + + getSets() { + return this.sets; + } +} + +// Human +class Human { + constructor() { + this.cardContainer; + } + + setCardContainer() { + this.cardContainer = $("#cardContainer"); + } + + populateCardContainer(hand) { + this.clearBoard(); + var cardCount = 0; + for (var i = 0; i < hand.length; i++) { + cardCount++; + this.addCardToContainer(hand[i]); + } + } + + clearBoard() { + var cardContainer = $("#cardContainer").empty(); + } + + addCardToContainer(card) { + $("#cardContainer").append("\"A"); + } + + emptyHand() { + $("#continue").html("Draw Card"); + searchValue = "drawCard"; + searchPlayer = "drawCard"; + } + + fullHand() { + $("#continue").html("Take Turn"); + searchValue = "x"; + searchPlayer = "x"; + } +} + +// Global SFX +class Sounds { + constructor() { + + } +} diff --git a/Games/Go-fish-master/pages/ins.html b/Games/Go-fish-master/pages/ins.html new file mode 100644 index 0000000000..fd6cddab67 --- /dev/null +++ b/Games/Go-fish-master/pages/ins.html @@ -0,0 +1,30 @@ + + + + + Go Fish + + + +
+

Let's Play Go Fish!

+ Back +

The aim of the game is to collect the most 'tricks' or 'sets'.

+

To begin, press 'Start Game' and enter the number of players (including yoruself) that you want to play.

+
+ +
+
+ + +
+ + diff --git a/Games/Go-fish-master/pages/main.html b/Games/Go-fish-master/pages/main.html new file mode 100644 index 0000000000..8afc026a27 --- /dev/null +++ b/Games/Go-fish-master/pages/main.html @@ -0,0 +1,64 @@ + + + + + Go Fish + + + +
+

Go Fish!

+ +

Here is where you will see a breakdown of your last turn

+ + +
+ +
+

Your Opponents

+
+ +
+
+ +
+

Your Cards

+
+ A card + A card + A card + A card + A card + A card + A card + A card +
+
+ +
+ + +
+ + diff --git a/README.md b/README.md index 2c1c8311a0..9998b725b9 100644 --- a/README.md +++ b/README.md @@ -790,10 +790,9 @@ This repository also provides one such platforms where contributers come over an |[Dot_Box_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Dot_Box_Game)| | [Cosmic_Blast](https://github.com/kunjgit/GameZone/tree/main/Games/Cosmic_Blast) | |[Mole](https://github.com/taneeshaa15/GameZone/tree/main/Games/Mole)| +| [Go-fish-master](https://github.com/kunjgit/GameZone/tree/main/Games/Go-fish-master) | |[Pottery-Game](https://github.com/kunjgit/GameZone/tree/main/Games/Pottery-Game)| - - | [Ganesh QR Maker](https://github.com/kunjgit/GameZone/tree/main/Games/Ganesh_QR_Maker) | - + | [Ganesh_QR_Maker](https://github.com/kunjgit/GameZone/tree/main/Games/Ganesh_QR_Maker) | |[Wheel_of_Fortunes](https://github.com/Saipradyumnagoud/GameZone/tree/main/Games/Wheel_of_Fortunes)| |[Tic-tac-toe](https://github.com/Saipradyumnagoud/GameZone/tree/main/Games/Tic-tac-toe)| diff --git a/assets/images/Go-fish-master.png b/assets/images/Go-fish-master.png new file mode 100644 index 0000000000..c8aa8e9b2d Binary files /dev/null and b/assets/images/Go-fish-master.png differ