2 Replies - 500 Views - Last Post: 28 July 2013 - 11:03 AM Rate Topic: -----

#1 claudioadaosouza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-July 13

Python... Minesweeper/ Number of ramdomic bombs

Posted 04 July 2013 - 03:45 PM

import random

# Matriz que será exibida

campo=[['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],

       ['X','X','X','X','X','X','X','X','X'],]

print " Bem-vindo ao jogo de campo minado, tente encontrar todos os campos onde não há mina nesta matriz 9x9 com 10 bombas. Boa sorte!"

for i in range (9):

    print campo[i]

#Matriz aonde serão colocadas as minas

mina=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],

      [0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],

      [0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],

      [0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],

      [0,0,0,0,0,0,0,0,0],]

for i in range (9):

    j=0

    var=random.randint (0, 8)

    mina[i][j+var]='*'

for i in range (9):

    for j in range (9):

        if i==0 and j==0:

            if mina[i][j]=='*':

                mina[i][j+1]=mina[i][j+1]+1

                if mina[i+1][j]!='*':

                    mina[i+1][j]=mine[i+1][j]+1

                if mina[i+1][j+1]!='*':

                    mina[i+1][j+1]=mina[i+1][j+1]+1

        elif i==0 and j>0 and j<8:

            if mina [i][j]=='*':

                mina[i][j+1]=mina[i][j+1]+1

                mina[i][j-1]=mina[i][j-1]+1

                if mina[i+1][j-1]!='*':

                    mina[i+1][j-1]=mina[i+1][j-1]+1

                if mina[i+1][j]!='*':

                    mina[i+1][j]=mina[i+1][j]+1

                if mina[i+1][j+1]!='*':

                    mina[i+1][j+1]=mina[i+1][j+1]+1

        elif i==0 and j==8:

            if mina[i][j]=='*':

                mina[i][j-1]=mina[i][j-1]+1

                if mina[i+1][j-1]!='*':

                    mina[i+1][j-1]=mina[i+1][j-1]+1

                if mina[i+1][j]!='*':

                    mina[i+1][j]=mina[i+1][j]+1

        elif i>0 and i<8 and j==0:

            if mina[i][j]=='*':

                mina[i][j+1]=mina[i][j+1]+1

                if mine[i-1][j]!='*':

                    mina[i-1][j]=mina[i-1][j]+1

                if mina[i-1][j+1]!='*':

                    mina[i-1][j+1]=mina[i-1][j+1]+1

                if mina[i+1][j]!='*':

                    mina[i+1][j]=mina[i+1][j]+1

                if mina[i+1][j+1]!='*':

                    mina[i+1][j+1]=mina[i+1][j+1]+1

        elif i>0 and i<8 and j>0 and j<8:

            if mina[i][j]=='*':

                mina[i][j-1]=mina[i][j-1]+1

                mina[i][j+1]=mina[i][j+1]+1

                if mina[i-1][j-1]!=0:

                    mina[i-1][j-1]=mina[i-1][j-1]+1

                if mina[i-1][j]!='*':

                    mina[i-1][j]=mina[i-1][j]+1

                if mina[i-1][j+1]!='*':

                    mina[i-1][j+1]=mina[i-1][j+1]+1

                if mina[i+1][j-1]!='*':

                    mina[i+1][j-1]=mina[i+1][j-1]+1

                if mina[i+1][j]!='*':

                    mina[i+1][j]=mina[i+1][j]+1

                if mina[i+1][j+1]!='*':

                    mina[i+1][j+1]=mina[i+1][j+1]+1

        elif i>0 and i<8 and j==8:

            if mina[i][j]=='*':

                mina[i][j-1]=mina[i][j-1]+1

                if mina[i-1][j]!='*':

                    mina[i-1][j]=mina[i-1][j]+1

                if mina[i-1][j-1]!='*':

                    mina[i-1][j-1]=mina[i-1][j-1]+1

                if mina[i+1][j]!='*':

                    mina[i+1][j]=mina[i+1][j]+1

                if mina[i+1][j-1]!='*':

                    mina[i+1][j-1]=mina[i+1][j-1]+1

        elif i==8 and j==0:

            if mina[i][j]=='*':

                mina[i][j+1]=mina[i][j+1]+1

                if mina[i-1][j]!='*':

                    mina[i-1][j]=mina[i-1][j]+1

                if mina[i-1][j+1]!='*':

                    mina[i-1][j+1]=mina[i-1][j+1]+1

        elif i==8 and j>0 and j<8:

            if mina [i][j]=='*':

                mina[i][j+1]=mina[i][j+1]+1

                mina[i][j-1]=mina[i][j-1]+1

                if mina[i-1][j-1]!='*':

                    mina[i-1][j-1]=mina[i-1][j-1]+1

                if mina[i-1][j]!='*':

                    mina[i-1][j]=mina[i-1][j]+1

                if mina[i-1][j+1]!='*':

                    mina[i-1][j+1]=mina[i-1][j+1]+1

        elif i==8 and j==8:

            if mina[i][j]=='*':

                mina[i][j-1]=mina[i][j-1]+1

                if mina[i-1][j-1]!='*':

                    mina[i-1][j-1]=mina[i-1][j-1]+1

                if mina[i-1][j]!='*':

                    mina[i-1][j]=mina[i-1][j]+1

         

while True:

    print "Digite as coordenadas do campo."

    i=input ("número da linha:")

    j=input ("número da coluna:")

    if mina[i][j]!='*':

        print "Parabéns, campo sem mina."

        campo[i][j]=mina[i][j]

        for k in range (9):

            print campo[k]

    if mine[i][j]=='*':

        print "Bomba, você perdeu! Tente novamente."

        for z in range (9):

            print mina[z]



How can this minesweeper have 10 bombs instead of 9? Please help me.

Is This A Good Question/Topic? 0
  • +

Replies To: Python... Minesweeper/ Number of ramdomic bombs

#2 b mitsai  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 59
  • Joined: 09-November 12

Re: Python... Minesweeper/ Number of ramdomic bombs

Posted 07 July 2013 - 09:05 PM

WAT? first, this community isnt portuguese, so they wont understand some of the code. Second your aren't the owner of that code that's why you don't know.
Was This Post Helpful? 1
  • +
  • -

#3 BlueMelon  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 187
  • Joined: 27-April 10

Re: Python... Minesweeper/ Number of ramdomic bombs

Posted 28 July 2013 - 11:03 AM

Hint:
range(9)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1