//прорисовка следующего изображения public void drawNextFigure(int[,] nextFig, WiHd c) { Image nextFigureImg = new Bitmap(nextFigurePallete.Width, nextFigurePallete.Height); using (Graphics g = Graphics.FromImage(nextFigureImg)) { int x, y; x = nextFigurePallete.Width; y = nextFigurePallete.Height; for (int Y = 0; Y < 4; Y++) { for (int X = 0; X < 3; X++) { if (Y < c.eY && X < c.eX) { if (nextFig[X, Y] > 0) { //g.DrawImage(cell_1, X * (x / 3), Y * (y / 3), 15, 15); DrawFigCell(g, X * (x / 3), Y * (y / 4), nextFig[X, Y]); } else { // g.DrawImage(cell_0, X * (x / 3), Y * (y / 3), 15, 15); DrawClearCell(g, X * (x / 3), Y * (y / 4)); } } else { // g.DrawImage(cell_0, X * (x / 3), Y * (y / 3), 15, 15); DrawClearCell(g, X * (x / 3), Y * (y / 4)); } } } nextFigurePallete.Image = nextFigureImg; } }
//меню, сохранить игру private void сохранитьИгруToolStripMenuItem_Click(object sender, EventArgs e) { if (!saved) { options.coords = new WiHd(mX, mY); options.cells = cellBuffer; options.x = xfig; options.y = yfig; options.level = level; options.point = point; options.timer = timer.Interval; options.fc = getFigureColor(); options.nfc = getNextFigureColor(); saveProcess.saveToFile(options); сохранитьИгруToolStripMenuItem.Text = Resources.restore_game; toolStripButton5.Text = Resources.restore_game; очиститьСохранениеToolStripMenuItem.Visible = true; toolStripButton6.Visible = true; saved = true; } else { saveProcess.saveOptions s = new saveProcess.saveOptions(); if (saveProcess.ifSave(ref s)) { // resetGame(); defaultOptions(s.coords.eX, s.coords.eY); game = true; generate = true; activeKey = true; Focus(); timer.Enabled = true; mX = s.coords.eX; mY = s.coords.eY; cellBuffer = s.cells; xfig = s.x; yfig = s.y; saved = true; point = s.point; level = s.level; nextFigure = s.nextFigure; timer.Interval = s.timer; timerSlow = s.timer; generateFigure(s.figure, ref figure, ref coords, ref s.fc); label1.Visible = false; остановитьИгруToolStripMenuItem.Enabled = true; паузаToolStripMenuItem.Enabled = true; int[,] nFig = new int[3, 3]; WiHd c = new WiHd(0, 0); generateFigure(s.nextFigure, ref nFig, ref c, ref s.nfc); arrayCopy(ref cell, cellBuffer); drawNextFigure(nFig, c); drawCells(); } else { очиститьСохранениеToolStripMenuItem_Click(null, null); } } }
//таймер private void timer1_Tick(object sender, EventArgs e) { if (!game) { timer.Enabled = false; остановитьИгруToolStripMenuItem.Enabled = false; паузаToolStripMenuItem.Enabled = false; MessageBox.Show(Resources.game_end); } else { if (!generate) { Random r = new Random(); options.figure = nextFigure; fc = nfc; nfc = 0; generateFigure(nextFigure, ref figure, ref coords, ref nfc); for (int i = 0; i < r.Next(1, 3); i++) { rotateFigure(); } generate = true; activeKey = true; nextFigure = r.Next(0, 7); options.nextFigure = nextFigure; int[,] nFig = new int[3, 3]; WiHd c = new WiHd(0, 0); fc = nfc; nfc = 0; generateFigure(nextFigure, ref nFig, ref c, ref nfc); drawNextFigure(nFig, c); lineCleaner(); timer.Interval = timerSlow; if (point >= 10) { level++; timerSlow -= 50; timer.Interval = timerSlow; point = 0; } levelInformation(); } arrayCopy(ref cell, cellBuffer); if (arrayToArray(xfig, yfig)) { yfig++; } else { arrayCopy(ref cellBuffer, cell); yfig = 0; generate = false; activeKey = false; soundPlayer.playSound("figure-fall"); } } drawCells(); }
//генерация фигуры public void generateFigure(int f, ref int[,] fig, ref WiHd coor, ref int cl) { Random r = new Random(); //int color = r.Next(1, 8);//цвет фигуры //if (cl > 0) color = cl; int color = f + 1; // цвет привязан к фигуре if (cl == 0) { cl = color; //возвращаем цвет сгенерированой фиругы } switch (/*r.Next(0, 5)*/ f) { case 0: /* ### ### */ fig = new int[, ] { { 0, color, color }, { color, color, 0 }, }; coor = new WiHd(2, 3); break; case 5: /* ### ### */ fig = new int[, ] { { color, color, 0 }, { 0, color, color }, }; coor = new WiHd(2, 3); break; case 1: /* #### ## */ fig = new int[, ] { { color, color, color }, { 0, color, 0 }, }; coor = new WiHd(2, 3); break; case 2: /* #### */ fig = new int[, ] { { color, color, color, color }, }; coor = new WiHd(1, 4); break; case 3: /* # ##### */ fig = new int[, ] { { 0, 0, color }, { color, color, color }, }; coor = new WiHd(2, 3); break; case 6: /* # ##### */ fig = new int[, ] { { color, 0, 0 }, { color, color, color }, }; coor = new WiHd(2, 3); break; case 4: /* ##### ##### ##### */ fig = new int[, ] { { color, color }, { color, color }, }; coor = new WiHd(2, 2); break; } }