Jump to content

Card Game


Recommended Posts

Hello

I am making a card game it's a classic called War, now this game should be fairly easy to make I would assume but I am having difficult time coming up with a solution that can give each of the players cards without giving them the same type of cards.

http://www.pagat.com/war/war.html

Both of the players get 26 cards each (I am using pictures as my cards labeled 1-52)

Now by me meaning same type of cards I mean the exact same card number and suit.

I am stomped here ^_^

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Width = 300
$Height = 200
$Deck = "Red"
$Resources = @ScriptDir & "\Cards\"



$War = GUICreate("War", $Width, $Height)
GUISetBkColor(0x008000)
$PlayerDeck = GUICtrlCreatePic($Resources & $Deck & ".jpg", 0 , 0 , 70 , 95)
$ComputerDeck = GUICtrlCreatePic($Resources & $Deck & ".jpg", $Width -70 , 0 , 70 , 95)
GUISetState(@SW_SHOW)
_Test()
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _Test()
    ;$Ran1 = Random(1 , 52 , 1)
    ;$Ran2 = Random(1 , 52 , 1)
    
    GUICtrlSetImage($PlayerDeck , $Resources & 1 & ".jpg")
    GUICtrlSetImage($ComputerDeck , $Resources & 27 & ".jpg")
    _Win(1 , 27)
EndFunc

Func _Win($PlayerWin , $ComputerWin)
    $Ace = "1" And "26" And "39" And "52"
    $2 = "2" And "14" And "27" And "40"
    
    If $PlayerWin = $Ace Then
        MsgBox(0 , "Player Wins" , "Ace")
    EndIf
    
    
    
    ;If $PlayerWin = 
EndFunc
Link to comment
Share on other sites

Hello

I am making a card game it's a classic called War, now this game should be fairly easy to make I would assume but I am having difficult time coming up with a solution that can give each of the players cards without giving them the same type of cards.

http://www.pagat.com/war/war.html

Both of the players get 26 cards each (I am using pictures as my cards labeled 1-52)

Now by me meaning same type of cards I mean the exact same card number and suit.

I am stomped here :shocked:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Width = 300
$Height = 200
$Deck = "Red"
$Resources = @ScriptDir & "\Cards\"



$War = GUICreate("War", $Width, $Height)
GUISetBkColor(0x008000)
$PlayerDeck = GUICtrlCreatePic($Resources & $Deck & ".jpg", 0 , 0 , 70 , 95)
$ComputerDeck = GUICtrlCreatePic($Resources & $Deck & ".jpg", $Width -70 , 0 , 70 , 95)
GUISetState(@SW_SHOW)
_Test()
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _Test()
    ;$Ran1 = Random(1 , 52 , 1)
    ;$Ran2 = Random(1 , 52 , 1)
    
    GUICtrlSetImage($PlayerDeck , $Resources & 1 & ".jpg")
    GUICtrlSetImage($ComputerDeck , $Resources & 27 & ".jpg")
    _Win(1 , 27)
EndFunc

Func _Win($PlayerWin , $ComputerWin)
    $Ace = "1" And "26" And "39" And "52"
    $2 = "2" And "14" And "27" And "40"
    
    If $PlayerWin = $Ace Then
        MsgBox(0 , "Player Wins" , "Ace")
    EndIf
    
    
    
    ;If $PlayerWin = 
EndFunc
I hope this will help you along with your project.

This being one possible way of dividing up 52 into two hands of equal size and random order without repeats..

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include <Array.au3>; Used for checking purposes.

Global $aHand1, $aHand2
$Width = 300
$Height = 200
$Deck = "Red"
$Resources = @ScriptDir & "\Cards\"

$War = GUICreate("War", $Width, $Height)
GUISetBkColor(0x008000)
$PlayerDeck = GUICtrlCreatePic($Resources & $Deck & ".jpg", 0, 0, 70, 95)
$ComputerDeck = GUICtrlCreatePic($Resources & $Deck & ".jpg", $Width - 70, 0, 70, 95)
GUISetState(@SW_SHOW)
_Test()
_Win(1, 27)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Test()
;$Ran1 = Random(1 , 52 , 1)
;$Ran2 = Random(1 , 52 , 1)

;Pick 26 random number between 1 and 52
    Local $num = 0, $sHand1 = " ", $sHand2 = " "
    Do
        $Ran1 = " " & Random(1, 52, 1) & " "; Spaces used to stop eg. 2 being recognized in 12 in next line.
        If StringInStr($sHand1, $Ran1) = 0 Then
            $sHand1 &= $Ran1 & "|"
            $num += 1
        EndIf
    Until $num = 26
    $num = 0

; Pick the remaining 26 numbers randomly
    Do
        $Ran1 = " " & Random(1, 52, 1) & " "
        If StringInStr($sHand1 & $sHand2, $Ran1) = 0 Then
            $sHand2 &= $Ran1 & "|"
            $num += 1
        EndIf
    Until $num = 26

; Creates an array from the string hands. Removes all white spaces, removes last "|" from string, then splits string on "|".
    $aHand1 = StringSplit(StringTrimRight(StringStripWS($sHand1, 8), 1), "|")
    $aHand2 = StringSplit(StringTrimRight(StringStripWS($sHand2, 8), 1), "|")

    #cs
    ; Check all cards, 1 to 52, exist & randonly separated into 2 hands.
        ConsoleWrite("$sHand1: " & $sHand1 & @CRLF & "$sHand2: " & $sHand2 & @CRLF)
        _ArrayDisplay($aHand1)
        _ArrayDisplay($aHand2)
        Local $aArr = StringSplit(StringTrimRight(StringStripWS($sHand1 & $sHand2, 8), 1), "|")
        _ArrayDisplay($aArr)
        _ArraySort($aArr, 0, 1)
        _ArrayDisplay($aArr)
    #ce

    ConsoleWrite(" $aHand1" & @CRLF)
    For $x = 1 To 26
        GUICtrlSetImage($PlayerDeck, $Resources & $aHand1[$x] & ".jpg")
        ConsoleWrite($x & "  " & $Resources & $aHand1[$x] & ".jpg" & @CRLF)
    Next

    ConsoleWrite(@CRLF & "$aHand2" & @CRLF)
    For $x = 1 To 26
        GUICtrlSetImage($ComputerDeck, $Resources & $aHand2[$x] & ".jpg")
        ConsoleWrite($x & "  " & $Resources & $aHand2[$x] & ".jpg" & @CRLF)
    Next
    Return
EndFunc  ;==>_Test

Func _Win($PlayerWin, $ComputerWin)
    $Ace = "1" And "26" And "39" And "52"
    $2 = "2" And "14" And "27" And "40"

    If $PlayerWin = $Ace Then
        MsgBox(0, "Player Wins", "Ace")
    EndIf



;If $PlayerWin =
EndFunc  ;==>_Win
Link to comment
Share on other sites

If i understand correctly - you can do the following :

1.Deal 1 card at a time

2.Do a random number from 1 to 52 each corresponding to 1 card

3.Remove the already dealt card from the deck , for example if you deal "1" corresponding to ace of hearts your deck will be "2 to 52"

That way you can implement other card games as Texas hold'em for example.

Link to comment
Share on other sites

use arrays.. and arraysearch... there are alot of array funtions

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...