|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace GameFrogs
{
public partial class Frogs : Form
{
string goal = "RRR LLL";
public Frogs()
{
InitializeComponent();
}
private void aTable1_NextM(int position)
{
if (TheEnd())
MessageBox.Show("Congratulations! You won!",
"The end",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
else
if (NoMovePossible())
{
MessageBox.Show("No more moves are possible\n",
"The end",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
//reset game
aTable1.ResetSituation();
}
}
private bool TheEnd()
{
return (aTable1.Situation.ToString() == goal);
}
private bool NoMovePossible()
{
for (int i = 0; i < 6; i++)
{
if (aTable1.Situation[i] == 'L' && aTable1.Situation[i + 1] == ' ')
return false;
if (i < 5)
{
if (aTable1.Situation[i] == 'L' & aTable1.Situation[i + 1] == 'R' &
aTable1.Situation[i + 2] == ' ')
return false;
}
}
for (int i = 6; i > 0; i--)
{
if (aTable1.Situation[i] == 'R' && aTable1.Situation[i - 1] == ' ')
return false;
if (i > 1)
{
if (aTable1.Situation[i] == 'R' & aTable1.Situation[i - 1] == 'L' &
aTable1.Situation[i - 2] == ' ')
return false;
}
}
return true;
}
private void btnReset_Click(object sender, EventArgs e)
{
aTable1.ResetSituation();
}
private void btnSolution_Click(object sender, EventArgs e)
{
Solutions a = new Solutions();
a.Show(this);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have a degree in mathematics, but I've worked as a programmer and now I teach programming in high school in Slovenia.