Changeset 3a0d468 in galcon-client


Ignore:
Timestamp:
Jun 20, 2010, 6:29:03 PM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
a4f5200, b87af8a
Parents:
9d030cb
Message:

Added code to connect to the game server.

Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • AndroidManifest.xml

    r9d030cb r3a0d468  
    1111    </application>
    1212    <uses-sdk android:minSdkVersion="7" />
     13    <uses-permission android:name="android.permission.INTERNET" />
    1314</manifest>
  • res/values/strings.xml

    r9d030cb r3a0d468  
    88    <string name="menu_pause">Pause</string>
    99    <string name="menu_resume">Resume</string>
    10     <string name="menu_easy">Easy</string>
    11     <string name="menu_medium">Medium</string>
    12     <string name="menu_hard">Hard</string>
     10    <string name="menu_connect">Connect</string>
    1311   
    1412    <string name="mode_ready">Lunar Lander\nPress Up To Play</string>
  • src/com/example/helloandroid/Game.java

    r9d030cb r3a0d468  
    1111
    1212public class Game extends Activity {
    13     private static final int MENU_EASY = 1;
    14 
    15     private static final int MENU_HARD = 2;
    16 
    17     private static final int MENU_MEDIUM = 3;
    18 
    19     private static final int MENU_PAUSE = 4;
    20 
    21     private static final int MENU_RESUME = 5;
    22 
    23     private static final int MENU_START = 6;
    24 
    25     private static final int MENU_STOP = 7;
     13    private static final int MENU_PAUSE = 1;
     14    private static final int MENU_RESUME = 2;
     15    private static final int MENU_START = 3;
     16    private static final int MENU_STOP = 4;
     17    private static final int MENU_CONNECT = 5;
    2618
    2719    /** A handle to the thread that's actually running the animation. */
    28     private DrawingThread mThread;
     20    public DrawingThread mThread;
    2921
    3022    /** A handle to the View in which the game is running. */
    3123    private GameView mGameView;
    3224
     25    private ClientThread client;
     26   
    3327    /**
    3428     * Invoked during init to give the Activity a chance to set up its Menu.
     
    4539        menu.add(0, MENU_PAUSE, 0, R.string.menu_pause);
    4640        menu.add(0, MENU_RESUME, 0, R.string.menu_resume);
    47         menu.add(0, MENU_EASY, 0, R.string.menu_easy);
    48         menu.add(0, MENU_MEDIUM, 0, R.string.menu_medium);
    49         menu.add(0, MENU_HARD, 0, R.string.menu_hard);
     41        menu.add(0, MENU_CONNECT, 0, R.string.menu_connect);
    5042
    5143        return true;
     
    6658                return true;
    6759            case MENU_STOP:
    68                 mThread.setState(DrawingThread.STATE_LOSE,
    69                         getText(R.string.message_stopped));
     60                mThread.setState(DrawingThread.STATE_LOSE, getText(R.string.message_stopped));
    7061                return true;
    7162            case MENU_PAUSE:
     
    7566                mThread.unpause();
    7667                return true;
     68            case MENU_CONNECT:
     69                mThread.connectionStarted = true;
     70                client = new ClientThread("192.168.1.6", 1337, this);
     71                                client.start();
     72                                mThread.doStart();
     73                                return true;
    7774        }
    7875
  • src/com/example/helloandroid/GameView.java

    r9d030cb r3a0d468  
    8181       
    8282        int mFleetSize;
     83       
     84        public boolean connectionStarted;
     85        public String connMessage;
    8386
    8487        public DrawingThread(SurfaceHolder surfaceHolder, Context context,
     
    107110           
    108111            mFleetSize = 50;
     112           
     113            connectionStarted = false;
     114            connMessage = "";
    109115        }
    110116
     
    346352                }
    347353                }
    348                
     354       
     355                //draw the fleet size bar on the bottom of the screen
    349356                float textSize = mTextPaint.getTextSize();
    350357                mTextPaint.setTextSize(24);
     
    355362               
    356363                mTextPaint.setTextSize(textSize);
    357                
     364       
    358365                mLinePaint.setColor(Color.YELLOW);
    359366                canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, mCanvasWidth-70, mCanvasHeight-5), 5, 5, mLinePaint);
     
    361368                mLinePaint.setColor(Color.GREEN);
    362369                canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, 70+(mCanvasWidth-140)*mFleetSize/100, mCanvasHeight-5), 5, 5, mLinePaint);
     370               
     371                //draw connection info
     372                if(connectionStarted) {
     373                        canvas.drawText(connMessage, (mCanvasWidth-mTextPaint.measureText(connMessage))/2, mCanvasHeight-200-(metrics.ascent+metrics.descent), mTextPaint);
     374                }
    363375        }
    364376
Note: See TracChangeset for help on using the changeset viewer.