Linipcfg is a little program displaying information about network interfaces. The concept is based on Windows 95 winipcfg. It is basically a GUI shell for /sbin/ifconfig.
Linipcfg is distributed under GPL. In general this means that you can do whatever you want with the code, except selling it or pretending you wrote it. For details on GPL, go to http://www.gnu.org.
To install the program, just copy the executable linipcfg to anywhere in your path (/usr/local/bin would be a good choice).
To recompile, type make.
Requires GTK+. I actually decided to write it when I started to learn GTK+. It is an excellent toolkit to write Linux GUI applications. To find out more about GTK+, visit http://www.gtk.org
I'm glad to report that aLinux includes linipcfg as part of the distribution. I must say I like this distro a lot.
Examples provided here are simple programs, without extensive use of Windows API. The only API calls I used are functions to play sound (because they are simple to use). The reason is that API calls don't follow standard VB feel and are more C-like, which is very confusing for beginners.
I wanted to concentrate on algorithms and data representation. Especially I hope that you may find the cards code module useful for designing other card games, I tried to make it that way.
Both examples are card games, that I hope will be of entertaining and educational value to you. I used card pictures contained in cards.dll, which is located in \WINDOWS\SYSTEM directory. Instead of using awkward API calls to load images directly from the DLL, I decided to save images as BMP files. But if you're familiar with windows API calls, it should be easy to make changes to use the DLL directly.
I'd like to explain some of the ideas behind the Poker code. Single card is represented as a user-defined data structure:
Public Type udtCard
Pic As String ' filename of the card image
Rank As Integer ' card value 2-10 direct, J is 11, Q is 12, K is 13 and A is 14
Color As Integer ' in color order; Clubs is 1, Diamonds is 2, Hearts is 3 and Spades is 4
Discard As Boolean ' Flag indicating whether the card is marked to be replaced
IsInHand As Boolean ' Flag whether the card was drawn already
End Type
Then we have an array of 52 cards, which is a deck:
Public Deck(1 To 52) As udtCard
and a hand which holds 5 cards:
Public Hand(1 To 5) As udtCard
When shuffling the deck of cards physically, you change the relative position of each card in the deck. Then you deal the cards sequentially. This shuffling/dealing algorithm can be implemented in software, but does not make much sense. Instead, we'll just deal a random card from sequentially organized deck. The result is just the same.
Another challenge is recognizing what is on hand. Most of the tasks of this and similar type can be accomplished with the use of array sorting. In this case, we sort by number of cards in one color, getting the longest color in the first element. Then we sort by rank, which lets us check for pair, three of a kind, full house and a four of a kind. It simplifies the logic a lot. For details, please see the code.
I hope that you'll find the source code commented out well, however certain things that seem obvious to me, may not be so obvious to you. Your input and questions are welcome - drop me a note at greg at draxen.org.
And another thing - you can use portions or all of the code in your programs. If you ever distribute programs containig portions of my code, I'd appreciate if you put apropriate note about it.
For games installation files (without source code) please look in Downloads section
How to display random image, assuming JPEG files in the direcory called images:
$images = glob ( "images/*.jpg" );
$n = rand(0,count($images)-1);
printf("<IMG SRC='%s' q>\n", $images[$n]);
Explanation: First line reads all file names into array $images. Second line generates a random number between zero and number of elements in the array less one. Third line references the image of random index $n from the array.