Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #9 - writing a basic game
New Posts  All Forums:Forum Nav:

# Programming Challenge #9 - writing a basic game - Page 2

Quote:
Originally Posted by DizZz

Thanks for making these up they're a fun little challenge
My pleasure
Quote:
Originally Posted by Jiiks

Sure
Cheers mate
Quote:
Originally Posted by Thereoncewasamaninparis

Well I am going all out, all I have to do today is sit for a TB or two of files to be parsed.

EDIT: Did everyone elses' buttons to include, URL, images, formatting etc etc disappear?
It's all there for me. Possibly a browser caching bug?
Seems like a fun challange. Will try it when I want to get a break from my current project.
 Dell UltraSharp U2312HM Dell UltraSharp U2312HM Overkill FTW! (21 items) For Sale: [For Sale] [Global] iPod Nano 4th Generation 8GB Blue £29.99 (GBP) or best offer
 Dell UltraSharp U2312HM Dell UltraSharp U2312HM Overkill FTW! (21 items) For Sale: [For Sale] [Global] iPod Nano 4th Generation 8GB Blue £29.99 (GBP) or best offer
Simple attempt at the "hard" problem. Hasn't been thoroughly tested but seems to function correctly.
Spoiler code (Click to show)
Code:
``````#!/usr/bin/pypy

from random import shuffle

ranks = "23456789TJQKA"
suits = "SCDH"
deck = [r+s for r in ranks for s in suits]

def score(hand):
result = 0
aces = 0
for card in hand:
card = card[:-1]
if card in "TJQK":
result += 10
elif card == "A":
result += 11
aces += 1
else:
result += int(card)
while result > 21 and aces > 0:
result -= 10
aces -= 1
return result

def display(hand):
return " ".join(hand)

def play():
currentDeck = list(deck)
shuffle(currentDeck)
dealerHand = [currentDeck.pop(), currentDeck.pop()]
dealerValue = score(dealerHand)
print "Dealer:", dealerHand[0], "?"
playerHand = [currentDeck.pop(), currentDeck.pop()]
playerValue = score(playerHand)
print "You:", display(playerHand), "Score:", playerValue
playing = False
if playerValue < 21:
while playing:
playerHand.append(currentDeck.pop())
playerValue = score(playerHand)
print "You:", display(playerHand), "Score:", playerValue
playing = False
if playerValue < 21:
if playerValue == 21:
print "Blackjack! You won."
return
if playerValue > 21:
print "Bust! You lost."
return
print "Dealer:", display(dealerHand), "Score:", dealerValue
playing = (dealerValue < playerValue)
while playing:
dealerHand.append(currentDeck.pop())
dealerValue = score(dealerHand)
print "Dealer:", display(dealerHand), "Score:", dealerValue
playing = False
if dealerValue < 21:
playing = (dealerValue <= playerValue)
if dealerValue > 21:
print "Dealer bust! You won."
return
print "Dealer won. You lost."

while True:
response = raw_input(message + " [y/n]: ")
if response == "n":
return False
if response == "y":
return True
print "Invalid response"

running = True
while running:
play()
```
Sample Output (Click to show)
Code:
``````\$ ./blackjack.py
Dealer: 7C ?
You: JH 2S Score: 12
Hit? [y/n]: n
Dealer: 7C AH Score: 18
Dealer won. You lost.
Play again? [y/n]: y
Dealer: 2C ?
Hit? [y/n]: n
Dealer: 2C QD Score: 12
Dealer: 2C QD 8S Score: 20
Dealer won. You lost.
Play again? [y/n]: y
Dealer: 9C ?
You: QC 5D Score: 15
Hit? [y/n]: n
Dealer: 9C 2S Score: 11
Dealer: 9C 2S 3C Score: 14
Dealer: 9C 2S 3C AC Score: 15
Dealer: 9C 2S 3C AC KS Score: 25
Dealer bust! You won.
Play again? [y/n]: n```
```
 Mythos (16 items)
CPUMotherboardGraphicsRAM
Intel i7 4770k EVGA Z87 Stinger EVGA 780 Ti SC Corsair Vengeance LP 16GB (2 x 8GB) DDR3 1600
Hard DriveHard DriveHard DriveCooling
Corsair Neutron GTX 240GB Samsung 850 EVO 250GB WD VelociRaptor (2x 300GB RAID 0) Corsair H75
OSMonitorKeyboardPower
Windows 8.1 Pro (64-bit) Asus VG248QE Filco Majestouch 2 TKL (Cherry Black) Corsair CX600 (600W Bronze)
CaseMouse
Fractal Node 304 Steelseries Sensei
 Mythos (16 items)
CPUMotherboardGraphicsRAM
Intel i7 4770k EVGA Z87 Stinger EVGA 780 Ti SC Corsair Vengeance LP 16GB (2 x 8GB) DDR3 1600
Hard DriveHard DriveHard DriveCooling
Corsair Neutron GTX 240GB Samsung 850 EVO 250GB WD VelociRaptor (2x 300GB RAID 0) Corsair H75
OSMonitorKeyboardPower
Windows 8.1 Pro (64-bit) Asus VG248QE Filco Majestouch 2 TKL (Cherry Black) Corsair CX600 (600W Bronze)
CaseMouse
Fractal Node 304 Steelseries Sensei
Here's my entry. This should meet the Hardest criteria. Implemented everything in Hard, and also implements Doubling Down, Dealer stands on 16, and winner is automatically declared if they draw 21.

Edit: Forgive the crappy console interface. I was just trying to get it done quick.
C# Code (Click to show)
Code:
``````using System;
using System.Collections.Generic;
using System.Linq;

namespace BlackJack
{
class Program
{
static void Main(string[] args)
{
bool playAgain = true;

while (playAgain)
{
bool firstDraw = true;
deck newDeck = new deck();
dealer dealer = new dealer();
player player = new player();

newDeck.shuffleDeck();
//newDeck.printDeck();

newDeck.deal(dealer, player);
Console.Clear();

dealer.showFirstHand();
player.showHand();

if (dealer.handValue == 21)
{
Console.WriteLine("Dealer has BlackJack!");
Console.WriteLine("Dealer Wins");
}
else if (player.handValue == 21)
{
Console.WriteLine("Player has BlackJack!!!");
Console.WriteLine("Player Wins!");
}
else
{

bool playerDraw = true;
while (playerDraw)
{
if (firstDraw)
Console.Write("Draw Another Card? (Y/N) or press D to Double Down ");
else
Console.Write("Draw Another Card? (Y/N)");
bool validkey = false;
string key = "";
while (validkey == false)
{

if (KeyPressed == ConsoleKey.Y.ToString() || KeyPressed == ConsoleKey.N.ToString() || (firstDraw && KeyPressed == ConsoleKey.D.ToString()))
{
Console.WriteLine(KeyPressed);
key = KeyPressed;
validkey = true;
firstDraw = false;
}
}

if (key == "Y")
{
player.drawCard(newDeck.dealNextCard());

if (player.handValue >= 21)
{
playerDraw = false;
}
}
else if (key == "D")
{
player.drawCard(newDeck.dealNextCard());

if (player.handValue >= 21)
{
playerDraw = false;
}

playerDraw = false;
}
else
{
playerDraw = false;
}
}

if (player.handValue <= 21)
{
Console.WriteLine();
bool dealerDraw = true;
while (dealerDraw)
{
if (dealer.handValue <= 16)
{
dealer.drawCard(newDeck.dealNextCard());
}
else
{
dealerDraw = false;
}
}
}

Console.WriteLine();
Console.WriteLine("Dealer's Hand: " + dealer.handValue);
Console.WriteLine("Player's Hand: " + player.handValue);
Console.WriteLine();

if (player.handValue == dealer.handValue)
Console.WriteLine("Tie game");
else
{
string winner = "";

if (player.handValue > 21)
winner = "Dealer";
else if (dealer.handValue > 21)
winner = "Player";
else if (player.handValue > dealer.handValue)
winner = "Player";
else if (dealer.handValue > player.handValue)
winner = "Dealer";

Console.WriteLine(winner + " WINS!");
}
}

Console.WriteLine();
Console.Write("Play Again? ");

if (playKey == ConsoleKey.Y.ToString() || playKey == ConsoleKey.N.ToString())
{
Console.WriteLine(playKey);
Console.WriteLine();
if (playKey == "N")
playAgain = false;
}

}
}
}

public class dealer
{
private List<card> hand = new List<card>();
public int handValue;

public dealer()
{
handValue = 0;
}

public void drawCard(card _card)
{
handValue += _card.faceValue;

if (handValue > 21 && hand.Where(a => a.faceValue == 11).Count() > 0)
{
card ace = hand.First(c => c.faceValue == 11);
hand.Remove(ace);
ace.faceValue = 1;
handValue -= 10;
}

Console.WriteLine("Dealer Draws: " + _card.name + " of " + _card.suit + "s");
Console.WriteLine("New Hand Value: " + handValue);
}

public void showFirstHand()
{
Console.WriteLine("Dealer's Cards:");
Console.WriteLine("**** of ****");
Console.WriteLine(hand[1].name + " of " + hand[1].suit + "s");
Console.WriteLine();
}

public void showHand()
{
Console.WriteLine("Dealer's Cards:");

foreach (card card in hand)
{
Console.WriteLine(card.name + " of " + card.suit + "s");
}

Console.WriteLine("Hand Value: " + handValue);
Console.WriteLine();
}
}

public class player
{
private List<card> hand = new List<card>();
public int handValue;

public player()
{
handValue = 0;
}

public void drawCard(card _card)
{
handValue += _card.faceValue;

if (handValue > 21 && hand.Where(a => a.faceValue == 11).Count() > 0)
{
card ace = hand.First(c => c.faceValue == 11);
hand.Remove(ace);
ace.faceValue = 1;
handValue -= 10;
}

Console.WriteLine("Player Draws: " + _card.name + " of " + _card.suit + "s");
Console.WriteLine("New Hand Value: " + handValue);
}

public void showHand()
{
Console.WriteLine("Player's Cards:");

foreach (card card in hand)
{
Console.WriteLine(card.name + " of " + card.suit + "s");
}

Console.WriteLine("Hand Value: " + handValue);
Console.WriteLine();
}
}

public class deck
{
List<card> cards = new List<card>();
int nextCard;

public deck()
{
nextCard = 0;
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 14; j++)
{
}
}
}

public void shuffleDeck()
{
cards = cards.OrderBy(c => Guid.NewGuid()).ToList<card>();
}

public void deal(dealer dealer, player player)
{
player.drawCard(dealNextCard());
dealer.drawCard(dealNextCard());
player.drawCard(dealNextCard());
dealer.drawCard(dealNextCard());
}

public card dealNextCard()
{
return cards[nextCard++];
}

public void printDeck()
{
foreach (card card in cards)
{
Console.WriteLine(card.name + " of " + card.suit + "s");
}
}
}

public class card
{
public suit suit;
public int value;
public cardName name;
public int faceValue;

public card(suit _suit, int _value)
{
suit = _suit;
value = _value;
name = (cardName)value;
if (value <= 10)
faceValue = value;
else if (value == 14)
faceValue = 11;
else
faceValue = 10;
}

}

public enum suit
{
Heart = 2,
Club = 3,
Diamond = 4
}
public enum cardName
{
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five =5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
Ten = 10,
Jack = 11,
Queen = 12,
King = 13,
Ace = 14
}

}```
```
Sample Output (Click to show)

Edited by wedge - 6/18/13 at 10:36pm
 Death Star (20 items) Darksaber (11 items)
CPUMotherboardGraphicsRAM
Athlon II x2 245 Asus M3A78 Radeon HD6570 1GB Mushkin Silverline 2GB DDR2
Hard DriveOptical DriveOSMonitor
OCZ Vertex 2 120GB Samsung Blu-Ray Windows 7 Samsung 46" DLP
PowerCaseOther
Silverstone Strider Essentials 400W Silverstone Milo ML03B Hauppage WinTV 1250
 Death Star (20 items) Darksaber (11 items)
CPUMotherboardGraphicsRAM
Athlon II x2 245 Asus M3A78 Radeon HD6570 1GB Mushkin Silverline 2GB DDR2
Hard DriveOptical DriveOSMonitor
OCZ Vertex 2 120GB Samsung Blu-Ray Windows 7 Samsung 46" DLP
PowerCaseOther
Silverstone Strider Essentials 400W Silverstone Milo ML03B Hauppage WinTV 1250
Quote:
Originally Posted by Dark Torcher

Simple attempt at the "hard" problem. Hasn't been thoroughly tested but seems to function correctly.
Spoiler code (Click to show)
Code:
``````#!/usr/bin/pypy

from random import shuffle

ranks = "23456789TJQKA"
suits = "SCDH"
deck = [r+s for r in ranks for s in suits]

def score(hand):
result = 0
aces = 0
for card in hand:
card = card[:-1]
if card in "TJQK":
result += 10
elif card == "A":
result += 11
aces += 1
else:
result += int(card)
while result > 21 and aces > 0:
result -= 10
aces -= 1
return result

def display(hand):
return " ".join(hand)

def play():
currentDeck = list(deck)
shuffle(currentDeck)
dealerHand = [currentDeck.pop(), currentDeck.pop()]
dealerValue = score(dealerHand)
print "Dealer:", dealerHand[0], "?"
playerHand = [currentDeck.pop(), currentDeck.pop()]
playerValue = score(playerHand)
print "You:", display(playerHand), "Score:", playerValue
playing = False
if playerValue < 21:
while playing:
playerHand.append(currentDeck.pop())
playerValue = score(playerHand)
print "You:", display(playerHand), "Score:", playerValue
playing = False
if playerValue < 21:
if playerValue == 21:
print "Blackjack! You won."
return
if playerValue > 21:
print "Bust! You lost."
return
print "Dealer:", display(dealerHand), "Score:", dealerValue
playing = (dealerValue < playerValue)
while playing:
dealerHand.append(currentDeck.pop())
dealerValue = score(dealerHand)
print "Dealer:", display(dealerHand), "Score:", dealerValue
playing = False
if dealerValue < 21:
playing = (dealerValue <= playerValue)
if dealerValue > 21:
print "Dealer bust! You won."
return
print "Dealer won. You lost."

while True:
response = raw_input(message + " [y/n]: ")
if response == "n":
return False
if response == "y":
return True
print "Invalid response"

running = True
while running:
play()
```
Sample Output (Click to show)
Code:
``````\$ ./blackjack.py
Dealer: 7C ?
You: JH 2S Score: 12
Hit? [y/n]: n
Dealer: 7C AH Score: 18
Dealer won. You lost.
Play again? [y/n]: y
Dealer: 2C ?
Hit? [y/n]: n
Dealer: 2C QD Score: 12
Dealer: 2C QD 8S Score: 20
Dealer won. You lost.
Play again? [y/n]: y
Dealer: 9C ?
You: QC 5D Score: 15
Hit? [y/n]: n
Dealer: 9C 2S Score: 11
Dealer: 9C 2S 3C Score: 14
Dealer: 9C 2S 3C AC Score: 15
Dealer: 9C 2S 3C AC KS Score: 25
Dealer bust! You won.
Play again? [y/n]: n```
```

Quote:
Originally Posted by wedge

Here's my entry. This should meet the Hardest criteria. Implemented everything in Hard, and also implements Doubling Down, Dealer stands on 16, and winner is automatically declared if they draw 21.

Edit: Forgive the crappy console interface. I was just trying to get it done quick.
C# Code (Click to show)
Code:
``````using System;
using System.Collections.Generic;
using System.Linq;

namespace BlackJack
{
class Program
{
static void Main(string[] args)
{
bool playAgain = true;

while (playAgain)
{
bool firstDraw = true;
deck newDeck = new deck();
dealer dealer = new dealer();
player player = new player();

newDeck.shuffleDeck();
//newDeck.printDeck();

newDeck.deal(dealer, player);
Console.Clear();

dealer.showFirstHand();
player.showHand();

if (dealer.handValue == 21)
{
Console.WriteLine("Dealer has BlackJack!");
Console.WriteLine("Dealer Wins");
}
else if (player.handValue == 21)
{
Console.WriteLine("Player has BlackJack!!!");
Console.WriteLine("Player Wins!");
}
else
{

bool playerDraw = true;
while (playerDraw)
{
if (firstDraw)
Console.Write("Draw Another Card? (Y/N) or press D to Double Down ");
else
Console.Write("Draw Another Card? (Y/N)");
bool validkey = false;
string key = "";
while (validkey == false)
{

if (KeyPressed == ConsoleKey.Y.ToString() || KeyPressed == ConsoleKey.N.ToString() || (firstDraw && KeyPressed == ConsoleKey.D.ToString()))
{
Console.WriteLine(KeyPressed);
key = KeyPressed;
validkey = true;
firstDraw = false;
}
}

if (key == "Y")
{
player.drawCard(newDeck.dealNextCard());

if (player.handValue >= 21)
{
playerDraw = false;
}
}
else if (key == "D")
{
player.drawCard(newDeck.dealNextCard());

if (player.handValue >= 21)
{
playerDraw = false;
}

playerDraw = false;
}
else
{
playerDraw = false;
}
}

if (player.handValue <= 21)
{
Console.WriteLine();
bool dealerDraw = true;
while (dealerDraw)
{
if (dealer.handValue <= 16)
{
dealer.drawCard(newDeck.dealNextCard());
}
else
{
dealerDraw = false;
}
}
}

Console.WriteLine();
Console.WriteLine("Dealer's Hand: " + dealer.handValue);
Console.WriteLine("Player's Hand: " + player.handValue);
Console.WriteLine();

if (player.handValue == dealer.handValue)
Console.WriteLine("Tie game");
else
{
string winner = "";

if (player.handValue > 21)
winner = "Dealer";
else if (dealer.handValue > 21)
winner = "Player";
else if (player.handValue > dealer.handValue)
winner = "Player";
else if (dealer.handValue > player.handValue)
winner = "Dealer";

Console.WriteLine(winner + " WINS!");
}
}

Console.WriteLine();
Console.Write("Play Again? ");

if (playKey == ConsoleKey.Y.ToString() || playKey == ConsoleKey.N.ToString())
{
Console.WriteLine(playKey);
Console.WriteLine();
if (playKey == "N")
playAgain = false;
}

}
}
}

public class dealer
{
private List<card> hand = new List<card>();
public int handValue;

public dealer()
{
handValue = 0;
}

public void drawCard(card _card)
{
handValue += _card.faceValue;

if (handValue > 21 && hand.Where(a => a.faceValue == 11).Count() > 0)
{
card ace = hand.First(c => c.faceValue == 11);
hand.Remove(ace);
ace.faceValue = 1;
handValue -= 10;
}

Console.WriteLine("Dealer Draws: " + _card.name + " of " + _card.suit + "s");
Console.WriteLine("New Hand Value: " + handValue);
}

public void showFirstHand()
{
Console.WriteLine("Dealer's Cards:");
Console.WriteLine("**** of ****");
Console.WriteLine(hand[1].name + " of " + hand[1].suit + "s");
Console.WriteLine();
}

public void showHand()
{
Console.WriteLine("Dealer's Cards:");

foreach (card card in hand)
{
Console.WriteLine(card.name + " of " + card.suit + "s");
}

Console.WriteLine("Hand Value: " + handValue);
Console.WriteLine();
}
}

public class player
{
private List<card> hand = new List<card>();
public int handValue;

public player()
{
handValue = 0;
}

public void drawCard(card _card)
{
handValue += _card.faceValue;

if (handValue > 21 && hand.Where(a => a.faceValue == 11).Count() > 0)
{
card ace = hand.First(c => c.faceValue == 11);
hand.Remove(ace);
ace.faceValue = 1;
handValue -= 10;
}

Console.WriteLine("Player Draws: " + _card.name + " of " + _card.suit + "s");
Console.WriteLine("New Hand Value: " + handValue);
}

public void showHand()
{
Console.WriteLine("Player's Cards:");

foreach (card card in hand)
{
Console.WriteLine(card.name + " of " + card.suit + "s");
}

Console.WriteLine("Hand Value: " + handValue);
Console.WriteLine();
}
}

public class deck
{
List<card> cards = new List<card>();
int nextCard;

public deck()
{
nextCard = 0;
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 14; j++)
{
}
}
}

public void shuffleDeck()
{
cards = cards.OrderBy(c => Guid.NewGuid()).ToList<card>();
}

public void deal(dealer dealer, player player)
{
player.drawCard(dealNextCard());
dealer.drawCard(dealNextCard());
player.drawCard(dealNextCard());
dealer.drawCard(dealNextCard());
}

public card dealNextCard()
{
return cards[nextCard++];
}

public void printDeck()
{
foreach (card card in cards)
{
Console.WriteLine(card.name + " of " + card.suit + "s");
}
}
}

public class card
{
public suit suit;
public int value;
public cardName name;
public int faceValue;

public card(suit _suit, int _value)
{
suit = _suit;
value = _value;
name = (cardName)value;
if (value <= 10)
faceValue = value;
else if (value == 14)
faceValue = 11;
else
faceValue = 10;
}

}

public enum suit
{
Heart = 2,
Club = 3,
Diamond = 4
}
public enum cardName
{
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five =5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
Ten = 10,
Jack = 11,
Queen = 12,
King = 13,
Ace = 14
}

}```
```
Sample Output (Click to show)

Nice work guys
My attempt
Python 2.7 Source code (Click to show)
Code:
``````#!/usr/bin/python

from Tkinter import *
from PIL import Image, ImageTk
from random import shuffle
from urllib2 import urlopen
import io

images = []
photos = []
card = []

class Deck(object):

def __init__(self):
self.suits = ['C', 'S', 'H', 'D']
self.ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
self.deck = [(rank, suit) for rank in self.ranks for suit in self.suits]
self.shuffle()
self.card_size = (73,98)
self.played_cards = []
self.card_face = ['http://imageshack.us/a/img9/6783/n8k4.jpg', 'http://imageshack.us/a/img577/9144/lkpr.jpg', 'http://imageshack.us/a/img16/7974/kz19.jpg', 'http://imageshack.us/a/img341/1584/kow9.jpg',\
'http://imageshack.us/a/img96/3832/9sij.jpg', 'http://imageshack.us/a/img593/5210/ax4f.jpg', 'http://imageshack.us/a/img18/5531/wv1t.jpg', 'http://imageshack.us/a/img534/4296/zpdb.jpg',\
'http://imageshack.us/a/img189/846/s6m5.jpg', 'http://imageshack.us/a/img819/5116/h39j.jpg', 'http://imageshack.us/a/img59/161/jnxb.jpg', 'http://imageshack.us/a/img35/3619/ykxe.jpg',\
'http://imageshack.us/a/img51/4187/ubrw.jpg', 'http://imageshack.us/a/img35/4148/8etg.jpg', 'http://imageshack.us/a/img856/8139/k233.jpg', 'http://imageshack.us/a/img713/5533/k6ld.jpg',\
'http://imageshack.us/a/img854/1117/vvj.jpg', 'http://imageshack.us/a/img5/9364/38va.jpg', 'http://imageshack.us/a/img401/4606/m635.jpg', 'http://imageshack.us/a/img600/1197/zdm9.jpg',\
'http://imageshack.us/a/img27/9006/83a6.jpg', 'http://imageshack.us/a/img5/6156/mslt.jpg', 'http://imageshack.us/a/img9/7453/j6i1.jpg', 'http://imageshack.us/a/img221/2149/7w3p.jpg',\
'http://imageshack.us/a/img266/2544/0eku.jpg', 'http://imageshack.us/a/img407/6823/r3r.jpg', 'http://imageshack.us/a/img834/6500/kllb.jpg', 'http://imageshack.us/a/img842/8531/u14b.jpg',\
'http://imageshack.us/a/img580/1034/x0od.jpg', 'http://imageshack.us/a/img191/7715/a8x0.jpg', 'http://imageshack.us/a/img801/1125/fq3r.jpg', 'http://imageshack.us/a/img845/5820/eaep.jpg',\
'http://imageshack.us/a/img13/6573/6ro1.jpg', 'http://imageshack.us/a/img834/4240/yvfm.jpg', 'http://imageshack.us/a/img841/6792/hcy5.jpg', 'http://imageshack.us/a/img42/9787/oz7a.jpg',\
'http://imageshack.us/a/img163/3135/gm7x.jpg', 'http://imageshack.us/a/img833/6261/z9yv.jpg', 'http://imageshack.us/a/img585/7933/8ark.jpg', 'http://imageshack.us/a/img832/8133/8mre.jpg',\
'http://imageshack.us/a/img838/6276/3h69.jpg', 'http://imageshack.us/a/img22/7359/w5cu.jpg', 'http://imageshack.us/a/img542/4223/6yqn.jpg', 'http://imageshack.us/a/img23/1951/suh1.jpg',\
'http://imageshack.us/a/img7/8003/xpiq.jpg', 'http://imageshack.us/a/img577/7663/olgf.jpg', 'http://imageshack.us/a/img703/5393/0kie.jpg', 'http://imageshack.us/a/img837/8590/dr3d.jpg',\
'http://imageshack.us/a/img600/5778/pn39.jpg', 'http://imageshack.us/a/img109/5589/5ndc.jpg', 'http://imageshack.us/a/img826/6804/pl79.jpg', 'http://imageshack.us/a/img402/482/6ne8.jpg',\
'http://imageshack.us/a/img40/413/aei7.jpg']

self.card_face_index = ['CA','C2','C3','C4','C5','C6','C7','C8','C9','CT','CJ','CQ','CK',\
'SA','S2','S3','S4','S5','S6','S7','S8','S9','ST','SJ','SQ','SK',\
'HA','H2','H3','H4','H5','H6','H7','H8','H9','HT','HJ','HQ','HK',\
'DA','D2','D3','D4','D5','D6','D7','D8','D9','DT','DJ','DQ','DK']

def shuffle(self):
shuffle(self.deck)

def get_card(self):
card = self.deck[0]
self.played_cards.append(card)
del self.deck[0]
return card

for card in cards:
if card not in self.deck:
self.deck.append(card)
if card in self.played_cards:
a=self.played_cards.index(card)
del self.played_cards[a]

def card_face_to_show(self, card):
card_to_show = card[1]+card[0]
card = self.card_face_index.index(card_to_show)
return card

class BlackJack(Deck):

def __init__(self):
super(BlackJack, self).__init__()
self.score = 1
self.player_hand_value = 0
self.dealer_hand_value = 0
self.player_hand = []
self.dealer_hand = []
self.player_bust = False
self.dealer_bust = False
self.dealer_turn = False
self.result =''
self.resultd ='Dealer has ' + str(self.dealer_hand_value) + ' showing'
self.resultp = str(self.player_hand_value) + self.result
self.card_face_position = []
self.win = False
self.double = False
self.values = {'A':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':10, 'Q':10, 'K':10}
self.card_positions_player = [[350, 550], [450, 550],\
[312.5, 575], [400, 575], [487.5, 575],\
[275, 600],[458.33, 600], [441.66, 600], [525, 600],\
[311.5, 625], [478.16, 625]]

self.card_positions_dealer = [[350, 100], [450, 100],\
[312.5, 125], [400, 125], [487.5, 125],\
[275, 150],[358.33, 150], [441.66, 150], [525, 150],\
[311.5, 175], [478.16, 175]]

def deck_size(self):
if len(self.deck) == 0:
temp = []

if len(self.player_hand) > 0:
for cards in range(len(self.player_hand)):
temp.append(self.player_hand[cards])

if len(self.dealer_hand) > 0:
for cards in range(len(self.dealer_hand)):
temp.append(self.dealer_hand[cards])

if len(temp) > 0:
for cards in temp:
index_of_card=self.played_cards.index(cards)
del self.played_cards[index_of_card]

vv=self.played_cards[:]

if len(temp) > 0:
for cards in temp:
self.played_cards.append(cards)

self.shuffle()

def deal_hand(self):
if not self.win:
self.score -= 1

self.player_hand = []
self.dealer_hand = []
self.player_bust = False
self.dealer_bust = False
self.dealer_turn = False
self.win = False
self.delay_count = 0

for a in range(4):
self.deck_size()
card = self.get_card()

if not a % 2:
self.player_hand.append(card)
else:
self.dealer_hand.append(card)

self.player_hand_value = self.total_hand(self.player_hand)
self.dealer_hand_value = self.total_hand(self.dealer_hand)

def hit(self):
if not self.win:

if not self.player_bust:

if not self.dealer_turn and len(self.player_hand) < 11:
self.deck_size()
card = self.get_card()
self.player_hand.append(card)

if not self.dealer_bust:

if self.dealer_turn and len(self.dealer_hand) < 11:
self.deck_size()
card = self.get_card()
self.dealer_hand.append(card)

self.dealer_hand_value = self.total_hand(self.dealer_hand)
self.player_hand_value = self.total_hand(self.player_hand)
self.bust()

def bust(self):
if self.player_hand_value > 21 and not self.player_bust:
self.score -= 1
self.result = str(self.player_hand_value)+' showing, ' + 'Busted,  New Deal?'
self.player_bust = True
self.win = True
if self.double:
self.score -= 1

if self.dealer_hand_value > 21 and not self.dealer_bust:
self.score += 1
self.result = 'Dealer busts, Player wins,  New Deal?'
self.dealer_bust = True
self.win = True
if self.double:
self.score += 1

def stand(self):
if not self.win:
self.dealer_turn = True

def dealer(self):
if not self.win:

if self.dealer_hand_value < 17:
self.hit()

elif self.player_hand_value == self.dealer_hand_value:
self.result = str(self.player_hand_value)+' showing, Tie ' + 'Player Wins,  New Deal?'
self.score += 1
self.win = True
if self.double:
self.score += 1

elif self.player_hand_value < self.dealer_hand_value:
self.result = str(self.player_hand_value)+' showing, ' + 'Dealer Wins,  New Deal?'
self.score -= 1
self.win = True
if self.double:
self.score -= 1

elif self.player_hand_value > self.dealer_hand_value > 16:
self.result = str(self.player_hand_value)+' showing, ' + 'Player Wins,  New Deal?'
self.score +=1
self.win = True
if self.double:
self.score += 1

def total_hand(self, hand):
value = 0
for a in hand:
value += self.values[a[0]]

for a in hand:
if a[0] == 'A' and value -1  < 11:
value +=10

return value

def show_results(self):
if not self.player_bust and not self.win:
self.result = str(self.player_hand_value)+' showing, Hit or Stand?'

if self.dealer_turn:
self.resultd ='Dealer has ' + str(self.dealer_hand_value) + ' showing'

elif not self.dealer_turn and self.dealer_hand[0][0] == 'A':
self.resultd ='Dealer has an ' + str(self.dealer_hand[0][0]) + ' showing'

else:
self.resultd ='Dealer has ' + str(self.values[self.dealer_hand[0][0]]) + ' showing'

return self.result, self.resultd

def update(self, card, pd='player'):
if pd == 'player':
cl = self.card_face_to_show(self.player_hand[card])
cpp = self.card_positions_player[card]

elif pd !='player' and card == 1 and not self.dealer_turn:
cpp = self.card_positions_dealer[card]
return 0, 52, (71, 96), cpp, self.show_results()

elif pd !='player' and self.dealer_turn:
cl = self.card_face_to_show(self.dealer_hand[card])
cpp = self.card_positions_dealer[card]
return 1, cl, (73, 98), cpp, self.show_results()

else:
cl = self.card_face_to_show(self.dealer_hand[card])
cpp = self.card_positions_dealer[card]
return 1, cl, (73, 98), cpp, self.show_results()

self.show_results()

if self.dealer_turn and (not self.win):
self.delay()

return cl, cpp, self.show_results()

def delay(self):
self.delay_count +=1

if self.delay_count == 120:
self.delay_count = 0
self.dealer()

def deal():
for a in range(len(game.dealer_hand)):
i, cl, cs, cpp, result = game.update(a,'dealer')
table_area.coords(card[cl],0,1600)

for a in range(len(game.player_hand)):
cl, cpp, result = game.update(a,'player')
table_area.coords(card[cl],0,1600)
game.double = False
game.deal_hand()

def hit():
game.hit()

def stand():
game.stand()

def double():
game.double = True
game.hit()
game.stand()

def init():
global game , card_face
for a in range(len(card)):
table_area.coords(card[a],0,1600)

game = BlackJack()
game.shuffle()
game.deal_hand()

init()

def draw():

for a in range(len(game.dealer_hand)):
i, cl, cs, cpp, result = game.update(a,'dealer')
if i == 1:
table_area.coords(card[52], 0,1600)
table_area.coords(card[cl], cpp[0],cpp[1])
table_area.tag_raise(card[cl])
table_area.itemconfig(dealer_messages, text = result[1], fill = 'white')

for a in range(len(game.player_hand)):
cl,cpp, result = game.update(a)
table_area.coords(card[cl], cpp[0],cpp[1])
table_area.tag_raise(card[cl])
table_area.itemconfig(player_messages, text = result[0], fill = 'white')

table_area.itemconfig(score, text = 'score ' + str(game.score), fill = 'white')

table_area.after(16,draw)

root = Tk()
root.title("BlackJack")
root.geometry("1025x815+100+100")

control_area = Frame(root)
control_area.pack(side='top')
control_area.grid_columnconfigure(0, weight=0)
control_area.grid_columnconfigure(1, weight=0)

table_area = Canvas(control_area, width=800, height=800)
table_area.configure(bg='Dark Green')
table_area.grid(row=0, column=1, rowspan = 20)

background = Image.open(io.BytesIO(background)).convert('RGBA')
bgd = ImageTk.PhotoImage(background)
bg = table_area.create_image(400,400, image=bgd)

deal = Button(control_area, text = 'Deal', command = deal, fg = 'black')
deal.grid(row=0, column=0)

hit = Button(control_area, text = 'Hit', command = hit, fg = 'black')
hit.grid(row=1, column=0)

stand = Button(control_area, text = 'Stand', command = stand, fg = 'black')
stand.grid(row=2, column=0)

double = Button(control_area, text = 'Double Down', command = double, fg = 'black')
double.grid(row=3, column=0)

reset = Button(control_area, text = 'Reset Game', command = init, fg = 'black')
reset.grid(row=7, column=0)

dealer_messages = table_area.create_text(400, 25, text = '', font = ("Helvetica", 30), fill = 'white')
player_messages = table_area.create_text(400, 770, text = '', font = ("Helvetica", 30), fill = 'white')
score = table_area.create_text(60, 300, text = '', font = ("Helvetica", 20), fill = 'white')

for a in range(len(game.card_face)):
images.append(Image.open(io.BytesIO(img)).convert('RGBA'))
photos.append(ImageTk.PhotoImage(images[a]))
card.append(table_area.create_image(0,1600, image=photos[a]))

draw()
root.mainloop()```
```
Sample output (Click to show)

Edited by tom.slick - 6/25/13 at 2:55pm
 Core I7 (13 items)
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800)
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105
PowerCase
CORSAIR 850TX Cooler Master ATCS 840
 Core I7 (13 items)
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800)
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105
PowerCase
CORSAIR 850TX Cooler Master ATCS 840
Quote:
Originally Posted by tom.slick

My attempt
Python 2.7 Source code (Click to show)
Code:
``````#!/usr/bin/python

from Tkinter import *
from PIL import Image, ImageTk
from random import shuffle
from urllib2 import urlopen
import io

images = []
photos = []
card = []

class Deck(object):

def __init__(self):
self.suits = ['C', 'S', 'H', 'D']
self.ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
self.deck = [(rank, suit) for rank in self.ranks for suit in self.suits]
self.shuffle()
self.card_size = (73,98)
self.played_cards = []
self.card_face = ['http://imageshack.us/a/img9/6783/n8k4.jpg', 'http://imageshack.us/a/img577/9144/lkpr.jpg', 'http://imageshack.us/a/img16/7974/kz19.jpg', 'http://imageshack.us/a/img341/1584/kow9.jpg',\
'http://imageshack.us/a/img96/3832/9sij.jpg', 'http://imageshack.us/a/img593/5210/ax4f.jpg', 'http://imageshack.us/a/img18/5531/wv1t.jpg', 'http://imageshack.us/a/img534/4296/zpdb.jpg',\
'http://imageshack.us/a/img189/846/s6m5.jpg', 'http://imageshack.us/a/img819/5116/h39j.jpg', 'http://imageshack.us/a/img59/161/jnxb.jpg', 'http://imageshack.us/a/img35/3619/ykxe.jpg',\
'http://imageshack.us/a/img51/4187/ubrw.jpg', 'http://imageshack.us/a/img35/4148/8etg.jpg', 'http://imageshack.us/a/img856/8139/k233.jpg', 'http://imageshack.us/a/img713/5533/k6ld.jpg',\
'http://imageshack.us/a/img854/1117/vvj.jpg', 'http://imageshack.us/a/img5/9364/38va.jpg', 'http://imageshack.us/a/img401/4606/m635.jpg', 'http://imageshack.us/a/img600/1197/zdm9.jpg',\
'http://imageshack.us/a/img27/9006/83a6.jpg', 'http://imageshack.us/a/img5/6156/mslt.jpg', 'http://imageshack.us/a/img9/7453/j6i1.jpg', 'http://imageshack.us/a/img221/2149/7w3p.jpg',\
'http://imageshack.us/a/img266/2544/0eku.jpg', 'http://imageshack.us/a/img407/6823/r3r.jpg', 'http://imageshack.us/a/img834/6500/kllb.jpg', 'http://imageshack.us/a/img842/8531/u14b.jpg',\
'http://imageshack.us/a/img580/1034/x0od.jpg', 'http://imageshack.us/a/img191/7715/a8x0.jpg', 'http://imageshack.us/a/img801/1125/fq3r.jpg', 'http://imageshack.us/a/img845/5820/eaep.jpg',\
'http://imageshack.us/a/img13/6573/6ro1.jpg', 'http://imageshack.us/a/img834/4240/yvfm.jpg', 'http://imageshack.us/a/img841/6792/hcy5.jpg', 'http://imageshack.us/a/img42/9787/oz7a.jpg',\
'http://imageshack.us/a/img163/3135/gm7x.jpg', 'http://imageshack.us/a/img833/6261/z9yv.jpg', 'http://imageshack.us/a/img585/7933/8ark.jpg', 'http://imageshack.us/a/img832/8133/8mre.jpg',\
'http://imageshack.us/a/img838/6276/3h69.jpg', 'http://imageshack.us/a/img22/7359/w5cu.jpg', 'http://imageshack.us/a/img542/4223/6yqn.jpg', 'http://imageshack.us/a/img23/1951/suh1.jpg',\
'http://imageshack.us/a/img7/8003/xpiq.jpg', 'http://imageshack.us/a/img577/7663/olgf.jpg', 'http://imageshack.us/a/img703/5393/0kie.jpg', 'http://imageshack.us/a/img837/8590/dr3d.jpg',\
'http://imageshack.us/a/img600/5778/pn39.jpg', 'http://imageshack.us/a/img109/5589/5ndc.jpg', 'http://imageshack.us/a/img826/6804/pl79.jpg', 'http://imageshack.us/a/img402/482/6ne8.jpg',\
'http://imageshack.us/a/img40/413/aei7.jpg']

self.card_face_index = ['CA','C2','C3','C4','C5','C6','C7','C8','C9','CT','CJ','CQ','CK',\
'SA','S2','S3','S4','S5','S6','S7','S8','S9','ST','SJ','SQ','SK',\
'HA','H2','H3','H4','H5','H6','H7','H8','H9','HT','HJ','HQ','HK',\
'DA','D2','D3','D4','D5','D6','D7','D8','D9','DT','DJ','DQ','DK']

def shuffle(self):
shuffle(self.deck)

def get_card(self):
card = self.deck[0]
self.played_cards.append(card)
del self.deck[0]
return card

for card in cards:
if card not in self.deck:
self.deck.append(card)
if card in self.played_cards:
a=self.played_cards.index(card)
del self.played_cards[a]

def card_face_to_show(self, card):
card_to_show = card[1]+card[0]
card = self.card_face_index.index(card_to_show)
return card

class BlackJack(Deck):

def __init__(self):
super(BlackJack, self).__init__()
self.score = 1
self.player_hand_value = 0
self.dealer_hand_value = 0
self.player_hand = []
self.dealer_hand = []
self.player_bust = False
self.dealer_bust = False
self.dealer_turn = False
self.result =''
self.resultd ='Dealer has ' + str(self.dealer_hand_value) + ' showing'
self.resultp = str(self.player_hand_value) + self.result
self.card_face_position = []
self.win = False
self.double = False
self.values = {'A':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':10, 'Q':10, 'K':10}
self.card_positions_player = [[350, 550], [450, 550],\
[312.5, 575], [400, 575], [487.5, 575],\
[275, 600],[458.33, 600], [441.66, 600], [525, 600],\
[311.5, 625], [478.16, 625]]

self.card_positions_dealer = [[350, 100], [450, 100],\
[312.5, 125], [400, 125], [487.5, 125],\
[275, 150],[358.33, 150], [441.66, 150], [525, 150],\
[311.5, 175], [478.16, 175]]

def deck_size(self):
if len(self.deck) == 0:
temp = []

if len(self.player_hand) > 0:
for cards in range(len(self.player_hand)):
temp.append(self.player_hand[cards])

if len(self.dealer_hand) > 0:
for cards in range(len(self.dealer_hand)):
temp.append(self.dealer_hand[cards])

if len(temp) > 0:
for cards in temp:
index_of_card=self.played_cards.index(cards)
del self.played_cards[index_of_card]

vv=self.played_cards[:]

if len(temp) > 0:
for cards in temp:
self.played_cards.append(cards)

self.shuffle()

def deal_hand(self):
if not self.win:
self.score -= 1

self.player_hand = []
self.dealer_hand = []
self.player_bust = False
self.dealer_bust = False
self.dealer_turn = False
self.win = False
self.delay_count = 0

for a in range(4):
self.deck_size()
card = self.get_card()

if not a % 2:
self.player_hand.append(card)
else:
self.dealer_hand.append(card)

self.player_hand_value = self.total_hand(self.player_hand)
self.dealer_hand_value = self.total_hand(self.dealer_hand)

def hit(self):
if not self.win:

if not self.player_bust:

if not self.dealer_turn and len(self.player_hand) < 11:
self.deck_size()
card = self.get_card()
self.player_hand.append(card)

if not self.dealer_bust:

if self.dealer_turn and len(self.dealer_hand) < 11:
self.deck_size()
card = self.get_card()
self.dealer_hand.append(card)

self.dealer_hand_value = self.total_hand(self.dealer_hand)
self.player_hand_value = self.total_hand(self.player_hand)
self.bust()

def bust(self):
if self.player_hand_value > 21 and not self.player_bust:
self.score -= 1
self.result = str(self.player_hand_value)+' showing, ' + 'Busted,  New Deal?'
self.player_bust = True
self.win = True
if self.double:
self.score -= 1

if self.dealer_hand_value > 21 and not self.dealer_bust:
self.score += 1
self.result = 'Dealer busts, Player wins,  New Deal?'
self.dealer_bust = True
self.win = True
if self.double:
self.score += 1

def stand(self):
if not self.win:
self.dealer_turn = True

def dealer(self):
if not self.win:

if self.dealer_hand_value < 17:
self.hit()

elif self.player_hand_value == self.dealer_hand_value:
self.result = str(self.player_hand_value)+' showing, Tie ' + 'Player Wins,  New Deal?'
self.score += 1
self.win = True
if self.double:
self.score += 1

elif self.player_hand_value < self.dealer_hand_value:
self.result = str(self.player_hand_value)+' showing, ' + 'Dealer Wins,  New Deal?'
self.score -= 1
self.win = True
if self.double:
self.score -= 1

elif self.player_hand_value > self.dealer_hand_value > 16:
self.result = str(self.player_hand_value)+' showing, ' + 'Player Wins,  New Deal?'
self.score +=1
self.win = True
if self.double:
self.score += 1

def total_hand(self, hand):
value = 0
for a in hand:
value += self.values[a[0]]

for a in hand:
if a[0] == 'A' and value -1  < 11:
value +=10

return value

def show_results(self):
if not self.player_bust and not self.win:
self.result = str(self.player_hand_value)+' showing, Hit or Stand?'

if self.dealer_turn:
self.resultd ='Dealer has ' + str(self.dealer_hand_value) + ' showing'

elif not self.dealer_turn and self.dealer_hand[0][0] == 'A':
self.resultd ='Dealer has an ' + str(self.dealer_hand[0][0]) + ' showing'

else:
self.resultd ='Dealer has ' + str(self.values[self.dealer_hand[0][0]]) + ' showing'

return self.result, self.resultd

def update(self, card, pd='player'):
if pd == 'player':
cl = self.card_face_to_show(self.player_hand[card])
cpp = self.card_positions_player[card]

elif pd !='player' and card == 1 and not self.dealer_turn:
cpp = self.card_positions_dealer[card]
return 0, 52, (71, 96), cpp, self.show_results()

elif pd !='player' and self.dealer_turn:
cl = self.card_face_to_show(self.dealer_hand[card])
cpp = self.card_positions_dealer[card]
return 1, cl, (73, 98), cpp, self.show_results()

else:
cl = self.card_face_to_show(self.dealer_hand[card])
cpp = self.card_positions_dealer[card]
return 1, cl, (73, 98), cpp, self.show_results()

self.show_results()

if self.dealer_turn and (not self.win):
self.delay()

return cl, cpp, self.show_results()

def delay(self):
self.delay_count +=1

if self.delay_count == 120:
self.delay_count = 0
self.dealer()

def deal():
for a in range(len(game.dealer_hand)):
i, cl, cs, cpp, result = game.update(a,'dealer')
table_area.coords(card[cl],0,1600)

for a in range(len(game.player_hand)):
cl, cpp, result = game.update(a,'player')
table_area.coords(card[cl],0,1600)
game.double = False
game.deal_hand()

def hit():
game.hit()

def stand():
game.stand()

def double():
game.double = True
game.hit()
game.stand()

def init():
global game , card_face
for a in range(len(card)):
table_area.coords(card[a],0,1600)

game = BlackJack()
game.shuffle()
game.deal_hand()

init()

def draw():

for a in range(len(game.dealer_hand)):
i, cl, cs, cpp, result = game.update(a,'dealer')
if i == 1:
table_area.coords(card[52], 0,1600)
table_area.coords(card[cl], cpp[0],cpp[1])
table_area.tag_raise(card[cl])
table_area.itemconfig(dealer_messages, text = result[1], fill = 'white')

for a in range(len(game.player_hand)):
cl,cpp, result = game.update(a)
table_area.coords(card[cl], cpp[0],cpp[1])
table_area.tag_raise(card[cl])
table_area.itemconfig(player_messages, text = result[0], fill = 'white')

table_area.itemconfig(score, text = 'score ' + str(game.score), fill = 'white')

table_area.after(16,draw)

root = Tk()
root.title("BlackJack")
root.geometry("1025x815+100+100")

control_area = Frame(root)
control_area.pack(side='top')
control_area.grid_columnconfigure(0, weight=0)
control_area.grid_columnconfigure(1, weight=0)

table_area = Canvas(control_area, width=800, height=800)
table_area.configure(bg='Dark Green')
table_area.grid(row=0, column=1, rowspan = 20)

background = Image.open(io.BytesIO(background)).convert('RGBA')
bgd = ImageTk.PhotoImage(background)
bg = table_area.create_image(400,400, image=bgd)

deal = Button(control_area, text = 'Deal', command = deal, fg = 'black')
deal.grid(row=0, column=0)

hit = Button(control_area, text = 'Hit', command = hit, fg = 'black')
hit.grid(row=1, column=0)

stand = Button(control_area, text = 'Stand', command = stand, fg = 'black')
stand.grid(row=2, column=0)

double = Button(control_area, text = 'Double Down', command = double, fg = 'black')
double.grid(row=3, column=0)

reset = Button(control_area, text = 'Reset Game', command = init, fg = 'black')
reset.grid(row=7, column=0)

dealer_messages = table_area.create_text(400, 25, text = '', font = ("Helvetica", 30), fill = 'white')
player_messages = table_area.create_text(400, 770, text = '', font = ("Helvetica", 30), fill = 'white')
score = table_area.create_text(60, 300, text = '', font = ("Helvetica", 20), fill = 'white')

for a in range(len(game.card_face)):
images.append(Image.open(io.BytesIO(img)).convert('RGBA'))
photos.append(ImageTk.PhotoImage(images[a]))
card.append(table_area.create_image(0,1600, image=photos[a]))

draw()
root.mainloop()```
```
Sample output (Click to show)

Nice output!
 Petrichor (24 items) Harbringer (12 items) Jaded (5 items)
CPUMotherboardGraphicsRAM
Intel i5-3570K @ 4.7GHz / 1.256V ASRock Z77 Extreme4 Gainward GTX 1060, 6GB TeamGroup 8GB, DDR3-1333 @ 1600MHz / 1.5V, 9-9-...
Hard DriveHard DriveHard DriveOptical Drive
Samsung SSD 830 Series, 128GB Seagate Barracuda ST31000524AS, 1TB, 7200 RPM Hitachi Deskstar IDK 0S03661, 3TB, 7200 RPM LG GH22NS50
CoolingCoolingCoolingOS
Lamptron FC5 V3 Noctua NH-D15 Noctua NF-A14 FLX (140mm) (x5)  Windows 10 Professional (64-bit)
MonitorMonitorKeyboardPower
Dell UltraSharp U2312HM (x3) LG 40UB800V Lioncast LK20, TKL, Cherry MX-Blue, DE-Layout Corsair AX860
Fractal Define R4 Black Mionix Castor Akasa Venom XXL Denon PMA 520 AE AMP
AudioAudioAudioAudio
Dali Zensor 3 Speakers (x2) Magnat Monitor Supreme Sub 301 A Audioengine D1 DAC / Headphone AMP Beyerdynamic DT 770 Pro 250 Ω
CPUMotherboardRAMHard Drive
Intel Pentium G3440T ASRock E3C226D2I Kingston ValueRAM, 16GB, DDR3-1333 MHz, ECC HGST IDK Deskstar H3IK40003272SE, 4 TB, 7200RPM
Hard DriveOSPowerCase
Seagate Barracuda ST3000DM001, 3 TB, 7200RPM (x2) FreeNAS 9.3 be quiet! Straight Power E9 400W NZXT Source 210 Elite
CPUGraphicsRAMHard Drive
Intel Core i3-2367M Intel HD Graphics 3000 4 GB 500 GB
Monitor
11.6" WXGA non-glare LED TFT, 1366x768
 Petrichor (24 items) Harbringer (12 items) Jaded (5 items)
CPUMotherboardGraphicsRAM
Intel i5-3570K @ 4.7GHz / 1.256V ASRock Z77 Extreme4 Gainward GTX 1060, 6GB TeamGroup 8GB, DDR3-1333 @ 1600MHz / 1.5V, 9-9-...
Hard DriveHard DriveHard DriveOptical Drive
Samsung SSD 830 Series, 128GB Seagate Barracuda ST31000524AS, 1TB, 7200 RPM Hitachi Deskstar IDK 0S03661, 3TB, 7200 RPM LG GH22NS50
CoolingCoolingCoolingOS
Lamptron FC5 V3 Noctua NH-D15 Noctua NF-A14 FLX (140mm) (x5)  Windows 10 Professional (64-bit)
MonitorMonitorKeyboardPower
Dell UltraSharp U2312HM (x3) LG 40UB800V Lioncast LK20, TKL, Cherry MX-Blue, DE-Layout Corsair AX860
Fractal Define R4 Black Mionix Castor Akasa Venom XXL Denon PMA 520 AE AMP
AudioAudioAudioAudio
Dali Zensor 3 Speakers (x2) Magnat Monitor Supreme Sub 301 A Audioengine D1 DAC / Headphone AMP Beyerdynamic DT 770 Pro 250 Ω
CPUMotherboardRAMHard Drive
Intel Pentium G3440T ASRock E3C226D2I Kingston ValueRAM, 16GB, DDR3-1333 MHz, ECC HGST IDK Deskstar H3IK40003272SE, 4 TB, 7200RPM
Hard DriveOSPowerCase
Seagate Barracuda ST3000DM001, 3 TB, 7200RPM (x2) FreeNAS 9.3 be quiet! Straight Power E9 400W NZXT Source 210 Elite
CPUGraphicsRAMHard Drive
Intel Core i3-2367M Intel HD Graphics 3000 4 GB 500 GB
Monitor
11.6" WXGA non-glare LED TFT, 1366x768
Agreed.

I very nearly added "has to have a GUI" as one of the challenge parameters but didn't think anyone would bother. So I'm hugely impressed with Tom's effort.
Thank You,
 Core I7 (13 items)
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800)
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105
PowerCase
CORSAIR 850TX Cooler Master ATCS 840
 Core I7 (13 items)
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800)
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105
PowerCase
CORSAIR 850TX Cooler Master ATCS 840
Well it's taken me a while, and I've made it so the player gets a bit more luck that usual.
Source code, written in Java (Click to show)
Code:
``````public class BlackJack()
{
public static void main(String[] args)
{
System.out.println("You win!");
}
}```
```

Yes, I'm also really impressed with Tom's effort. And.. I can't believe how similar C# is to Java (not Tom's, a few posts ago), first time I've seen it properly.
Edited by JoeChamberlain - 6/27/13 at 12:53pm
 For Gaming (18 items) For Working (8 items) For Serving (8 items)
CPUMotherboardGraphicsRAM
AMD FX-8350 @ 4.6 Ghz ASUS M5A97-PRO Sapphire R9 290X Tri-X 4GB @ 1170/1475 8GB Corsair Vengeance Blue LP DDR3 2133 Mhz
Hard DriveHard DriveOptical DriveCooling
Crucial M4 SSD 128 GB Toshiba SATA III 2TB SAMSUNG DVDRW Corsair H60
OSMonitorKeyboardPower
Windows 10 Pro 64 Bit Asus MG279Q 27" FreeSync WQHD 144hz IPS Corsair RGB K65 Cherry Red Corsair CX750M
CaseMouseAudioAudio
Cooler Master Elite 430 Corsair Vengeance M65 Alesis iO2 Express Audio Interface Wharfedale Pro Diamond 8.2 Active Studio Monitors
Audio
Corsair Vengeance 1500 v2 7.1 Dolby Headset
CPUGraphicsRAMHard Drive
Intel Core i7-3740QM CPU @ 2.70 Ghz NVidia Quadro K1000M 2GB 32GB DDR3 500GB 7200RPM
Optical DriveOSMonitorOther
Slot DVDRW Windows 7 64-Bit 1080p Built in Display Dell Precision M4700
 For Gaming (18 items) For Working (8 items) For Serving (8 items)
CPUMotherboardGraphicsRAM
AMD FX-8350 @ 4.6 Ghz ASUS M5A97-PRO Sapphire R9 290X Tri-X 4GB @ 1170/1475 8GB Corsair Vengeance Blue LP DDR3 2133 Mhz
Hard DriveHard DriveOptical DriveCooling
Crucial M4 SSD 128 GB Toshiba SATA III 2TB SAMSUNG DVDRW Corsair H60
OSMonitorKeyboardPower
Windows 10 Pro 64 Bit Asus MG279Q 27" FreeSync WQHD 144hz IPS Corsair RGB K65 Cherry Red Corsair CX750M
CaseMouseAudioAudio
Cooler Master Elite 430 Corsair Vengeance M65 Alesis iO2 Express Audio Interface Wharfedale Pro Diamond 8.2 Active Studio Monitors
Audio
Corsair Vengeance 1500 v2 7.1 Dolby Headset
CPUGraphicsRAMHard Drive
Intel Core i7-3740QM CPU @ 2.70 Ghz NVidia Quadro K1000M 2GB 32GB DDR3 500GB 7200RPM
Optical DriveOSMonitorOther
Slot DVDRW Windows 7 64-Bit 1080p Built in Display Dell Precision M4700
New Posts  All Forums:Forum Nav:
Return Home
Back to Forum: Coding and Programming
• Programming Challenge #9 - writing a basic game
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #9 - writing a basic game