项目没有解决错误 [英] Project did not solve the error
本文介绍了项目没有解决错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
项目没有解决错误。我做了扫雷游戏,但是行和列给出了错误。
链接到我的项目
https://app.box.com/s/3go54y99ewfd3jdoa1um [ ^ ]
project did not solve the error.I did minesweeper game but row and column gives the error.
link to my project
https://app.box.com/s/3go54y99ewfd3jdoa1um[^]
//Box opening function function in the neighbor list
//Kutu açma fonksiyonu içindeki komşu listesi fonksiyonu
List<Box> ListOfNeighbours(int Row, int Column)
{
List<Box> TheList = new List<Box>();
for (int r = -1; r <= 1; r++)
{
for (int c = -1; c <= 1; c++)
{
if ((r == 0 && c == 0) || (Column + c < 0) || (Row + r < 0) || ((Column + c) >= RowCount) || (Row + r >= ColumnCount))
{
continue;
}
TheList.Add(ListOfBoxes[Row + r, Column + c]);
}
}
return TheList;
}
考虑所有项目
Consider all projects
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cet.MineSweeperGame
{
public partial class MineGame : Form
{
public MineGame()
{
InitializeComponent();
}
public int RowCount;
public int ColumnCount;
public int BombCount;
//Firstclickswhenthe bombwill be used toreset the game.
//İlk tıklamada bomba çıktığında oyunu yenilemek için kullanılacak.
bool FirstClick = true;
// All boxes will be kept in a list.
Box[,] ListOfBoxes;
//Geçen zamanı tutacak.
int timeCount= 0;
//Kalan bayrak sayısını tutacak.
int flagCount;
//Zaman sayacı
private void timer_Tick(object sender, EventArgs e)
{
txtTime.Text = timeCount++.ToString();
}
//Yenileme düğmesinin olayı
private void btnRenew_Click(object sender, EventArgs e)
{
if (numTotalBomb.Value < numRowCount.Value * numColumnCount.Value)
{
timer.Stop();
FirstClick = true;
ResetBoxBoard();
GenerateGame();
}
else
{
MessageBox.Show("Total bomb should be less than " + (numRowCount.Value * numColumnCount.Value).ToString());
}
}
//Refresh button cleaning function on the board
//Yenileme düğmesindeki tahtayı temizleme fonksiyonu
private void ResetBoxBoard()
{
BoxBoard.Enabled = true;
BoxBoard.Controls.Clear();
}
//When the form is installed just install the game.
//Form yüklendiğinde sadece oyunu kur.
private void MineGame_Load(object sender, EventArgs e)
{
GenerateGame();
}
//Game setting function
//Oyunu kurma fonksiyonu
private void GenerateGame()
{
RowCount = Convert.ToInt32(numRowCount.Value);
ColumnCount = Convert.ToInt32(numColumnCount.Value);
BombCount = Convert.ToInt32(numTotalBomb.Value);
timeCount = 0;
txtTime.Text = "0";
flagCount = Convert.ToInt32(numTotalBomb.Value);
txtFlag.Text = flagCount.ToString();
ListOfBoxes = new Box[RowCount, ColumnCount];
BoxBoard.Width = RowCount * Box.BOX_WIDTH;
this.Width = RowCount * Box.BOX_WIDTH + 13;
BoxBoard.Height = RowCount * Box.BOX_HEIGHT;
this.Height = BoxBoard.Height + BoxBoard.Top + 35;
//Create boxes and knees.
for (int r = 0; r < RowCount; r++)
{
for (int c = 0; c < ColumnCount; c++)
{
Box b = new Box();
ListOfBoxes[r, c] = b;
b.Column = c;
b.Row = r;
b.Top = r * Box.BOX_HEIGHT;
b.Left = c * Box.BOX_WIDTH;
//Hem sağ hem sol tık için
b.MouseUp += new MouseEventHandler(b_MouseUp);
BoxBoard.Controls.Add(b);
}
}
int currentBomb = 0;
//Random put a bomb.
Random rnd = new Random();
do
{
int random = rnd.Next(RowCount * ColumnCount);
int rndR = random / RowCount;
int rndC = random % ColumnCount;
if (!ListOfBoxes[rndR, rndC].isBomb)
{
ListOfBoxes[rndR, rndC].isBomb = true;
currentBomb++;
foreach (Box neighbour in ListOfNeighbours(rndR, rndC)) { neighbour.NeighboursBombCount++; }
}
} while (currentBomb < BombCount);
}
//Games in the function setting button assigned to mouse events
//Oyun kurma fonksiyonu içinde düğmelere atanan fare olayları
void b_MouseUp(object sender, MouseEventArgs e)
{
//left click
//Sol tıklama
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Box clickedBox = sender as Box;
if (!clickedBox.isFlagged)
{
if (clickedBox.isBomb)
{
if (FirstClick == false)
{
timer.Stop();
BoxBoard.Enabled = false;
ShowAllBombs();
//Bir de tıklanan bomba vurgulanacak. One bomb also clicked will be highlighted
clickedBox.BackColor = System.Drawing.Color.Red;
}
else
{
MessageBox.Show("Unlucky! Game will be renewed.");
ResetBoxBoard();
GenerateGame();
}
}
else
{
OpenBox(clickedBox);
if (timeCount == 0)
{ //The delayed onset of the next line counter have to take care of the problem.
//Bir sonraki satır sayacın geç başlaması sorununu halletmek için var.
timeCount++;
timer.Start();
FirstClick = false;
}
//The game is finished or not checking a box is opened.
//Oyunun bitip bitmediğini bir kutu açıldığında kontrol et.
if (isFinished())
{
timer.Stop();
BoxBoard.Enabled = false;
MessageBox.Show("Finished!");
}
}
}
}
//Sağ tıklama right click
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
Box b = (Box)sender;
if (!b.isFlagged)
{
b.isFlagged = true;
b.BackgroundImage = Image.FromFile(Application.StartupPath + "\\Flag.png");
b.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
flagCount--;
txtFlag.Text = flagCount.ToString();
}
else
{
b.isFlagged = false;
b.BackgroundImage = null;
flagCount++;
txtFlag.Text = flagCount.ToString();
}
//Games that run down the control flag of sheep.
//Oyunun bitip bitmediğini bayrak konunca da kontrol et.
if (isFinished())
{
timer.Stop();
BoxBoard.Enabled = false;
MessageBox.Show("Bitti.");
}
}
}
//Mouse events inside the box opening function
//Fare olayları içindeki kutu açma fonksiyonu
private void OpenBox(Box clickedBox)
{
if (clickedBox.NeighboursBombCount > 0)
{
clickedBox.Enabled = false;
clickedBox.Text = clickedBox.NeighboursBombCount.ToString();
clickedBox.isOpen = true;
}
else
{
clickedBox.Visible=false;
clickedBox.isOpen = true;
foreach (Box b in ListOfNeighbours(clickedBox.Row, clickedBox.Column))
{
if (!b.isOpen && !b.isFlagged) { OpenBox(b); }
}
}
}
//Box opening function function in the neighbor list
//Kutu açma fonksiyonu içindeki komşu listesi fonksiyonu
List<box> ListOfNeighbours(int Row, int Column)
{
List<box> TheList = new List<box>();
for (int r = -1; r <= 1; r++)
{
for (int c = -1; c <= 1; c++)
{
if ((r == 0 && c == 0) || (Column + c < 0) || (Row + r < 0) || ((Column + c) >= RowCount) || (Row + r >= ColumnCount))
{
continue;
}
TheList.Add(ListOfBoxes[Row + r, Column + c]);
}
}
return TheList;
}
//Clicking bomb bombs and false flag no flag indicating function
//Bomba tıklanınca bayraksız bombaları ve yanlış bayrakları gösteren fonksiyon
private void ShowAllBombs()
{
for (int r = 0; r < RowCount; r++)
{
for (int c = 0; c < ColumnCount; c++)
{ // Original Showing bombs in the game just no flag.
//Orijinal oyunda sadece bayraksız bombalar gösteriliyor.
if (ListOfBoxes[r, c].isBomb && !ListOfBoxes[r, c].isFlagged)
{
ListOfBoxes[r, c].BackgroundImage = Image.FromFile(Application.StartupPath + "\\Bomb.png");
ListOfBoxes[r, c].BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
}
//Bomb put in place non-faulty flags
//Bomba olmayan yere konan hatalı bayraklar
if (!ListOfBoxes[r, c].isBomb && ListOfBoxes[r, c].isFlagged)
{
ListOfBoxes[r, c].BackgroundImage = Image.FromFile(Application.StartupPath + "\\WrongFlag.png");
}
}
}
}
//Function which checks whether the game is finished or not
//Oyunun bitip bitmediğini kontrol eden fonksiyon
private bool isFinished()
{
bool result = true;
for (int r = 0; r < RowCount; r++)
{
for (int c = 0; c < ColumnCount; c++)
{
if (ListOfBoxes[r, c].isBomb && !ListOfBoxes[r, c].isFlagged)
{
result = false;
}
if (!ListOfBoxes[r, c].isBomb && !ListOfBoxes[r, c].isOpen)
{
result = false;
}
}
}
return result;
}
}
}
</box></box></box>
推荐答案
shouldn是否反转了RowCount和ColumnCount?
shouldn't RowCount and ColumnCount be reversed?
if ((r == 0 && c == 0) || (Column + c < 0) || (Row + r < 0) || ((Column + c) >= ColumnCount) || (Row + r >= RowCount))
{
row = 7
column = 15
bomb = 10
给定值给出错误
不适用于每个值
这篇关于项目没有解决错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文