private void GameFormMode1_Paint(object sender, PaintEventArgs e) { if (next_game_shown) { AnotherGame.Show(); } else { AnotherGame.Hide(); } // draw playing area // it goes first by the colls - X for (int i = 0; i < this.settings.cols; i++) { for (int j = 0; j < this.settings.rows; j++) { Pen blackPen = new Pen(Color.Black, 1); e.Graphics.DrawRectangle(blackPen, i * this.settings.cell_size + INDENT_X, j * this.settings.cell_size + INDENT_Y, this.settings.cell_size, this.settings.cell_size); } } // draw blocks foreach (Block block in positionedBlocks) { block.Kresli(e.Graphics); } if (showWin) { Graphics g = e.Graphics; Bitmap main_image = new Bitmap("smile.png"); next_game_shown = true; Color backColor = main_image.GetPixel(1, 1); main_image.MakeTransparent(backColor); e.Graphics.DrawImage( main_image, this.Width - 100, 0, 64, 64); } }
private void GameFormMode1_MouseUp(object sender, MouseEventArgs e) { clicked = false; if (MouseButtons.Left == e.Button) { if (selected != null) { clicked = false; int half_size = settings.cell_size / 2; if ((selected.x >= INDENT_X - half_size && selected.x < INDENT_X + half_size + (this.settings.cols * this.settings.cell_size)) && (selected.y >= INDENT_Y - half_size && selected.y < INDENT_Y + half_size + (this.settings.rows * this.settings.cell_size))) { // suradnice bez odsunutia var noindentX = (selected.x - INDENT_X); var noindentY = (selected.y - INDENT_Y); // doskakovanie int dx = noindentX % this.settings.cell_size; int dy = noindentY % this.settings.cell_size; // dole v pravo if (dx > half_size && dy > half_size) { noindentX += settings.cell_size - dx; noindentY += settings.cell_size - dy; } // hore v pravo else if (dx > half_size && dy <= half_size) { noindentX += settings.cell_size - dx; } // dole v lavo else if (dx <= half_size && dy > half_size) { noindentY += settings.cell_size - dy; } // konecny prepocet doskakovania selected.x = (noindentX / this.settings.cell_size) * this.settings.cell_size + INDENT_X; selected.y = (noindentY / this.settings.cell_size) * this.settings.cell_size + INDENT_Y; selected.in_playground = true; // moved same object for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // moved same object if (playground[r, s] == selected.id) { playground[r, s] = 0; } } } // playing int fromX = noindentX / this.settings.cell_size; int fromY = noindentY / this.settings.cell_size; Console.WriteLine($"{INDENT_X} {INDENT_Y}, {selected.x} {selected.y}"); int toX = (selected.width / this.settings.cell_size) + fromX; int toY = (selected.height / this.settings.cell_size) + fromY; bool return_to_start = false; // if in playground borders if ((toX <= settings.cols) && (toY <= settings.rows) && (fromX >= 0) && (fromY >= 0)) { // set ocupied space to selected block id for (int r = fromY; r < toY; r++) { for (int s = fromX; s < toX; s++) { // occupied place if (playground[r, s] != 0) { return_to_start = true; break; } else { playground[r, s] = selected.id; } } } if (return_to_start == false) { // TODO: chyba gridBlocks //if (!gridBlocks.Contains(selected)) //{ // gridBlocks.Add(selected); // update_colors(); //} } // check game over int num = 0; for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // empty place if (playground[r, s] == 0) { num += 1; } } } // game over -- filled all blocks if (num == 0) { for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // empty place aby sa nam resetla po vyhrati matica na nuly playground[r, s] = 0; } } showWin = true; AnotherGame.Show(); } } else { return_to_start = true; } // move to start position if (return_to_start) { selected.x = selected.startX; selected.y = selected.startY; selected.in_playground = false; // TODO: chyba gridBlocks //if (gridBlocks.Contains(selected)) //{ // gridBlocks.Remove(selected); // update_colors(); //} } } else { selected.x = selected.startX; selected.y = selected.startY; selected.in_playground = false; // TODO: chyba gridBlocks //if (gridBlocks.Contains(selected)) //{ // gridBlocks.Remove(selected); // update_colors(); //} // moved out of the playground for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // reset if (playground[r, s] == selected.id) { playground[r, s] = 0; } } } } deltaX = 0; deltaY = 0; selected = null; Invalidate(); } } }
private void GameFormMode2_MouseUp(object sender, MouseEventArgs e) { clicked = false; if (MouseButtons.Left == e.Button) { if (selected != null) { clicked = false; int half_size = settings.cell_size / 2; if ((selected.x >= 0 + INDENT_X - half_size && selected.x < INDENT_X + half_size + this.settings.cols * this.settings.cell_size) && (selected.y >= 0 + INDENT_Y - half_size && selected.y < INDENT_Y + half_size + this.settings.rows * this.settings.cell_size)) { // suradnice bez odsunutia var noindentX = (selected.x - INDENT_X); var noindentY = (selected.y - INDENT_Y); // doskakovanie int dx = noindentX % this.settings.cell_size; int dy = noindentY % this.settings.cell_size; // dole v pravo if (dx > half_size && dy > half_size) { noindentX += settings.cell_size - dx; noindentY += settings.cell_size - dy; } // hore v pravo else if (dx > half_size && dy <= half_size) { noindentX += settings.cell_size - dx; } // dole v lavo else if (dx <= half_size && dy > half_size) { noindentY += settings.cell_size - dy; } // konecny prepocet doskakovania selected.x = (noindentX / this.settings.cell_size) * this.settings.cell_size + INDENT_X; selected.y = (noindentY / this.settings.cell_size) * this.settings.cell_size + INDENT_Y; selected.in_playground = true; // moved same object for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // moved same object if (playground[r, s] == selected.id) { playground[r, s] = 0; } } } // moved block - check if in playground and mark or rewrite ids in playground int fromX = noindentX / this.settings.cell_size; int fromY = noindentY / this.settings.cell_size; int toX = (selected.width / this.settings.cell_size) + fromX; int toY = (selected.height / this.settings.cell_size) + fromY; // if in playground borders if ((toX <= settings.cols) && (toY <= settings.rows) && (fromX >= 0) && (fromY >= 0)) { // set ocupied space to selected block id foreach (Block block in this.settings.blocks) { // ak je uz v ploche odpocitaj INDENT if (block.in_playground) { fromX = (block.x - INDENT_X) / this.settings.cell_size; fromY = (block.y - INDENT_Y) / this.settings.cell_size; } else { fromX = block.x / this.settings.cell_size; fromY = block.y / this.settings.cell_size; } toX = (block.width / this.settings.cell_size) + fromX; toY = (block.height / this.settings.cell_size) + fromY; // prepise sa playground podla aktualnych tapiet if ((toX <= settings.cols) && (toY <= settings.rows) && (fromX >= 0) && (fromY >= 0)) { for (int r = fromY; r < toY; r++) { for (int s = fromX; s < toX; s++) { playground[r, s] = block.id; } } } } // check game over int num = 0; for (int i = 0; i < this.settings.cols; i++) { for (int j = 0; j < this.settings.rows; j++) { if (settings.playground[j, i] != playground[j, i]) { num++; } } } // game over -- filled all blocks if (num == 0) { for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // empty place aby sa nam resetla po vyhrati matica na nuly playground[r, s] = 0; } } AnotherGame.Show(); showWin = true; } // show block color if (!gridBlocks.Contains(selected)) { gridBlocks.Add(selected); update_colors(); } if (lastMoved.Contains(selected) == false) { lastMoved.Add(selected); } } else { // return to start selected.x = selected.startX; selected.y = selected.startY; if (gridBlocks.Contains(selected)) { gridBlocks.Remove(selected); update_colors(); } selected.in_playground = false; } } else { selected.x = selected.startX; selected.y = selected.startY; if (gridBlocks.Contains(selected)) { gridBlocks.Remove(selected); update_colors(); } selected.in_playground = false; // moved out of the playground for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // reset if (playground[r, s] == selected.id) { playground[r, s] = 0; } } } } deltaX = 0; deltaY = 0; selected = null; Invalidate(); } } }
void GameFormMouseUp(object sender, MouseEventArgs e) { clicked = false; if (selected.x >= 0 && selected.x < this.settings.cols * this.settings.cell_size) { if (selected.y >= 0 && selected.y < this.settings.rows * this.settings.cell_size) { selected.x = (selected.x / this.settings.cell_size) * this.settings.cell_size; selected.y = (selected.y / this.settings.cell_size) * this.settings.cell_size; } } Invalidate(); deltaX = 0; deltaY = 0; this.print_playground(); // check game over int num = 0; for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // empty place if (playground[r, s] == 0) { num += 1; } // occupied but moved - unset else if (playground[r, s] == selected.id) { playground[r, s] = 0; } } } if (num == 0) { for (int r = 0; r < this.settings.rows; r++) { for (int s = 0; s < this.settings.cols; s++) { // empty place aby sa nam resetla po vyhrati matica na nuly playground[r, s] = 0; } } GoodGameL.Show(); AnotherGame.Show(); } // _________________SEM TO NESEDI_________________ int fromX = selected.x / this.settings.cell_size; int fromY = selected.y / this.settings.cell_size; //int toX = selected.width / this.settings.cell_size; //int toY = selected.height / this.settings.cell_size; int toX = (selected.width / this.settings.cell_size) + fromX; //prerobil som tieto 2 premenne int toY = (selected.height / this.settings.cell_size) + fromY; // Debug.WriteLine(fromX + " " + fromY); Debug.WriteLine(toX + " " + toY); // set ocupied space to selected block id for (int r = fromY; r <= toY; r++) { for (int s = fromX; s < toX; s++) { // to be occupied if ((r < settings.rows) && (s < settings.cols)) //doplnil som tento if!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! { playground[r, s] = selected.id; } } } this.print_playground(); }
private void GameFormMode2_Paint(object sender, PaintEventArgs e) { if (next_game_shown) { AnotherGame.Show(); } else { AnotherGame.Hide(); } // map block id to its color foreach (Block block in this.settings.blocks) { if (!idcolor_map.ContainsKey(block.id)) { idcolor_map.Add(block.id, block.color); } } Control control = (Control)sender; int local_indentX = INDENT_X + (settings.cols * settings.cell_size) + settings.cell_size; int local_indentY = INDENT_Y; for (int i = 0; i < this.settings.cols; i++) { for (int j = 0; j < this.settings.rows; j++) { // draw playing area Pen blackPen = new Pen(Color.Black, 1); e.Graphics.DrawRectangle(blackPen, i * this.settings.cell_size + INDENT_X, j * this.settings.cell_size + INDENT_Y, this.settings.cell_size, this.settings.cell_size); // draw final state example area e.Graphics.DrawRectangle(blackPen, i * this.settings.cell_size + local_indentX, j * this.settings.cell_size + local_indentY, this.settings.cell_size, this.settings.cell_size); if (idcolor_map.ContainsKey(settings.playground[j, i])) { Color c = idcolor_map[settings.playground[j, i]]; Brush brush = new SolidBrush(c); e.Graphics.FillRectangle(brush, i * this.settings.cell_size + local_indentX, j * this.settings.cell_size + local_indentY, this.settings.cell_size, this.settings.cell_size); } } } // draw blocks last foreach (Block block in settings.blocks) { block.Kresli(e.Graphics); } if (showWin) { Graphics g = e.Graphics; Bitmap main_image = new Bitmap("smile.png"); next_game_shown = true; Color backColor = main_image.GetPixel(1, 1); main_image.MakeTransparent(backColor); e.Graphics.DrawImage( main_image, this.Width - 100, 0, 64, 64); } }