Ако обаче откриете целта навреме, печелите текущата игра.
- Код: Избери целия код
/*
* Created by SharpDevelop.
* User: Добромир
* Date: 10.3.2019 г.
* Time: 19:20 ч.
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Цел
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
string[,] Pole;
int Opiti, TargetRow, TargetCol;
bool OK, EndTime;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
Pole = new string[16,16];
for(int row = 0; row < 16; row++)
for(int col = 0; col < 16; col++)
Pole[row, col] = "????";
Opiti = 7;
OK = EndTime = false;
Random rnd= new Random();
TargetRow = rnd.Next(16);
TargetCol = rnd.Next(16);
}
void MainFormKeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)27) Application.Exit();
}
void MainFormPaint(object sender, PaintEventArgs e)
{
Color clr;
e.Graphics.DrawString("Остават " + Opiti + " опита...", new Font("Arial", 32.0f),
new SolidBrush(Color.Red), 128.0f, 8.0f);
for(int row = 0; row < 16; row++)
for(int col = 0; col < 16; col++)
{
e.Graphics.DrawRectangle(new Pen(Color.Brown, 2.7f),
40 * row + 3, 128 + 32 * col + 3,
34, 26);
clr = Color.Yellow;
if(Pole[row, col] == "OK! ") clr = Color.Red;
else if(Pole[row, col] != "????") clr = Color.Green;
e.Graphics.DrawString(Pole[row, col], new Font("Arial", 9.0f),
new SolidBrush(clr),
40 * row + 5, 128 + 32 * col + 7);
}
if(EndTime)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White),0,0,639,639);
e.Graphics.DrawString("BAD JOB!", new Font("Arial", 64.0f),
new SolidBrush(Color.Red), 120.0f, 260.0f);
}
if(OK)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White),0,0,639,639);
e.Graphics.DrawString("OK!", new Font("Arial", 64.0f),
new SolidBrush(Color.Red), 260.0f, 260.0f);
}
}
void MainFormMouseDown(object sender, MouseEventArgs e)
{
int row, col;
double dlt;
if(e.Y > 128)
{
row = e.X / 40;
col = (e.Y - 128) / 32;
dlt = Math.Sqrt((row - TargetRow) * (row - TargetRow) + (col - TargetCol) * (col - TargetCol));
if(dlt < 0.9)
{
Pole[row, col] = "OK! ";
OK = true;
}
else
Pole[row, col] = ("" + dlt).Substring(0,Math.Min(4,(""+dlt).Length));
Opiti--;
if(Opiti <= 0)
EndTime = true;
}
this.Invalidate();
}
}
}

Меню