Basic structure for 2 player game

This is a discussion on Basic structure for 2 player game within the C Programming forums, part of the General Programming Boards category; Hi, I coded a game, some years ago now, and am trying get back into coding so excuse the stupid ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    Basic structure for 2 player game

    Hi,
    I coded a game, some years ago now, and am trying get back into coding so excuse the stupid question, but it was a one player game with the basic structure:
    Code:
    do
    	{	
    		******	
    	}
    	while(c != 27 || score > 0);
    What i want to do is adapt it to include two players, I was wondering what sort of structure i could / should use (if there is a nice way of doing it) instead of having a a whole bunch of 'if' statements laying around. Also all the 'movement', 'score', 'end game' etc... code exist in their own functions and can be used independantly by each play obvisouly, so its really just the do-while i want to optimise.

    Appreciate any help, thankyou.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    while no winner
        set active player
        get move from active player
        plot move
    Pretty much the same idea. Make a function that takes valid input. Maybe another one (depending on what sort of game you're making) that checks to see if that's valid, and if not, sends you back to re-enter your input, make a 'check win'. Make something to display the updated board (or whatever your game is).


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2
    Ahh, im an idiot, a simple while loop with a win flag, thx quzah, ive already coded the functions (essentially) so should be sweet, thx.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 04:18 PM
  2. Please help with some coding..
    By stehigs321 in forum C Programming
    Replies: 2
    Last Post: 10-27-2003, 06:44 PM
  3. Game Structure
    By Travis Dane in forum Game Programming
    Replies: 7
    Last Post: 12-27-2002, 12:34 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21