Ogólnie to robię prosty program na zajęcia. Program ten wyświetla panel po którym w dół spadają pojedyncze klocki i można je przesuwać w prawo w lewo, jak klocków będzie za dużo to krzyczy "game over" i czyści planszę. Oczywiscie wykładowca dał nam kawałek kodu i trzeba wszystko dorobić. parę punktów sam zrobiłem ale nie wiem jak sie zabrać za takie trzy:
1 pkt) Zmodyfikuj program w taki sposób, aby kafelek nigdy nie pojawiał się przy krawędzi planszy,
a w pozostałych kolumnach z takim samym prawdopodobieństwem.
2 pkt) Dodaj obsługę spadania kafelek (po naciśnięciu odpowiedniego przycisku kafelek z minimalnym opóźnieniem (szybka animacja) spada na sam dół - nie można nim już sterować
3 pkt) Jeśli 4 jednokolorowe kafelki utworzą kwadrat, to wszystkie one znikają a
te kafelki, które były położone nad nimi spadają na dół.
Bardzo proszę o pomoc, nie muszą to być gotowe kody a jakieś wskazówki.
Program:
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 Kolo_teris
{
public partial class Form1 : Form
{
public bool appRunning = false;
public Tile activeTile = null;
Random rnd = new Random();
//Tablica pól
public bool[,] tilesMatrix;
public Form1()
{
InitializeComponent();
tilesMatrix = new bool[
arenaPanel.Width / Tile.TileWidth,
arenaPanel.Height / Tile.TileHeight];
}
private void startButton_Click(object sender, EventArgs e)
{
if (appRunning)
{
appRunning = false;
startButton.Text = "START";
}
else
{
appRunning = true;
startButton.Text = "STOP";
timer1.Enabled = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (appRunning)
{
if (activeTile == null) //create a new tile to fall down
{
// Losowanie pozycji
int pos = rnd.Next(tilesMatrix.GetLength(0));
if (tilesMatrix[pos, 0])
{ // end of game
appRunning = false;
MessageBox.Show("Game Over");
arenaPanel.Controls.Clear();
for (int i = 0; i < tilesMatrix.GetLength(0); ++i)
for (int j = 0; j < tilesMatrix.GetLength(1); ++j)
{
tilesMatrix[i, j] = false;
}
startButton.Text = "START";
}
else
{
tilesMatrix[pos, 0] = true;
activeTile = new Tile();
arenaPanel.Controls.Add(activeTile);
//activeTile.Size = new System.Drawing.Size(Tile.Width, Tile.Height);
activeTile.Location = new Point(pos * Tile.TileWidth, 0);
activeTile.UseVisualStyleBackColor = true;
activeTile.Enabled = true;
int kolor = rnd.Next(3);
switch (kolor)
{
case 0: activeTile.BackColor = Color.Yellow;
break;
case 1: activeTile.BackColor = Color.Red;
break;
case 2: activeTile.BackColor = Color.Green;
break;
}
}
}
else
{ //continue falling down
if (activeTile.Location.Y + 2 * Tile.TileHeight >= arenaPanel.Height)
{ // the tile is at the bottom
activeTile = null;
}
else
{
int posx = activeTile.Location.X / activeTile.Width;
int posy = activeTile.Location.Y / activeTile.Height;
if (!tilesMatrix[posx, posy + 1])
{
tilesMatrix[posx, posy + 1] = true;
activeTile.Location = new Point(posx * Tile.TileWidth, (posy + 1) * Tile.TileHeight);
tilesMatrix[posx, posy] = false;
}
else
{ //tile blocked
activeTile = null;
}
}
}
}
}
private void downButton_Click(object sender, EventArgs e)
{
}
private void leftButton_Click(object sender, EventArgs e)
{
{
int posx = activeTile.Location.X / activeTile.Width;
int posy = activeTile.Location.Y / activeTile.Height;
if (!tilesMatrix[posx - 1, posy])
{
tilesMatrix[posx - 1, posy] = true;
activeTile.Location = new Point((posx - 1) * Tile.TileWidth, (posy) * Tile.TileHeight);
tilesMatrix[posx, posy] = false;
}
else
{ //tile blocked
activeTile = null;
}
}
}
private void rightButton_Click(object sender, EventArgs e)
{
{
int posx = activeTile.Location.X / activeTile.Width;
int posy = activeTile.Location.Y / activeTile.Height;
if (!tilesMatrix[posx + 1, posy])
{
tilesMatrix[posx + 1, posy] = true;
activeTile.Location = new Point((posx + 1) * Tile.TileWidth, (posy) * Tile.TileHeight);
tilesMatrix[posx, posy] = false;
}
else
{ //tile blocked
activeTile = null;
}
}
}
}
}