Click here to Skip to main content
15,893,904 members
Articles / Programming Languages / C#

JawBreaker Game in C#

Rate me:
Please Sign up or sign in to vote.
4.83/5 (44 votes)
28 Dec 20034 min read 413.2K   14.7K   111  
A simple implementation of Jawbreaker
using System;

namespace JawBreaker
{
	/// <summary>
	/// Summary description for Tester.
	/// </summary>
	public class Tester
	{
		public Tester()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public static void Test()
		{
			Cell[,] data=new Cell[3,3];
			Initialize(data);
			data[2,1]=null;
			Syncronize(data);
			Print(data);

			Console.ReadLine();


		}

		public static void Initialize(Cell[,] data)
		{
			int rows=data.GetLength(0);
			int cols=data.GetLength(1);
			for(int i=0;i<rows;i++)
			{
				for(int j=0;j<cols;j++)
				{

					data[i,j]=new Cell(i,j,3);
				}
				
			}

			


		}



		public static void Syncronize(Cell[,] data)
		{
			int rows=data.GetLength(0);
			int cols=data.GetLength(1);

			//Use bruteforce to sync for the time being
			for(int times=0;times<rows;times++)
			{
			
				for(int i=0;i<rows-1;i++)
				{
					for(int j=0;j<cols;j++)
					{
						Cell c=data[i,j];

						if(c!=null)
						{
							Cell other=data[c.Row+1,c.Col];
							if(other==null)
							{
								
								data[c.Row+1,c.Col]=c;
								data[c.Row,c.Col]=null;
								
							}

						}
					}
				}
			}
			
		}

		public static void Print(Cell[,] data)
		{
			int rows=data.GetLength(0);
			int cols=data.GetLength(1);
			for(int i=0;i<rows;i++)
			{
				for(int j=0;j<cols;j++)
				{
					if(data[i,j]==null)
					{
						Console.Write("--null-"+" ");
					}

					Console.Write(data[i,j]+" ");
				}
				Console.WriteLine();
			}

		}

		public static void Print(int[,] data)
		{
			int rows=data.GetLength(0);
			int cols=data.GetLength(1);
			for(int i=0;i<rows;i++)
			{
				for(int j=0;j<cols;j++)
				{
					Console.Write(data[i,j]+" ");
				}
				Console.WriteLine();
			}

		}



	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions