Mission Objective To Aim For

Winning & Losing

Now that we have all of the components required for an almost complete game of TK-MineSweeper, it's time to introduce some variables which define the state of the game in terms of success and failure. We lose in TK-MineSweeper by stepping on mines. We will be able to win (when we have implemented the ability to defuse mines) in TK-MineSweeper by successfully locating all of the mines in the mineField without having trod on any of them.
Why not, then, define a state lost, which is 0 when lost is false, and 1 when lost is true ?
In a similar fashion, we define a variable, won to be 0 when we have not won, and 1 when we have won.
We may include them into the TK-MineSweeper proceedings as follows :

  won is 0;
  lost is 0;
These variables, however, have no meaning unless we give them some meaning. In the play function described in the previous section, we have a condition whereby we lose the game (we 'try' a cell which contains a mine). We currently receive a message saying something like : "BANG ! Oops, mine here"
With our new conditions, however, we can add the modification of lost to this part of the script, making lost equal 1.
The following reproduction of the play function includes the modification of lost, and can be copy & pasted at will :
  func play : currentPos {
    if ((pos>0)&&(pos<=nCells)) {
      if (status[pos]==1) {
        status[pos] = 0;
        if (mines[pos]==1) {
          writeln("BANG ! Mine Here - Game Over");
          lost is 1;
        } else {
          if (values[pos]!="0") {
          } else {
            if ((((pos-1)%4)!=0)&&(pos>xDim)&&(mines[pos-xDim-1]!=1)) {
              todo("pos is "//str(pos-xDim-1)//";");
            if ((((pos-1)%4)!=0)&&((pos-1)>0)&&(mines[pos-1]!=1)) {
              todo("pos is "//str(pos-1)//";");
            if ((((pos-1)%4)!=0)&&(pos<=((yDim-1)*xDim))&&(mines[pos+xDim-1]!=1)) {
              todo("pos is "//str(pos+xDim-1)//";");
            if ((pos<=((yDim-1)*xDim))&&(mines[pos+xDim]!=1)) {
              todo("pos is "//str(pos+xDim)//";");
            if xDim)&&(mines[pos-xDim]!=1)) {
              todo("pos is "//str(pos-xDim)//";");
      } else {
        writeln(pos, " is already uncovered - choose another cell (1-16)");
So, we now have some definitions which relay the state of the player's success. However, whilst we have these variables, there is nothing to respond to them.

Game Results

However, we can soon remedy this by defining a function which is a triggered action in response to modifications to either of the game success variables : won or lost.
We can have a simple routine, which is triggered by modifications to won or lost. Depending upon the values of these success variables, this routine can output either a success message, or a failure message.
A typical representation of such a function appears below :

  func outResult : won, lost {
    if ((won==1)(lost==1)) {
      if (won==1) {
        writeln("\n\nYou've Successfully Defused The Mine Field !!\n\n");
        writeln("\t\tWell Done\n\n");
      if (lost==1) {
        writeln("Doh! You're Now In Lots Of Ickle Bits\n\n");
Selecting a cell containing a mine now results in a little message informing you that you have lost the game. At the current time, there is still no way of winning (not fair !) But, a redress is about to appear. The next section of this TK-MineSweeper demonstration looks at some more complex, but still pretty essential aspects, or the mineSweeper game. Namely, we are looking into how the player can select suspected mine cells, and try to win the game.

Move to the tenth TK-MineSweeper page...

Updated Wednesday, January 6, 1999