SkellySoul Posted April 30, 2009 Share Posted April 30, 2009 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.htmlBoth 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 expandcollapse popup#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 More sharing options...
Malkey Posted April 30, 2009 Share Posted April 30, 2009 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 expandcollapse popup#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 = EndFuncI 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.. expandcollapse popup#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 More sharing options...
Juvigy Posted April 30, 2009 Share Posted April 30, 2009 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 More sharing options...
CodyBarrett Posted April 30, 2009 Share Posted April 30, 2009 use arrays.. and arraysearch... there are alot of array funtions [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
SkellySoul Posted May 1, 2009 Author Share Posted May 1, 2009 Thanks for the help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now