Pipe game. How to do checking of pipes on a connectedness
Hi, all. I try to write a game "Pipes". It will be a console game. I have got two questions.
First question: The program must check - Is this placing of pipes possible on the field ? i.e. Will a player be able to collect pipes? How to do this checking?
Second question: Checking of pipes on a connectedness. How to check do pipes befit to each other, or not ?
Description of game:
On the screen is presented the playing field, on which are located the angular elements of kind: ┌, └, ┘ , ┐, –, |,+, and others. Task of player - for the minimum number of rotations of these elements to make a single line from them. Example of game:http://home.earthlin...rn/pipegame.htm.
P.S. Sorry for my bad English. Hoping you understand me.
Re: Pipe game. How to do checking of pipes on a connectedness
Originally Posted by Pahanuch
Hi, all. I try to write a game "Pipes". It will be a console game. I have got two questions.
First question: The program must check - Is this placing of pipes possible on the field ? i.e. Will a player be able to collect pipes? How to do this checking?
Second question: Checking of pipes on a connectedness. How to check do pipes befit to each other, or not ?
Description of game:
On the screen is presented the playing field, on which are located the angular elements of kind: ┌, └, ┘ , ┐, –, |,+, and others. Task of player - for the minimum number of rotations of these elements to make a single line from them. Example of game:http://home.earthlink.net/~tdglenn/unicorn/pipegame.htm.
P.S. Sorry for my bad English. Hoping you understand me.
Re: Pipe game. How to do checking of pipes on a connectedness
Thanks, Pah. I might have some suggestions depending on how you want to do this. Is this going to be a Widows Forms application or a web-based app?
If Windows Forms, you could just use a bunch of pictureboxes in a grid, and then rotate the image onclick(). Web-based probably javascript to place images and rotate.
For rotation, why not use an array with four positions, representing "top", "right", "down", "left." Then fill the array with 0 if no line and 1 if line, so a line from top to boottom would be [1,0,1,0]. You could use multi-dimensional arrays with the first dimension representing the x,y grid coordinate of the square, and the second dimension representing which side the line went to. By comparing cell[0,1] to cell[1,1], you can tell if the lines are touching.
Just some ideas. I could maybe help mre if I knew how/what platform you wanted to build this on. Good luck!
Re: Pipe game. How to do checking of pipes on a connectedness
mrgr8avil, Thank U very mush. I want to build this in Console Application ... on C#.NET. But I don't understand, how we can to compare pipes. For example, if we to compare two objects [| and |] array1[1,0,1,0] (array1["top", "right", "down", "left"]) with array2 [1,0,1,0] ("top", "right", "down", "left") on cell [0,1] and [0,2]. We must to compare array2[top] with array1[down] and array2[left] with array1[right]. I don't understan how we can do that =(
Last edited by Pahanuch; August 27th, 2012 at 08:49 AM.
Re: Pipe game. How to do checking of pipes on a connectedness
As I typed this, I thought of about 50 ways it could be made simpler - but this would work and I hope will give you the starting block to do something better on your own.
I am really thinking it will not be possible to do what you want in a console environment, since the console environment is not suited to mouse input or refreshing or graphics or really anything. I suppose you could draw the grid using ASCII, then require the user to type the x,y coordinates of the tile they want to rotate, then re-draw the grid with the change - but that is cumbersome and ugly. I'm really thinking either web or form would be the only way to go, but I'm interested in seeing what you come up with if you continue to try for a console. Good luck!!
Code:
int gridX = 10;//how many rows
int gridY = 10;//how many columns
gameSquare[,] gameSurface = null;
public pipes(int gameRows, int gameColumns)
{
gameSurface = new gameSquare[gridX, gridY];
//load original tiles
for (int x = 0; x < gameRows; x++)
{
for (int y = 0; y < gameColumns; y++)
{
gameSurface[x, y] = new gameSquare(x, y, new int[] { 0, 0, 0, 0 });
}
}
}
public void rotateTile(int xCoord, int yCoord)
{
gameSurface[xCoord, yCoord].rotate();
evaluateTiles();
}
private void evaluateTiles()
{
//square above would be y-1
//square below is y+1
//square to left is x-1;
//square to right is x+1;
for (int x = 0; x < gridX; x++)
{
for (int y = 0; y < gridY; y++)
{
//set connected to false to begin with - logic will correct if truly connected
gameSurface[x, y - 1].isConnected(false);
gameSurface[x - 1, y].isConnected(false);
//start with second row
if (y > 0)
{
//check if top of square matches bottom of square above it
if (gameSurface[x, y - 1].pipeSides[2] == 1 && gameSurface[x, y].pipeSides[0] == 1)
{
gameSurface[x, y - 1].isConnected(true);
}
}
//start with second column
if (x > 0)
{
//check to see if left of square matches right of square to left of it
if (gameSurface[x - 1, y].pipeSides[1] == gameSurface[x, y].pipeSides[3])
{
gameSurface[x - 1, y].isConnected(true);
}
}
}
}
}
class gameSquare
{
int xPosInGrid;
int yPosInGrid;
public int[] pipeSides = { 0, 0, 0, 0 }; // Top right bottom left, 1 if pipe touches, 0 if no pipe touches
public bool[] connected = { false, false, false, false };
public gameSquare(int xCoordinate, int yCoordinate, int[] initialPipeSides)
{
xPosInGrid = xCoordinate;
yPosInGrid = yCoordinate;
pipeSides = initialPipeSides;
}
public void rotate()
{
//clockwise
for (int i = 0; i < pipeSides.Length; i++)
{
if (pipeSides[i] == 0)
{
pipeSides[i] = 1;
}
}
}
public void isConnected(bool isSquareConnected){
if(isSquareConnected){
//turn color to connected
}else{
//turn color to disconnected
}
}
}
Last edited by mrgr8avill; August 27th, 2012 at 09:30 AM.
Re: Pipe game. How to do checking of pipes on a connectedness
Thanks! You really helped me. But can you help me last time, if it not hard for you ?! I don't know how to do line-up of the pipes from centre (like in example). I show, what I mean, on the picture.
Re: Pipe game. How to do checking of pipes on a connectedness
You're welcome. I think the center square would always be connected. You can set its connected to true after processing the rest of the squares. I think the logic I provided in my last sample would accommodate this, but you can always set it to connected manually if it does not. Good luck!
Re: Pipe game. How to do checking of pipes on a connectedness
I'm sorry, but it seems to me, that you not correctly understand me. I will try to explain again. So, For Example, if some square has not line-up to centre square, but has line-up to others square, which has not line-up to centre too - then this squares (pipes) will not change the color to blue. Because this squares (pipes) is has not way to center square (source water). I'm sorry, againg, for my bad English. Its not my native language.
Re: Pipe game. How to do checking of pipes on a connectedness
I understand what you need now. You can follow the logic of my code. Apply it to the center square. I have provided enough to do what you need. Now it is up to you to finish it. I know you want to do this yourself. So I don't want to do it for you. Good luck!
Re: Pipe game. How to do checking of pipes on a connectedness
I did that...
Code:
field [i, j].down = 1;
field [i, j].top = 1;
field [i, j].right = 0;
field [i, j].left = 0;
if ((field [i, j - 1].down == 1 && field [i, j].top == 1) && ((field [i, j - 1].flag == false && field [i, j].flag == true) ||
(field [i,j-1].flag == true && field [i,j].flag == false) || (field [i,j - 1].flag == true && field [i,j].flag == true))) {
field [i, j].flag = true;
field [i, j - 1].flag = true;
cx.Cells [i + 2, j - 1 + 2].BackgroundColor = ConsoleColor.Blue;
cx.Cells [i + 2, j + 2].BackgroundColor = ConsoleColor.Blue;}
but now i have got a new problem. I can't to do cheking for uncoupling of pipes. When the way to center was broken, others pipes, must to lost connection to center. I can't understand how to do this. Help me if you can, please.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.