Results 1 to 2 of 2

Thread: Player 1 works in my game but how can I make "Player 2" work?

  1. #1

    Thread Starter
    Junior Member rastin's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    26

    Question Player 1 works in my game but how can I make "Player 2" work?

    Hi,
    Thanks all for helping me with my game so far.

    I've made a small board game which includes player one only (inc code as well for him to help with making code for player 2).

    I've also set up player 2's icons and labels etc...but not sure what code to make for him to work in the same way

    I’m sure that most of player 2’s code can be cut and pasted from player 1’s but I’m not sure which parts.

    How can I make player 2 work in the game?

    (.zip file attached which has the game)


    Thanks,
    Rastin

  2. #2
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    I'm guessing this game is at a fairly early stage, so I'm just going to make some general comments, not give actual code.

    1) You need a global variable (e.g. Dim CurrentPlayer as Integer) that indicates whose turn it is.

    2) Put a routine at the end of the players' turns to change it to the next player.

    3) Good programming practice says that you should assume in future there could be any number of players, not just two.

    Therefore duplicating your code for the two players is not a good idea. You'ld end up withj six copies for six players and it would be difficult to maintain.

    4) Write general routines for everything, and use the CurrentPlayer variable to control what is done.

    e.g. Image(CurrentPlayer).move etc...

    That way you can have the same code for every player. Easier to maintain and update.

    5) Instead of code like

    VB Code:
    1. Select Case Image2.Top
    2. Case "3360"
    3.   Image2.Top = 2535
    4. Case "2535"
    5.   Image2.Top = 1710
    6. Case "1710"
    7.   Image2.Left = 4755
    8.   Image2.Top = 1711
    9. End Select

    I would use global constants like

    VB Code:
    1. Dim Const CONST_A1 = 3360
    2. etc...

    VB Code:
    1. Select Case Image2.Top
    2. Case CONST_A1
    3.   Image2.Top = CONST_B1
    4. Case CONST_B1
    5.   Image2.Top = CONST_C2
    6.  
    7.  etc...

    That way you can set your constants at the start of the program and easily change them if you change the board size. You can also give them meaningful names.

    Hope the above helps!
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width