Advertisement

checkers

Started by May 22, 2018 02:43 AM
15 comments, last by phil67rpg 6 years, 6 months ago

void black_piece()
{
	if (board[5][1] == 1)
	{
		drawScene_move();
	}
	if (board[4][0] == 1)
	{
		flag[4][0] = true;
//		drawScene_move_one();
	}
	if (board[4][2] == 1)
	{
		flag[4][2] = true;
//		drawScene_move_two();
	}
}

void move_piece()
{
	if (flag[4][0] == true)
	{
		flag[4][2] = false;
		drawScene_move_one();
	}
	if (flag[4][2] == true)
	{
		flag[4][0] = false;
		drawScene_move_two();
	}
}

void mouseMotion(int x, int y)
{
	if (y <= 180)
	{
		y = 180;
	}
	if (x <= 240)
	{
		x = 240;
	}
	if (y >= 420)
	{
		y = 420;
	}
	if (x >= 560)
	{
		x = 560;
	}
	board[(y - 180) / 30][(x - 240) / 40] = 1;
	cout << x << " " << y << endl;
	move_piece();
	black_piece();
	glFlush();
}

well I am making a checkers game using c++ and opengl. I am trying to get one piece to move from one  space to another but do it only once not twice.

2 hours ago, phil67rpg said:

well I am making a checkers game using c++ and opengl. I am trying to get one piece to move from one  space to another but do it only once not twice.

Ok.

 

You've been told quite a few times that this forum is not for status updates -- use the blogs for that.

Do you have a specific question?

Hello to all my stalkers.

Advertisement

well with my code I am able to erase a piece at the original square. Then I can drag and drop a piece at the upper left square and the upper right square. Unfortunately I can drag and drop a piece to both locations. I want to only drag and drop a piece at only one location and not at the other location.

please help, do you need more info?

I'm assuming mouseMotion is called in a loop/every frame. This also means that black_piece is called every time.

Inside black_piece, you set some flags to be true, depending on where the mouse cursor is. Inside move_piece, you check some flags, and force the other flag to be false.

But since mouseMotion (and thus black_piece) will be called the next frame as well, the flag you set to false can get set to true again. That is,  flag[4][0] can be true and set flag[4][2] to false, while the next frame board[4][2] can be 1, which will set flag[4][2] to true, which will end up calling drawScene_move_two.

 

I have no clue how to solve the problem you have. I don't understand what you're trying to do, based on the code you have. The tiny amount of code you've posted hints at very strange decisions and architecture (which is the same as things have been the last x years you've been posting here). I have no clue what "board" or "flag" is supposed to mean, and I honestly doubt looking at more of your code will make things clearer.

Hello to all my stalkers.

19 hours ago, phil67rpg said:

well with my code I am able to erase a piece at the original square. Then I can drag and drop a piece at the upper left square and the upper right square. Unfortunately I can drag and drop a piece to both locations. I want to only drag and drop a piece at only one location and not at the other location.

I'm confused as well regarding the specifics but I'll try anyhow.

As long as you're using some form of a map like a 2D Array, and if your game is using official tournament rules there shouldn't be any issue with setting the proper jumps. If you're allowing the player to optionally refuse double or triple jumping then you need to either put a movement queue in place, or stop the jump at the dropped position.

If the issue is your code for movement is getting looped through over and over when you only intend it to run once per movement cycle, then you either need to handle the mouse click through an event manager that sets a boolean that an action has taken place, then run your logic and wait until another event, or program this to cycle once through your real-time input in your logic step.

I would also run it on a one stop cycle which means when you move the piece you have an algorithm which determines the jump path, then it executes it and stops as opposed to moving, checking, moving, checking, in real-time per tick.

Programmer and 3D Artist

Advertisement

void black_piece()
{
	if (board[5][1] == 1)
	{
		drawScene_move();
	}
	if (board[4][0] == 1)
	{
		drawScene_move_one();
	}
	if (board[4][2] == 1)
	{
		drawScene_move_two();
	}
}

void mouseMotion(int x, int y)
{
	if (y <= 180)
	{
		y = 180;
	}
	if (x <= 240)
	{
		x = 240;
	}
	if (y >= 420)
	{
		y = 420;
	}
	if (x >= 560)
	{
		x = 560;
	}
	board[(y - 180) / 30][(x - 240) / 40] = 1;
	cout << x << " " << y << endl;
	black_piece();
	glFlush();
}

I cut out some of my code that is not useful, but I am still getting the same problem.

You didn't address anything that was said in my above post.

Your code above does zero in terms of explaining to us anymore than you had done so prior.

Programmer and 3D Artist


void black_piece()
{
	if (board[5][1] == 1)
	{
		drawScene_move();
		move_piece[5][1] = true;
	}
	if (board[4][0] == 1)
	{
		drawScene_move_one();
		move_piece[4][0] = true;
	}
	if (board[4][2] == 1)
	{
		drawScene_move_two();
		move_piece[4][2] = true;
	}
}

void mouseMotion(int x, int y)
{
	if (y <= 180)
	{
		y = 180;
	}
	if (x <= 240)
	{
		x = 240;
	}
	if (y >= 420)
	{
		y = 420;
	}
	if (x >= 560)
	{
		x = 560;
	}
	board[(y - 180) / 30][(x - 240) / 40] = 1;
	cout << x << " " << y << endl;
	black_piece();
	glFlush();
}

I have read your comments on my game. You said that my movement should be run once per cycle. Also that the mouse click should be run through an event manager. I am unclear what you mean by an event manager. however I do know how to set a Boolean that an action has taken place.

If you're able to upload your entire source code (make sure I can compile and run it) I can look into this more to better explain a solution.

Programmer and 3D Artist

This topic is closed to new replies.

Advertisement