This is a creation in Article, where the information may have evolved or changed.
This article mainly quoted the online teaching http://www.cwflynt.com/TclForTeens/
Step a Download the poker image Package mentioned in Lesson 17th
Http://www.cwflynt.com/TclForTeens/cards.zip
Unzip all files within the Cards.zip to the C:\cards\ directory
"You can put it in the Cards directory of the desktop."
Step b jumps to the 20th lesson http://www.cwflynt.com/TclForTeens/lsn20.html
Find the last frame of the source code, and its previous sentence is "and that's all the changes." Here's the complete game.
Copy this frame of code into the string constants of the go code as follows
Package Mainimport "Github.com/nsf/gothic" Const Init_script = ' #init_script字符串常量, TCL/TK code starts from the next line ' func main () {ir: = Got Hic. Newinterpreter (Init_script) <-ir. Done}
Step c Save the go file to the C:\cards\ directory
"Anyway, with the image files together, the same directory on the line"
Step d Run and compile
Liteide under Compile as
Operating effects such as:
Step e Release
Found from the installation directory of the ACTIVETCL development environment (typically c:\tcl\)
Bin folder, copy the tcl86.dll Tk86.dll and Zlib1.dll 3 files to
Under the C:\cards\ directory
Then find the tcl8.6 and tk8.6 folders from the C:\tcl\lib, and copy the two to
C:\cards\lib\ under
"If necessary, you can remove some unused packages to reduce the size of the published files"
Finish
"Attach all go source code, only more than 400 lines, which contains TCL/TK code of the # comments are almost 100 lines."
package mainimport "github.com/nsf/gothic" const init_script = ' ###################### ########################################### proc loadimages {}--# load the card images # Arguments# NONE# # Results# The global array "Concentration" is modified to include a # list of card image names# proc loadImages {} { global concentration # the card image filenames are named as S_V.gif where # S is a single letter for suit (hearts, diamonds, spades, clubs) # V is a 1 or 2 character descriptor of the suit - One of: &nbSp;# a k q j 10 9 8 7 6 5 4 3 2 # # glob returns a list of fileNames that match the pattern - *_*.gif # means all filenames that have a underbar in the name, and a .gif extension. foreach filename [glob *_*.gif] { # we discard the aces to leave 48 cards because that makes a # 6x8 card display. if {($fileName ne "C_a.gif") && ($fileName ne "H_a.gif") && ($fileName ne "D_ A.gif ") && ($fileName ne "S_a.gif")} { # split the card name (C_8) from the suffix (. gif) set card [lindex [split $fileName .] 0] # create an image with the card name, using the file # and save it in a list of card images: concentration (cards) image create photo $card -file $fileName lappend concentration (cards) $card } } # Load the images to use for the card back and # for blank cards foreach filename {blank.gif back.gif} { # split the card name from the suffix (. GIF) set card [lindex [split $fileName .] 0] # Create the image image create photo $card -file $fileName }}# ################################################################ proc randomizelist {}--# Change the order of the cards in the list# arguments# originallist the list to be shuffled# # results# the concentration (cards) list is changed - no cards will be lost# of added, but the order will be random.# proc randomizelist {originallist} { # how many cards are we playing with. set listLength [llength $originalList] # Initialize a new (Random) list to be empty Set newlist {} # loop for as many cards as are in the card list at the # start. We remove one card on each pass through the loop. for {set i $listLength} {$i > 0} {incr i -1} { # Select a random card from the remaining Cards. set p1 [expr int (rand () * $i)] # put that card onto the new list of cards lappend newList [lindex $originalList $p 1] # remove that card from the card list. set originalList [lreplace $originalList $p 1 $p 1] } # replace the empty list of cards with the new list that ' S got all # the cards in it. return $newList}################################################################# proc makegameboard {}--# create the game board widgets - canvas and labels.# Arguments# NONE# # Results# new gui widgets are created.# proc makegameboard {} { # create and grid the canvas that will hold the card images Canvas .game -width 800 -height 724 -bg gray grid .game -row 1 -column 1 -columnspan 6 # create and grid the labels for turns and score label .lmyscorelabel -text "My score" label .lmyscore -textvariable concentration (player, Score) label .lturnLabel -text "Turn" label .lturn - Textvariable concentration (Turn) grid .lmyscorelabel -row 0 -column 1 -sticky e grid .lmyscore -row 0 -column 2 -sticky w grid .lturnlabel -row 0 -column 5 -sticky e grid .lturn -row 0 -column 6 -sticky w}############################################################## ### proc startgame {}--# actually start a game running# arguments# none# # results# initializes per-game indices in the global array "Concentration" # The card list is randomized# the gui is modified.# proc Startgame {} { global concentration set concentration (Player,score) 0 set concentration (Turn) 0 set concentration (Selected,rank) { } set concentration (player,x) 0 set concentration (player,y) 2 set concentratIon (Cards) [randomizeList $concentration (cards)] # save the height and width of the cards to make the code easier # to read. set height [image height [lindex $ Concentration (cards) 0]] set width [image width [lindex $ Concentration (cards) 0]] # leave spaces between cards. incr width incr height # remove any existing items on the canvas .game delete all # Start In the upper left hand corner set x 90 set y 2 # Step through the list of cards for {set pos 0} {$pos < [llength $concentration (cards)]} {incr pos} { # Place the back-of-a-card image on the board # to simulate a card that is face-down. .game create image $x $y -image back -anchor nw -tag card_$ Pos # add a binding on the card back to react # to a player left-clicking the back. .game bind card_$pos < buttonrelease-1> "playerturn $pos" # step to the next column (The width of a card) incr x $width &nbsP;# if we ' Ve put up 8 columns of cards, reset x to the # far left, and step down one row. if {$x >= [expr 90 + ($width * 8)] } { set x 90 incr y $height } }}################################################### ############## proc flipimagex {canvas canvasid start end background}--# makes it appear that an image object on a canvas is being flipped# Arguments# canvas the canvas holding the image# canvasid the Identifier for this canvas item# start the initial image being Displayed# end the final image to display# background the color to show behind the image being flipped.# this is probably the canvas background color# # Results# configuration for the canvas item is modified.# proc flipimagex {canvas canvasid start end background} { global concentration # get the height/width of the image we ' ll be using set height [image height $ Start] set width [image width $start] # the image will rotate around the x axis # calculate and save the Center, since we ' ll be using it a lot set centerx [ expr $width / 2] # Create a new temp Image that we ' ll be modifying. image create photo temp - height $height -width $width # Copy the initial image into our temp image, and configure the # canvas to show our temp image, instead of the original image # in this location. temp copy $start $canvas itemconfigure $canvasID -image temp update idle after 25 # copy the start image into the temp with greater # subsampling ( making it appear like more and more of an # edge view of the image). # move the start of the image to the center on each pass # through the loop for {set i 2} {$i < 8} {incr i} { set left [expr $centerX - $width / (2 * $i)] set right [expr $centerX + $width / (2 * $i)] temp put $background -to 0 0 $ width $height temp copy -to $left 0 $right $height -subsample $i 1 $ start update idle after 10 } # copy the end image into the temp with less and less # subsampling (making it appear like less and Less of an # edge view of the image) . # move the start of the image away from thecenter on each pass # through the loop for {set i 8} {$i > 1} {incr i -1} { set left [expr $centerX - $width / (2 * $i)] set right [expr $centerx + $width / (2 * $i)] temp put $background -to 0 0 $width $height temp copy -to $left 0 $right $height -subsample $i 1 $end update idle after 10 } # configure the canvas to show the final image, and # delete our temporary image $canvas itemconfigure $canvasID -image $end image delete temp}################################################################# proc playerturn { Position}--# selects a card for comparison, or checks the current# card against a previous selection.# Arguments# position the position of this card in the deck.## Results# the selection fields of the global array "Concentration" # are modified.# the gui is modified.# proc playerturn {position} { global concentration set card [lindex $concentration (cards) $position] flipImageX .game card_$position back $card gray set rank [lindex [split $card _] 1] # if concentration ( Selected,rank) is empty, this is the first # part of a turn. mark this card as selected and we ' re Done. if {{} eq&nBSP; $concentration (Selected,rank)} { # increment the Turn counter incr concentration (Turn) set Concentration (Selected,rank) $rank set concentration (selected,position) $position set concentration (selected,card) $card } else { # if we ' Re here, then this is the second part of a turn. # Compare the rank of this card to the previously saved rank. if {$position == $concentration (selected,position)} { return } # update the screen * now* (TO&NBSP;SHOW&NBSP;THE&NBSp;card), and pause for one second. update idle after 1000 # if the ranks are identical, handle the match condition if {$rank eq $concentration (Selected,rank)} { # increase the Score by one incr concentration (Player,score) # remove the two cards and their backs from the board .game bind card_$position < buttonrelease-1> "" .game bind card_$concentration ( selected,position) <ButtonRelease-1> "" movecards card_$poSition \ card_$concentration (selected,position ) player # check to see if we ' ve won yet. if {[checkforfinished] } { endgame } } else { # if we ' re here, The cards were not a match. # flip the cards to back up (Turn the cards face down) flipImageX .game card_$position $card back gray flipimagex .game card_$concentration (selected,position) \ $concentration (Selected,card) back gray } # Whether or not we had a match, Reset the concentration (Selected,rank) # to an empty string so that the next click will be a select. set concentration (Selected,rank) {} }}############################################# #################### proc movecards {cvs id1 id2 prefix}--# moves cards from their current location to the# score pile for # Arguments# id1 An identifier for a canvas item# id2 an identifier for a canvas item# prefix identifier for which location should get the card# # results# # proc moveCards {id1 id2 prefix} { global concentration .game raise $id 1 .game raise $id 2 .game coords $id 1 $concentration ($prefix, x) $concentration ($prefix, y) .game coords $id 2 $concentration ($prefix, x) $concentration ($prefix, y) incr Concentration ($prefix, y) 30}################################################################# proc checkforfinished {}--# checks to see if the game is won. returns true/false# arguments# # # results# # proc checkforfinished {} { global concentration global concentration if {$concentration (Player,score) == 24} { return true } else { return false }}######################### ######################################## proc endgame {}--# provide end of game display and ask about a new game# Arguments# none# # results# gui is modified# proc endGame {} { global concentration set position 0 foreach card $concentration (cards) { .game itemconfigure card_$position -image $card incr position } &Nbsp; # update the screen *now*, and pause for 2 seconds update idle; after 2000 .game create rectangle 250 250 450 400 -fill blue \ -stipple gray50 -width 3 -outline gray button . again -text "Play again" -command { destroy .again destroy .quit startgame } button .quit -text "Quit" -command "Exit" .game create window 350 300 -window .again .game create window 350 350 -window .quit}loadimagesmakegameboardstartgame ' Func main () { ir :=&Nbsp;gothic. Newinterpreter (Init_script) <-ir. Done}