Created
October 3, 2015 17:31
-
-
Save bolenton/c31dd9abb074b0715f51 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 System.Web; | |
namespace WarCardGame | |
{ | |
class Dealer | |
{ | |
Random rand = new Random(); | |
public void DealPlayersDeck(Deck cards, Dictionary<int, string> humanDeck, Dictionary<int, string> computerDeck) | |
{ | |
var fullDeck = cards.CreateNewDeck(); | |
List<int> keyList = new List<int>(fullDeck.Keys); | |
// shuffle list and take first 26 items from it | |
var shuffled = keyList.OrderBy(item => rand.Next()).ToList(); | |
var keyListfirst = shuffled.Take(26).ToList(); | |
// loop on keylist | |
foreach (var randKey in keyListfirst) | |
{ | |
humanDeck.Add(randKey, fullDeck[randKey]); | |
fullDeck.Remove(randKey); | |
} | |
// take the rest of the list | |
var keyListrest = shuffled.Skip(26).ToList(); | |
foreach (var randKey in keyListrest) | |
{ | |
computerDeck.Add(randKey, fullDeck[randKey]); | |
fullDeck.Remove(randKey); | |
} | |
} | |
} | |
} |
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 System.Collections.Generic; | |
namespace WarCardGame | |
{ | |
class Deck | |
{ | |
public Dictionary<int, string> CreateNewDeck() | |
{ | |
Dictionary<int, string> newDeck = new Dictionary<int, string>() | |
{ | |
{1, "~/cards/c1.png"}, {2, "~/cards/c2.png"}, {3, "~/cards/c3.png"}, {4, "~/cards/c4.png"}, | |
{5, "~/cards/c5.png"}, {6, "~/cards/c6.png"}, {7, "~/cards/c7.png"}, {8, "~/cards/c8.png"}, | |
{9, "~/cards/c9.png"}, {10, "~/cards/c10.png"}, {11, "~/cards/cj.png"}, {12, "~/cards/cq.png"}, {13, "~/cards/ck.png"}, | |
{14, "~/cards/d1.png"}, {15, "~/cards/d2.png"}, {16, "~/cards/d3.png"}, {17, "~/cards/d4.png"}, | |
{18, "~/cards/d5.png"}, {19, "~/cards/d6.png"}, {20, "~/cards/d7.png"}, {21, "~/cards/d8.png"}, | |
{22, "~/cards/d9.png"}, {23, "~/cards/d10.png"}, {24, "~/cards/dj.png"}, {25, "~/cards/dq.png"}, {26, "~/cards/dk.png"}, | |
{27, "~/cards/h1.png"}, {28, "~/cards/h2.png"}, {29, "~/cards/h3.png"}, {30, "~/cards/h4.png"}, | |
{31, "~/cards/h5.png"}, {32, "~/cards/h6.png"}, {33, "~/cards/h7.png"}, {34, "~/cards/h8.png"}, | |
{35, "~/cards/h9.png"}, {36, "~/cards/h10.png"}, {37, "~/cards/hj.png"}, {38, "~/cards/hq.png"}, {39, "~/cards/hk.png"}, | |
{40, "~/cards/s1.png"}, {41, "~/cards/s2.png"}, {42, "~/cards/s3.png"}, {43, "~/cards/s4.png"}, | |
{44, "~/cards/s5.png"}, {45, "~/cards/s6.png"}, {46, "~/cards/s7.png"}, {47, "~/cards/s8.png"}, | |
{48, "~/cards/s9.png"}, {49, "~/cards/s10.png"}, {50, "~/cards/sj.png"}, {51, "~/cards/sq.png"}, {52, "~/cards/sk.png"}, | |
}; | |
return newDeck; | |
} | |
} | |
} |
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
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WarCardGame.Default" %> | |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title></title> | |
<style type="text/css"> | |
.auto-style1 { | |
text-align: center; | |
} | |
.auto-style2 { | |
background-color: #FFFF99; | |
} | |
</style> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
<h1 class="auto-style1">Mega War The Card Game</h1> | |
<h3 class="auto-style1">Created by Taurus Omejia<br /> | |
<br /> | |
</h3> | |
<h3 class="auto-style1"> | |
<asp:Image ID="warImage" runat="server" /> | |
</h3> | |
<p class="auto-style1"> | |
<asp:Label ID="computerDeckLabel" runat="server"></asp:Label> | |
<asp:ImageButton ID="computerDeckImage" runat="server" /> | |
| |
<asp:Image ID="computerActiveCard1" runat="server" /> | |
| |
<asp:Image ID="playerActiveCard1" runat="server" /> | |
| |
<asp:ImageButton ID="playerDeckImage" runat="server" OnClick="playerDeckImage_Click" /> | |
<asp:Label ID="playerDeckLabel" runat="server"></asp:Label> | |
</p> | |
<p class="auto-style1"> | |
| |
<asp:Label ID="computerCardInfo" runat="server"></asp:Label> | |
| |
<asp:Label ID="playerCardInfo" runat="server"></asp:Label> | |
</p> | |
<p class="auto-style1"> | |
| |
</p> | |
<h3 class="auto-style1"> | |
<asp:TextBox ID="playerNameTB" runat="server"></asp:TextBox> | |
</h3> | |
<p class="auto-style1"> | |
<strong> | |
<asp:Label ID="gameInfoLabel" runat="server" CssClass="auto-style2"></asp:Label> | |
</strong> | |
</p> | |
<h3 class="auto-style1"> | |
<asp:Button ID="playGameBTN" runat="server" OnClick="playGameBTN_Click" Text="Play Game" /> | |
<br /> | |
</h3> | |
</div> | |
<p class="auto-style1"> | |
<asp:Label ID="resultLabel" runat="server"></asp:Label> | |
</p> | |
</form> | |
</body> | |
</html> |
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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace WarCardGame | |
{ | |
public partial class Default : System.Web.UI.Page | |
{ | |
static Dealer dealer = new Dealer(); | |
static Player humanPlayer = new Player(); | |
static Player computerPlayer = new Player(); | |
Dictionary<int, string> playerDeck = humanPlayer.playerDeck; | |
static Dictionary<int, string> computerDeck = computerPlayer.playerDeck; | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (!Page.IsPostBack) | |
{ | |
//ViewState.Add("playerMoney", 500); | |
//moneyLabel.Text = ViewState["playerMoney"].ToString(); | |
warImage.ImageUrl = "~/cards/war.png"; | |
warImage.Height = 200; | |
gameInfoLabel.Text = "Enter your name and click 'Play Game'"; | |
playerDeckImage.Visible = false; | |
computerDeckImage.Visible = false; | |
} | |
} | |
protected void playGameBTN_Click(object sender, EventArgs e) | |
{ | |
GameEngine myGame = new GameEngine(); | |
//Load the deck and dealer and the players | |
Deck myDeck = new Deck(); | |
//Dealer deals 26 cards to each player | |
dealer.DealPlayersDeck(myDeck, playerDeck, computerDeck); | |
setUp(); | |
} | |
protected void playerDeckImage_Click(object sender, System.Web.UI.ImageClickEventArgs e) | |
{ | |
var playerCard = humanPlayer.drawCard(playerDeck); | |
int computerCard = computerPlayer.drawCard(computerDeck); | |
playerActiveCard1.ImageUrl = playerDeck[playerCard]; | |
computerActiveCard1.ImageUrl = computerDeck[computerCard]; | |
//humanPlayer.returnCardToDeck(playerDeck, playerCard); | |
//computerPlayer.returnCardToDeck(computerDeck, computerCard); | |
resultLabel.Text = "You won this round, draw you next card!"; | |
} | |
public void setUp() | |
{ | |
var playerName = playerNameTB.Text; | |
playerDeckImage.ImageUrl = "~/cards/b2fv.png"; | |
playerDeckImage.Visible = true; | |
computerDeckImage.ImageUrl = "~/cards/b2fv.png"; | |
computerDeckImage.Visible = true; | |
gameInfoLabel.Text = "Draw a card from your deck " + playerName; | |
playGameBTN.Visible = false; | |
playerNameTB.Visible = false; | |
warImage.Visible = false; | |
playerDeckLabel.Text = playerName + " Deck"; | |
computerDeckLabel.Text = "Siri's Deck"; | |
} | |
} | |
} |
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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace WarCardGame | |
{ | |
public class Player | |
{ | |
public Random rand = new Random(); | |
public Dictionary<int, string> playerDeck { get; set; } | |
public Player() | |
{ | |
playerDeck = new Dictionary<int, string>(); | |
} | |
//both players need to Draw cards | |
//public int drawCard(Dictionary<int, string> playerDeck) | |
//{ | |
// return playerDeck.First().Key; | |
//} | |
//winner needs cards return to bottom of deck | |
//public void returnCardToDeck(Dictionary<int, string> playerDeck, int card) | |
//{ | |
// playerDeck.Add(card, playerDeck[card]); | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment