Last active
November 4, 2015 21:23
-
-
Save CasonBarnhill/cf178f32ebf5c09bd303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using RestSharp; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Week3day2 | |
{ | |
class Program | |
{ | |
private class DeckResponse | |
{ | |
public bool succcess{ get; set; } | |
public string deck_id { get; set; } | |
public bool shuffled { get; set; } | |
public int remaining { get; set; } | |
public List<Card> cards { get; set; } | |
} | |
static void Main(string[] args) | |
{ | |
//Generate a deck and shuffle it | |
var client = new RestClient("http://deckofcardsapi.com"); | |
var request = new RestRequest("api/deck/new/shuffle/?deck_count=1", Method.GET); | |
DeckResponse response = client.Execute<DeckResponse>(request).Data; | |
//Deal 5 cards out 3 times to different hands | |
var deal5cards = new RestRequest($"api/deck/{response.deck_id}/draw/?count=5"); | |
DeckResponse player1cards = client.Execute<DeckResponse>(deal5cards).Data; | |
DeckResponse player2cards = client.Execute<DeckResponse>(deal5cards).Data; | |
DeckResponse player3cards = client.Execute<DeckResponse>(deal5cards).Data; | |
// Console.WriteLine(player1cards.cards.Sum(x => x.CardValue)); | |
// Console.WriteLine(player2cards.cards.Sum(x => x.CardValue)); | |
// Console.WriteLine(player3cards.cards.Sum(x => x.CardValue)); | |
//Show All 3 players hands. When displaying each hand show the total value.. | |
//of the hand and also display all 5 cards. | |
Console.WriteLine($"Player 1 hand value: {player1cards.cards.Sum(x => x.CardValue)}."); | |
var player1CardImages = (player1cards.cards.Select(x => x.code)); | |
foreach (var s in player1CardImages) | |
{ | |
Console.WriteLine(s); | |
} | |
Console.WriteLine(player1cards.cards.Select(x => x.code)); | |
Console.WriteLine($"Player 2 hand value: {player2cards.cards.Sum(x => x.CardValue)}."); | |
var player2CardImages = (player1cards.cards.Select(x => x.code)); | |
foreach (var s in player2CardImages) | |
{ | |
Console.WriteLine(s); | |
} | |
Console.WriteLine(player1cards.cards.Select(x => x.code)); | |
Console.WriteLine($"Player 3 hand value: {player1cards.cards.Sum(x => x.CardValue)}."); | |
var player3CardImages = (player2cards.cards.Select(x => x.code)); | |
foreach (var s in player3CardImages) | |
{ | |
Console.WriteLine(s); | |
} | |
Console.WriteLine(player1cards.cards.Select(x => x.code)); | |
//Indicate which hand has the highest value and what that value is. | |
var player1HighValue = player1cards.cards.Sum(x => x.CardValue); | |
var player2HighValue = player2cards.cards.Sum(x => x.CardValue); | |
var player3HighValue = player3cards.cards.Sum(x => x.CardValue); | |
if (player1HighValue>player2HighValue && player1HighValue>player3HighValue) | |
{ | |
Console.WriteLine($"Player1 has the highest hand of {player1HighValue}"); | |
} | |
if (player2HighValue > player1HighValue && player2HighValue > player3HighValue) | |
{ | |
Console.WriteLine($"Player2 has the highest hand of {player2HighValue}"); | |
} | |
if (player3HighValue > player1HighValue && player3HighValue > player2HighValue) | |
{ | |
Console.WriteLine($"Player3 has the highest hand of {player3HighValue}"); | |
} | |
//Show the min and max card for each hand. | |
var player1LowCard = player1cards.cards.Min(x => x.CardValue); | |
var player2LowCard = player2cards.cards.Min(x => x.CardValue); | |
var player3LowCard = player3cards.cards.Min(x => x.CardValue); | |
Console.WriteLine($"Player1 low card is {player1LowCard}"); | |
Console.WriteLine($"Player2 low card is {player2LowCard}"); | |
Console.WriteLine($"Player3 low card is {player3LowCard}"); | |
var player1HighCard = player1cards.cards.Max(x => x.CardValue); | |
var player2HighCard = player2cards.cards.Max(x => x.CardValue); | |
var player3HighCard = player3cards.cards.Max(x => x.CardValue); | |
Console.WriteLine($"Player1 high card is {player1HighCard}"); | |
Console.WriteLine($"Player2 high card is {player2HighCard}"); | |
Console.WriteLine($"Player3 high card is {player3HighCard}"); | |
//Display which hand has the most hearts. | |
var player1Hearts = player1cards.cards.Count(x => x.suit == "HEARTS"); | |
var player2Hearts = player2cards.cards.Count(x => x.suit == "HEARTS"); | |
var player3Hearts = player3cards.cards.Count(x => x.suit == "HEARTS"); | |
if (player1Hearts> player2Hearts && player1Hearts>player3Hearts) | |
{ | |
Console.WriteLine($"Player 1 has {player1Hearts} Hearts, which is the most"); | |
} | |
if (player2Hearts> player1Hearts && player2Hearts>player3Hearts) | |
{ | |
Console.WriteLine($"Player 2 has {player2Hearts} Hearts, which is the most"); | |
} | |
if (player3Hearts> player1Hearts && player3Hearts> player2Hearts) | |
{ | |
Console.WriteLine($"Player 3 has {player3Hearts} Hearts, which is the most"); | |
} | |
Console.ReadLine(); | |
} | |
} | |
public class Card | |
{ | |
public string image { get; set; } | |
public string value { get; set; } | |
public string suit { get; set; } | |
public string code { get; set; } | |
public int CardValue | |
{ | |
get | |
{ | |
switch (this.value) | |
{ | |
case "ACE": | |
return 1; | |
case "JACK": | |
return 10; | |
case "QUEEN": | |
return 10; | |
case "KING": | |
return 10; | |
default: | |
return int.Parse(this.value); | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment