Need Help Creating Light Out Game!

This is a discussion on Need Help Creating Light Out Game! within the C++ Programming forums, part of the General Programming Boards category; I need help making a lights out game using a regular command prompt. It is 5 rows by 5 columns ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    21

    Need Help Creating Light Out Game!

    I need help making a lights out game using a regular command prompt.
    It is 5 rows by 5 columns using a matrix and by showing to the user the results using “cout” statements and two different characters, one for ON and one for OFF. The user has to enter the row and column to change.

    Code:
    0 0 0 0 0
    0 0 1 0 0
    0 1 1 1 0
    0 0 1 0 0
    0 0 0 0 0
    
    Col:   2
    Row: 2
    lights on (1) : 5
    lights off (0) : 20
    Number of moves: 1
    This is what I have so far, but I don't know where to go from there.
    Thank You!

    Code:
    #include <iostream>
    using namespace std;
    
    
    main ()
    {
    	int row1, col1
    	const int size = 5;
    	char on[5][5] ={{'0','0','0','0','0'}, 
    					{'0','0','0','0','0'},
    					{'0','0','0','0','0'},
    					{'0','0','0','0','0'},
    					{'0','0','0','0','0'}};
    	for (int row = 0; row < size; row ++)
    	{
    		for(int col = 0; col < size; col++)
    		{
    			cout << on[row][col];
    		}
    		cout << endl;
    	}
    
    
    return 0;
    }

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    hmm.. what are the rules of this game..?!??! I would help but I don' t even know how to play...
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    21
    Well you enter a number for row and colum and spot changes to a 1, and so does the adjacent values both verticallly and horizontally. The object is to turn all the zeros to ones.

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Lightbulb

    ok.. i think i got it...

    so far.. you have created a nice 2d array of your board...

    Now all we need are functions to:

    • Prompt the user for coord input (if user enters 'Q', then quit)
    • Set the 2d array in response to user input
    • Winner determination check (loop through the entire board, if all 1's, then win == TRUE)
    • Reset function in case player wants to play again (reset all var's and set board to all 0's)
    • Optional: use file I/O to record previous high scores.. and provide and option to view high scores



    think that's about it..


    lights out..!!
    Last edited by The Brain; 10-29-2005 at 07:14 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    21
    I have this so far, but how do you calculate the number of lights on and off? Also how do I make the loop end if all the zeros are ones? Also when I try to change one of the corners it turn a zero into 1 one in the wrong spot.
    Code:
    #include <iostream>
    using namespace std;
    
    
    
    int main()
    {
    	int row1, col1, move = -1;
    	const int size = 5;
    
    	int light[size][size] ={{0,0,0,0,0}, 
    							{0,0,0,0,0},
    							{0,0,0,0,0},
    							{0,0,0,0,0},
    							{0,0,0,0,0}};
    	for (int row = 0; row < size; row ++)
    	{
    		cout <<"\t";
    		for(int col = 0; col < size; col++)
    		{
    			cout << light[row][col];
    		}
    		cout << endl;
    	}
    
    	cout << endl;
    
    
    
    	do
    	{
    		move += 1;
    		cout << "Number of moves: " <<move << endl;
    		cout << "Col: ";
    		cin >> col1;
    		cout << "Row: ";
    		cin >> row1;
    		
    		cout << endl;
    		if(light[row1][col1] == 0)
    		{
    			light[row1][col1] = 1;
    		
    	
    			if(light[row1 + 1][col1] == 1)
    			{
    			light[row1 + 1][col1] = 0;
    			}
    			else
    			{
    				light[row1 + 1][col1] = 1;
    			}
    
    			if(light[row1 - 1][col1] == 1)
    			{
    			light[row1 - 1][col1] = 0;
    			} 
    			else
    			{
    				light[row1 - 1][col1] = 1;
    			}
    
    			if(light[row1][col1 + 1] == 1)
    			{
    				light[row1][col1 + 1] =0;
    			}
    			else
    			{
    				light[row1][col1 + 1] = 1;
    			}
    				
    			if(light[row1][col1 - 1] == 1) 
    			{
    				light[row1][col1 - 1] = 0;
    			}
    			else 
    			{
    				light[row1][col1 - 1] = 1;
    			}
    		}
    		
    		else if (light[row1][col1] == 1)
    		{
    			light[row1][col1] = 0;
    		
    		
    			if(light[row1 + 1][col1] == 0)
    			{
    			light[row1 + 1][col1] = 1;
    			}
    			else
    			{
    				light[row1 + 1][col1] =0;
    			}
    
    			if(light[row1 - 1][col1] == 0)
    			{
    			light[row1 - 1][col1] = 1;
    			} 
    			else
    			{
    				light[row1 - 1][col1] = 0;
    			}
    
    			if(light[row1][col1 + 1] == 0)
    			{
    				light[row1][col1 + 1] =1;
    			}
    			else
    			{
    				light[row1][col1 + 1] = 0;
    			}
    				
    			if(light[row1][col1 - 1] == 0) 
    			{
    				light[row1][col1 - 1] = 1;
    			}
    			else 
    			{
    				light[row1][col1 - 1] = 0;
    			}
    		}
    		
    
    		for (int row = 0; row < size; row ++)
    		{
    			cout <<"\t";
    			for(int col = 0; col < size; col++)
    			{
    				cout << light[row][col];
    			}
    			cout << endl;
    		}
    		cout << endl;
    		
    	}while(size);
    	
    	return 0;
    
    	
    }
    Last edited by slickwilly440; 10-29-2005 at 07:41 PM.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    21
    I got the program to calculat the number of lights on and off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating an AI engine for a simple game
    By cyb3r in forum Game Programming
    Replies: 1
    Last Post: 01-26-2009, 12:19 PM
  2. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-21-2006, 11:23 PM
  3. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-25-2006, 11:14 PM
  4. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  5. My Memory Game
    By jazy921 in forum C Programming
    Replies: 0
    Last Post: 05-05-2003, 05:13 PM

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