Games that I've modded or created levels: Titan Quest, The Elder Scrolls IV:Oblivion, The Elder Scrolls V:Skyrim, Tony hawk series, C&D Generals, C&D Generals:Zero hour, Battle For Middle Earth I, Battle For Middle Earth II series Worms:Mayhem, Worms:Armageddon, Warcraft 3 series, Fallout 3 series, Medieval Lords, Crysis, Age Of Empires III series Trackmania Forever, Factorio Experience with Engines : Cry Engine , Unity , Game Maker Studio , Experience with Tools : Blender , Photoshop , Basic Video Editing

  • View media
  • View media
  • View media
  • View media
  • View media
  • View media
RSS feed My Blogs

I've created a minesweeper game in C for a school project of mine and I decided to upload it here.Of course it needs to be compiled first since below there's only code.

#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>
#include <math.h>
#include <time.h>

#define dimensions_small_table 15
int tile_choiceX,tile_choiceY,gbl_current_round=-1,gbl_mines=-1,tile_revealed_small_table[dimensions_small_table][dimensions_small_table],tile_checkZeros_small_table[dimensions_small_table][dimensions_small_table]; //global variables for small table
char gbl_Small_table[dimensions_small_table][dimensions_small_table],gbl_gameEnd='A';

int main()
   {
	int gotostart;
    char menu01sel,choice01;
    printf("Welcome to Minesweeper Game!\n");
    do
      {
	   gotostart=0;
       printf("Press 1 to start playing!\n");
       printf("Press 2 for information\n");
       printf("Press 3 for legend\n");
       printf("Press 4 to exit\n");
       do
       { menu01sel=getch(); } 
       while (menu01sel!='1' &amp;&amp; menu01sel!='2' &amp;&amp; menu01sel!='3' &amp;&amp; menu01sel!='4');
       switch(menu01sel)
       {
        case '1':
	       SmallTableGame();
           break;
        case '2':
           HelpFunction(); 
           gotostart=1; 
           break;
        case '3':
           printf("\nLEGEND: *=tile not revealed,E=tile empty,B=tile has bomb\nNumber(1,...,8)=the number is equal to the amount of bombs at the nearby tiles\n\n");
           gotostart=1;
           break;
        default:
           return ProgramEnd();
       }
       if (gotostart!=1)
          {
           if (gbl_gameEnd=='L')
             {
              printf("\n\nYou found a mine!I am sorry but you lost!Do you want to try again?(Y=Yes,N=No)\n");
              do 
               { choice01=getch(); }
              while (choice01!='N' &amp;&amp; choice01!='n' &amp;&amp; choice01!='Y' &amp;&amp; choice01!='y');
             }
           else if (gbl_gameEnd=='W')
             {
              printf("\n\n\nCongratulations!You have won the game!Want to play again?(Y=Yes,N=No)\n");
              do 
               { choice01=getch(); }
              while (choice01!='N' &amp;&amp; choice01!='n' &amp;&amp; choice01!='Y' &amp;&amp; choice01!='y');
             }
           if (choice01=='Y' || choice01=='y')
              gotostart=1;
          }
      } while (gotostart==1);
    return ProgramEnd();
   }




/*==================================This is the function used for the small table game==============================*/
int SmallTableGame()  //this table contains 225 tiles
   {                                     
    //tile_choiceX and tile_choiceY have real number values --should be changed to use in arrays (real value-1)
    int i,j,rand01,rand02,TotalTilesReveal,tilecounted[dimensions_small_table][dimensions_small_table],gotocoordinates;
    //start up things below
    gbl_gameEnd='A';//the value A means nothing.It could be anything apart from W or L
    gbl_current_round=0;
    TotalTilesReveal=0;
    for (i=0;i<dimensions_small_table;i++)  
       {
        for (j=0;j<dimensions_small_table;j++)
           {
            gbl_Small_table[i][j]=0;
            tile_revealed_small_table[i][j]=0;
            tile_checkZeros_small_table[i][j]=0;
            tilecounted[i][j]=0;
           }
       }  
    /*---------------------------------------------*/
    do
      {
       printf("Enter the amount of mines you want on your minefield(Max mines %.lf):",pow(dimensions_small_table,2)-1);
       scanf("%d",&amp;gbl_mines);
      } while (gbl_mines>=pow(dimensions_small_table,2) || gbl_mines<=0);
    /*------------------*/
    //this part of script will generate the minefield//
    srand(time(0));//this line will make sure each time your run the program the first mine doesn't appear at the same place
    for (i=0;i<gbl_mines;i++)
        {
         do
           {
            rand01=rand()%dimensions_small_table;
            rand02=rand()%dimensions_small_table;
           } while(gbl_Small_table[rand01][rand02]=='B');
         gbl_Small_table[rand01][rand02]='B';
         srand(time(0));//this line is very important DO NOT ERASE!Makes the minefield random
        }
    /*-------------------------------------------------*/
    printf("\nGame has started!\n=====================\n");
    do
     {
      putchar('\n');
      if (gbl_current_round!=0)
          {
           if(gbl_Small_table[tile_choiceX-1][tile_choiceY-1]=='B')
              gbl_gameEnd='L';
           if (gbl_gameEnd!='L' &amp;&amp; gbl_gameEnd!='W' &amp;&amp; gbl_Small_table[tile_choiceX-1][tile_choiceY-1]!='B')
              NearbyMineCheck(tile_choiceX,tile_choiceY);
           for (i=0;i<dimensions_small_table;i++)  
               {
                for (j=0;j<dimensions_small_table;j++)
                    {
                     if (tile_revealed_small_table[i][j]==1 &amp;&amp; tilecounted[i][j]==0 &amp;&amp; gbl_Small_table[i][j]!='B')
                         {
                          tilecounted[i][j]=1;
                          TotalTilesReveal++;
                         }
                    }
               }
           if ((TotalTilesReveal+gbl_mines)==pow(dimensions_small_table,2))
               gbl_gameEnd='W';
          }
      gbl_current_round++;
      printf("   ");
      for (i=0;i<dimensions_small_table;i++)
          {
           if (i<9)
              printf(" 0%d",i+1);
           else
              printf(" %d",i+1);
          }
      putchar('\n');
      printf("   ");
      for (i=0;i<dimensions_small_table*3;i++)
          putchar('-');
      for (i=0;i<dimensions_small_table;i++)
         {
          putchar('\n');
          if (i<9)
             printf("0%d| ",i+1);
          else
             printf("%d| ",i+1);
          for (j=0;j<dimensions_small_table;j++)
              {
               if (gbl_gameEnd=='L')
                  {
                   if(gbl_Small_table[i][j]=='B' || tile_revealed_small_table[i][j]==1)
                       printf("%c  ",gbl_Small_table[i][j]);
                   else printf("*  ");
                  }
               else
                  {
                   if (tile_revealed_small_table[i][j]==0)
                       printf("*  ");
                   else 
                      printf("%c  ",gbl_Small_table[i][j]);
                  }
              }
         }
      if (gbl_gameEnd!='L' &amp;&amp; gbl_gameEnd!='W')
         {
          do
            {
	         gotocoordinates=0;
             printf("\n\nEnter the coordinates of the tile you want to reveal.");
             printf("\nX coordinate(row): ");
             tile_choiceX=ReadCoordinates();
             printf("\nY coordinate(column): ");
	         tile_choiceY=ReadCoordinates();
             if (tile_revealed_small_table[tile_choiceX-1][tile_choiceY-1]==1)
                 {
                  printf("\nThe tile at %d,%d has already been revealed.Choose another.\n",tile_choiceX,tile_choiceY);
                  gotocoordinates=1;
                 }
            } while (gotocoordinates==1);
         }
     } while (gbl_gameEnd!='L' &amp;&amp; gbl_gameEnd!='W');  //gbl_gameEnd will take the value L when the game is lost or W if it is won
    return 0;
   }
	
/*--------------------IMPORTANT FUNCTIONS BELOW-------------------------*/

//This function will check for nearby mines of the tile that was chosen//
NearbyMineCheck(int tempX,int tempY)
  {
   int i,j,tile_nearMinesCount,gotostart;
   do 
      {
	   gotostart=0;
       tile_nearMinesCount=NearbyMineCheck2(tempX,tempY);   
       gbl_Small_table[tempX-1][tempY-1]=tile_nearMinesCount+48; //48='0'	
       tile_revealed_small_table[tempX-1][tempY-1]=1;
       tile_checkZeros_small_table[tempX-1][tempY-1]=1;
       if (tile_nearMinesCount==0) 
          {
           if (tempY>1)
              NearbyMineCheck2(tempX,tempY-1);//left
           if (tempY<dimensions_small_table)
              NearbyMineCheck2(tempX,tempY+1);//right
           if (tempX>1)
              NearbyMineCheck2(tempX-1,tempY);//up
           if (tempX<dimensions_small_table)
              NearbyMineCheck2(tempX+1,tempY);//down
           if (tempX>1 &amp;&amp; tempY>1)
              NearbyMineCheck2(tempX-1,tempY-1);//up-left
           if (tempX>1 &amp;&amp; tempY<dimensions_small_table)
              NearbyMineCheck2(tempX-1,tempY+1);//up-right
           if (tempX<dimensions_small_table &amp;&amp; tempY>1)
              NearbyMineCheck2(tempX+1,tempY-1);//down-left
           if (tempX<dimensions_small_table &amp;&amp; tempY<dimensions_small_table)
              NearbyMineCheck2(tempX+1,tempY+1);//down-right
           for (i=0;i<dimensions_small_table;i++)  
              {
               for (j=0;j<dimensions_small_table;j++)
                  {
                   if (gbl_Small_table[i][j]=='0' &amp;&amp; tile_checkZeros_small_table[i][j]==0 &amp;&amp; tile_revealed_small_table[i][j]==1)
                      {
                       tempX=i+1;
                       tempY=j+1;
                       tile_checkZeros_small_table[i][j]=1;         
                       gotostart=1;
                      }
                   if (gotostart==1)
                       break;
                  }
               if (gotostart==1)
                  break;
              }
          }
      } while (gotostart==1);
  }


int NearbyMineCheck2(int tempX,int tempY) //This Function is part of NearbyMineCheck Function
   {
    int tile_nearMinesCount=0;
    /*This function will reveal the nearby tiles*/
    if (tempY>1  &amp;&amp; gbl_Small_table[tempX-1][tempY-2]=='B')
        {tile_nearMinesCount++;}//left
    if (tempY<dimensions_small_table &amp;&amp; gbl_Small_table[tempX-1][tempY]=='B')
        {tile_nearMinesCount++;}//right
    if (tempX>1 &amp;&amp; gbl_Small_table[tempX-2][tempY-1]=='B')
        {tile_nearMinesCount++;}//up
    if (tempX<dimensions_small_table &amp;&amp; gbl_Small_table[tempX][tempY-1]=='B')
        {tile_nearMinesCount++;}//down
    if (tempX>1 &amp;&amp; tempY>1)
       {
        if (gbl_Small_table[tempX-2][tempY-2]=='B')
            {tile_nearMinesCount++;}//up-left
       }
    if (tempX>1 &amp;&amp; tempY<dimensions_small_table)
       {
        if (gbl_Small_table[tempX-2][tempY]=='B')
            {tile_nearMinesCount++;}//up-right
       }
    if (tempX<dimensions_small_table &amp;&amp; tempY>1)
       {
        if (gbl_Small_table[tempX][tempY-2]=='B')
            {tile_nearMinesCount++;}//down-left 
       }
    if (tempX<dimensions_small_table &amp;&amp; tempY<dimensions_small_table)
       {
        if (gbl_Small_table[tempX][tempY]=='B')
           {tile_nearMinesCount++;}//down-right
       }     
    gbl_Small_table[tempX-1][tempY-1]=tile_nearMinesCount+48; //48='0'	
    tile_revealed_small_table[tempX-1][tempY-1]=1; 
    return tile_nearMinesCount;
   }

int ReadCoordinates()
    {
     int tile_choice,tile_choiceValid=-1;         
     do
       {
        scanf("%d",&amp;tile_choice);
        if (tile_choice>=1 &amp;&amp; tile_choice<=dimensions_small_table)
            tile_choiceValid=1; //Y is column
        else
           {
            tile_choiceValid=0;
            printf("\nY coordinate not within bounds.Must be within 1 and %d\n",dimensions_small_table);
           }
       } while (tile_choiceValid==0);
       return tile_choice;
    }

HelpFunction(void)
   //This function is called when the user needs help
   {
    printf("\nThe player is initially presented with a grid of undifferentiated squares.Some randomly selected squares, unknown to the player, are designated to contain mines.The game is played by revealing squares of the grid.If a square containing a mine is revealed, the player loses the game. Otherwise, a digit is revealed in the square, indicating the number of adjacent squares (typically, out of the possible eight) that contain mines.\n\n");
   }

int ProgramEnd(void)
   {
	printf("\n=================================\nMade by pkyrkos7 aka Panos\n=================================\n");
    system("pause");
    return 0;
   }

Start a group Groups
2D Games

2D Games

293 members Fans & Clans

They are places where "Z axis" does not exist, only YX reign, the word is unknown 3D, games are simple but should be played, many of them will make us...

Age of Fans

Age of Fans

581 members Fans & Clans

For all fans of Age of Empires & Age of Mythology!

Aliens vs Predator Source

Aliens vs Predator Source

277 members Fans & Clans

Aliens vs Predator Source for all the avp games and movies. Your AvP Source of the latest AvP news, videos, images,and more. Join the AvP Source.

Biohazard Fans

Biohazard Fans

253 members Fans & Clans

All fans of the Resident Evil games, join here and share knowledge about the RE series and have fun!

Day Z Survivors

Day Z Survivors

93 members Fans & Clans

The purpose of this group is to schedule DayZ gameplay events, which will make it much easier to get ahead in DayZ. Eventually, through teamwork and determination...

Dead Frontier

Dead Frontier

3 members Fans & Clans

this group was made for those who play Dead Frontier.

Fans of Silent Hill

Fans of Silent Hill

522 members Hobbies & Interests

This group is for the fans of silent hill games to stay up to date with all things Silent Hill.

Greece

Greece

95 members Geographic

This is The Greek Group In ModDb. A small taste of home for every greek in the huge website of moddb. all greek friendly and greek members of moddb can...

Post comment Comments  (0 - 10 of 13)
Aphroditeishot
Aphroditeishot

Hey! Thanks for watching The Isle! It's great to have support!

Reply Good karma Bad karma+1 vote
tiagochefe
tiagochefe

Thanks for tracking our game Ilhado :D

Reply Good karma Bad karma+1 vote
drunkonnectar
drunkonnectar

Hey pkyrkos7, thanks for being a watcher on "Drunk On Nectar", this kind of support is always a source of motivation! If possible do tell other folks about the game as well, in any way you see fit, that would be of immense help too!

PS: That's a neat C project you had going in your 2013 minesweeper blog btw :) I remember doing C projects like that myself in my high-school days more than a decade ago. Hope you're still keeping at it!

Reply Good karma Bad karma+1 vote
pkyrkos7 Creator
pkyrkos7

Hey just saw your message apparently email notifications don't come when somebody posts at your profile :/

Your game looks very nice and quite unique I must say , it's always nice to see something new!

The C code was with only a couple of months experience when I was learning C at my uni so now coding is much better ;)

Reply Good karma+1 vote
aldodf
aldodf

Hello, my name is aldodf and am a big fan of Gabrilduro in particular the mod old America in 1860, I and other fans, as a gift for the 2014 Gabrilduro we want to increase the vows, because I do not know if you've seen, but it is the victim of some idiots who put 1 for no reason, you andremme to put 10 as voting, sarabbe a great gift for a great modder who never asks for anything and is always friendly and polite!

Thanks in advance: D

Reply Good karma Bad karma+1 vote
CyberPhoenixInt
CyberPhoenixInt

Thanks for watching Raw F.O.X!

Reply Good karma Bad karma+2 votes
zuthen
zuthen

sorry i never got back to you on your friend request. didnt even realize i had gotten it, i dont check this sites mail as much as i should.

Reply Good karma Bad karma+2 votes
iQew
iQew

Hey, thanks for tracking Mindworld on indieDB, we really appreciate your interest :)

Reply Good karma Bad karma+2 votes
pkyrkos7 Creator
pkyrkos7

It seems really interesting!

Reply Good karma+2 votes
iQew
iQew

Thanks!

Reply Good karma Bad karma+2 votes
Post a comment

You are not logged in, your comment will be anonymous unless you join the community. Or sign in with your social account:

Level
26%
AddonDB
20
Avatar
Avatar
Last Online
Country
Greece Greece
Gender
Male
Friends
Become friends
Member watch
Start tracking
Mod DB
Statistics
Rank
753 of 556,295
Visitors
9,638 (10 today)
Time Online
3 days
Activity Points
2,326
Watchers
8 members
Comments
499
Site visits
11,773
Contact
Contact
Send Message
Homepage
Moddb.com
Friends
Valyndimir Online
ElfFriend
ElfFriend Online
ElijahHouck
ElijahHouck Online
French_Fry
French_Fry Online
xristos10
xristos10 Online
Orchamedes
Orchamedes Online
Enpremi
Enpremi Online
Eorl_256
Eorl_256 Online
alcapone_256
alcapone_256 Online
KOYK_GR
KOYK_GR Online