My First OOP - A Solitaire Game

I learned about the concept of the Object-oriented programming(OOP) when I was attending college some years ago.  The professor introduced the concepts of common objects such as a stack, a queue and dequeue frequently used in computer programming.  He also talked about advantage of programming in objects in general.   I still remember vividly the example he used in his lecture to illustrate the concepts, a solitaire game: The deck of cards can be thought of a stack. The up-pile can be thought of a stack. The down-pile can be thought of a queue/dequeue. A poker card can be thought of an object that has the following properties:

Value(Ace,Two,Three,Four,Six,Seven,Eight,Nine,Ten,Jack,Queen,King) Color (Red,Black) Suite (Heart,Diamond,Club,Spade) Face (Front,Back)
  • A poker card in the solitaire game can be checked if it has a move to other piles according to the game's rule. These checking correspond to its methods. * To check if the card can move to a up-pile, we use the function CanGoUpPile as follow:

    Public Function CanGoUpPile(UpPile As Deck) As Boolean    

        If UpPile.Size > 0 Then        

            If UpPile.Top.Color = Me.Color And UpPile.Top.Value + 1 = Me.Value And UpPile.Top.Suit = Me.Suit Then            

                    CanGoUpPile = True        

            Else            

                     CanGoUpPile = False             

            End If    

        ElseIf Me.Value = ACE Then        

            CanGoUpPile = True    

        Else        

            CanGoUpPile = False    

        End If

    End Function

  • To check if the card can move to a down-pile, we use the function CanGoDownPile as follow:

    Public Function CanGoDownPile(DownPile As Deck) As Boolean    

        If DownPile.Size > 0 Then

              If DownPile.Front.CardImage = DownPile.Front.FaceImage Then            

                    If DownPile.Front.Color <> Me.Color And DownPile.Front.Value - 1 =    Me.Value Then

                         CanGoDownPile = True            

                    Else                

                          CanGoDownPile = False            

                    End If        

            Else            

                    CanGoDownPile = False        

            End If    

        ElseIf Me.Value = KING Then        

            CanGoDownPile = True    

        Else        

            CanGoDownPile = False    

        End If

    End Function

    The entire card object class written in vb can be read here. With these abstractions, it's easier to write the solitaire game.  Here is my first solitaire game that you can download and play. The entire solitaire project's source code in vb can be downloaded here.


fshell 发布于  2009-7-30 15:58 

Glassfish, Apache & AJP Connector

If we run your Glassfish application server in your local network and you want your applications to serve your internet users, we may run our Apache server in front with reverse proxy.  Apache can pass the requests to our Glassfish application server through its connector.  Glassfish supports the standard http connector and the AJP connector.  Personally, I like to to use the AJP connector because it maintains the original IP address from the client.  To use the connectors, we need to load the needed Apache modules and configure Apache and Glassfish if necessary as follow:

* HTTP connector

modules: proxy, proxy_http ProxyRequests Off <Proxy *>  Order deny,allow  Allow from all </Proxy> ProxyPass /app http://localhostname:8080/app ProxyPassReverse /app http://localhostname:8080/app

* AJP connector

modules: proxy, proxy_ajp ProxyRequests Off <Proxy *>  Order deny,allow  Allow from all </Proxy> ProxyPass /app ajp://localhostname:8009/app ProxyPassReverse /app ajp://localhostname:8009/app

If we use AJP connector, we need to copy the following jar files to the lib sub directory of our Glassfish installation directory.

* commons-logging-api.jar  * commons-modeler-2.0.jar  * tomcat-ajp.jar

For AJP to work properly for Glassfish v2, these files must come from Tomcat 5.5.23.  Files from other Tomcat versions may not work and may give
you an error: java.lang.NoSuchFieldError: USE_CUSTOM_STATUS_MSG_IN_HEADER.

To configure the Glassfish AJP connector:

From the console: $GLASSFISH_HOME/bin/asadmin create-jvm-options -Dcom.sun.enterprise.web.connector.enableJK=8009

From the console:
sudo ./asadmin create-jvm-options -Dcom.sun.enterprise.web.connector.enableJK.propertyFile = /path/glassfish/domains/domain1/config/glassfish-jk.properties  


fshell 发布于  2009-7-11 14:46 

Roller 3.0 to 4.0

I chose Roller as my blog software simplely because I already had one of its runtime environment installed in my system.  I already installed  the Sun Java Application Server, known as the Glassfish now, when I started working on my EJB application some years ago. 

It took me some time to install and configure Roller 3.0 for it requried some dependent packages from some third-party.  Overall, it wasn't too bad and it's up and running finally.  I aslo installed some other additional Rolloer Themes.  It's nice to have so many themes available.

As I upgraded my system to an Ubuntu system, I decided to also upgrade Roller to Roller 4.0.   Roller 4.0 was quite easier to install or upgrade than Roller 3.0.   I just edited the roller-custom.properties and place it in /glassfishv2/domains/domain1/lib/classes and I was ready to go.  Here is the contents:

installation.type=auto database.configurationType=jdbc database.jdbc.driverClass=com.mysql.jdbc.Driver database.jdbc.connectionURL=jdbc:mysql://localhost:3306/rollerdb?autoReconnect=true&amp; useUnicode=true&amp;characterEncoding=utf-8&amp;mysqlEncoding=utf8 database.jdbc.username=sqluser database.jdbc.password=tsqlpassword mail.configurationType=properties mail.hostname=localhost

If you blog in languages other than English, you need to set the character set of your MYSQL server to be unicode utf8.  Edit the your my.cnf and add the following:

[client] default-character-set=utf8 [mysqld] character-set-server=utf8 default-collation=utf8_unicode_ci default-character-set=utf8

Also you need to change the JDBC connection string as follow to support utf8:

jdbc:mysql://localhost:3306/rollerdb?autoReconnect=true&amp; useUnicode=true&amp;characterEncoding=utf-8&amp;mysqlEncoding=utf8

One thing I am not happy about Roller 4.0 is that the Roller Themes from 3.0 don't work for Roller 4.0 any more.  There aren't any additional themes available for dowonload from the Roller Support Project.  Hope more themes are available soon.


fshell 发布于  2009-7-4 08:29 

Ubuntu Linux System

I just downloaded the Ubuntu 9.04, a free Linux operating system distribution from Ubuntu.  I installed the server version into my old machine purchased almost ten years ago.  This machine has a Intel II 400Mhz CPU, 1Gb memory, and a 12Gb hard disk.  I didn't installed the desktop system because it will be used mainly as a server.  I hope it's sufficient to serve this site.  Everything seems fine so far. 

I have had positive feelings about this operating system.  It made my life much more easier to install and configure my system.  I especially like the 'sudo apt-get install ' command used to install packages available online.  This is a big deal for me, who spent a lot of hours to install and configure my previous Solaris system on the same machine.  I used to download the source codes such as Send Mail, Cryrus, etc. I would compile and configure them step by step according to their instructions.  Those were very time-consuming operations. With 'sudo apt-get install ' from Ubuntu, I was able to installed all my packages online in minutes without any problems.  Thank to people working on this and making this possible!


fshell 发布于  2009-7-3 21:08