177Fermer179
onurLe 08/05/2008 à 03:03
Rintintin, c'est de toi Kirby? Je l'avais testé il y a des années smile Marrant. Voilà un peu de code source à moi: 'Mines sweeper for 2 players on TI !! ' by Onur CELEBI ' compiled with ETP Studio   www.etpstudio.com '  4 Jan 2005 Public TabloMines[16,16] as Integer          'Un tableau 16*16                'Valeurs dans le tableau:   0 = rien                '                                   1 = mine Public TabloView[16,16] as Integer                'valeurs dans le tableau:     0 = rien 1..8 le nombre affiché                '                                   9 = caché                '                                   10 = drapeau1                '                                   11 = drapeau2                '                                   12 = mine                 Public TabloProba[16,16] as Integer Public CameraX as Integer Public CameraY as Integer Public CurPly as Integer          'current player Public GameMode as Integer          ' GameMode                                         ' 0 = 1 player                                         ' 1 = 2 players on-calc                                         ' 2 = 2 players hum. vs calc Public MinesNb as Integer Public MinesNbDisp as Integer Public RectShown as Integer Public BlocToTickX as Integer Public BlocToTickY as Integer Procedure MAIN:      'The startpoint of your program      Local i as Integer      Local j as Integer      Local k as Integer      GrayOn            DrawBitmap intro      Font 0      DarkPlane      Lbl menu_str           If GameMode = 0 Then                Locate 5,94,"                 One player       >>>",4           ElseIf GameMode = 1 Then                Locate 5,94,"<<<    Two players on-calc   >>>",4           Else                Locate 5,94,"<<< Two players hum. vs. calc   ",4                          EndIf           i= GetKey()      If i=338 And GameMode>0 Then           GameMode = GameMode -1      ElseIf i= 344 And GameMode <2 Then           GameMode = GameMode +1      EndIf      If i=264 Then           GrayOff           Return      EndIf      If i<>13 Then           GoTo menu_str      EndIf                  For i=0 To 15           For j=0 To 15                TabloView[i,j] = 9                TabloMines[i,j] = 0           Next      Next      For k=1 To 51           Do                i = Random(16)                j = Random(16)           Loop while TabloMines[i,j]=1           TabloMines[i,j] = 1      Next      MinesNb = 51      MinesNbDisp = MinesNb      CameraX = 0      CameraY = 0            Game      ClearAll      DrawBitmap MadeETP160      Font 1      LightPlane      Locate 55,5,"Made With",4      Locate 30,90,"www.etpstudio.com",4      DarkPlane      Locate 55,5,"Made With",4      Locate 30,90,"www.etpstudio.com",4      Wait 90            WaitKey      GrayOff       Procedure GAME      Local CursorX[2] as Integer      Local CursorY[2] as Integer      Local Score[2] as Integer      Local Ctr as Integer     'the counter for the cursor highlighting      Local EscCtr as Integer     'the counter for the ESC key      Local EntCtr as Integer 'the counter for the ENTER key      Local SndCtr as Integer 'the counter for the 2nd key      Local HLCtr as Integer     'the counter for the 'player' higlighting      Local MsgDispCtr as Integer           Local MsgDisp as String      Local Stop as Integer     'exit the loop if someone wins :)      Local Control as Integer                  ClearAll           LightPlane      For EscCtr=0 To 100           Line 0,EscCtr,160,EscCtr,4      Next      DarkPlane      Line 30,0,30,94,4      Line 29,0,29,94,4            HLCtr = 0      EscCtr = 0      EntCtr = 0      SndCtr = 0      Control = 0          ' AI's control            MsgDispCtr = 9      If GameMode = 0 Then           MsgDisp = "Press 2nd key to put flags.."      Else           MsgDisp = "Try to find every mine..."      EndIf      CurPly = 0      Ctr = 0      Stop = 0      CursorX[0] = 0      CursorY[0] = 0      CursorX[1] = 0      CursorY[1] = 0      Score[0] = 0      Score[1] = 0            DrawALL            DrawScores Score[0],Score[1]            Do           If Ctr = 1 Then                PutTile 8*(CursorX[CurPly]-CameraX)+32,8*(CursorY[CurPly]-CameraY),cursor           ElseIf Ctr = 10 Then                ShowBloc CursorX[CurPly],CursorY[CurPly]           ElseIf Ctr = 20 Then                Ctr = 0                If MsgDispCtr > 1 Then                     If CursorY[CurPly]-CameraY < 8 Then                          If RectShown = 30 Then                               DrawALL                          EndIf                          DrawMessage MsgDisp,88                     Else                          If RectShown = 88 Then                               DrawALL                          EndIf                          DrawMessage MsgDisp,30                     EndIf                     MsgDispCtr = MsgDispCtr -1                ElseIf MsgDispCtr = 1 Then                     DrawALL                     MsgDispCtr = 0                EndIf           EndIf           Ctr = Ctr +1                      ' Putting Flag for solo mode           '----------------------------------------------------           If KEY89_2ND And GameMode = 0 Then                SndCtr = SndCtr +1           Else                SndCtr = 0           EndIf           If SndCtr = 5 Then                SndCtr = 0                PutFlag CursorX[CurPly],CursorY[CurPly]                DrawScores 0,0                If MinesNb = 0 And MinesNbDisp = 0 Then                     Stop = 1                ElseIf MinesNbDisp <= 0 Then                     MsgDispCtr = 9                     MsgDisp = "There are still enabled mines.."                EndIf           EndIf                      ' AI           '------------------------------------------------           If GameMode = 2 And CurPly = 1 Then                If Control = 0 Then                     'think..                     Think                     Control = 99                ElseIf CursorX[1]<BlocToTickX Then                     Control = 2          'right                ElseIf CursorX[1]>BlocToTickX Then                     Control = 1          'left                ElseIf CursorY[1]<BlocToTickY Then                     Control = 4          'down                ElseIf CursorY[1]>BlocToTickY Then                     Control = 3          'up                Else                     Control = 5                EndIf           EndIf                                 ' Cursor move...           '-----------------------------------------------------                If KEY89_LEFT And CursorX[CurPly]>0 And (GameMode < 2 Or CurPly = 0) Or Control=1 Then                     ShowBloc CursorX[CurPly],CursorY[CurPly]                     CursorX[CurPly] = CursorX[CurPly] -1                     PutTile 8*(CursorX[CurPly]-CameraX)+32,8*(CursorY[CurPly]-CameraY),cursor                     Wait 2                EndIf                If KEY89_RIGHT And CursorX[CurPly]<15 And (GameMode < 2 Or CurPly = 0) Or Control=2 Then                     ShowBloc CursorX[CurPly],CursorY[CurPly]                     CursorX[CurPly] = CursorX[CurPly] +1                     PutTile 8*(CursorX[CurPly]-CameraX)+32,8*(CursorY[CurPly]-CameraY),cursor                     Wait 2                EndIf                If KEY89_UP And CursorY[CurPly]>0 And (GameMode < 2 Or CurPly = 0) Or Control=3 Then                     ShowBloc CursorX[CurPly],CursorY[CurPly]                     CursorY[CurPly] = CursorY[CurPly] -1                     If CursorY[CurPly]<CameraY Then                          CameraY = CursorY[CurPly]                          DrawALL                     EndIf                     PutTile 8*(CursorX[CurPly]-CameraX)+32,8*(CursorY[CurPly]-CameraY),cursor                     Wait 2                EndIf                If KEY89_DOWN And CursorY[CurPly]<15 And (GameMode < 2 Or CurPly = 0) Or Control=4 Then                     ShowBloc CursorX[CurPly],CursorY[CurPly]                     CursorY[CurPly] = CursorY[CurPly] +1                     If CursorY[CurPly]-11>CameraY Then                          CameraY = CursorY[CurPly] - 11                          DrawALL                     EndIf                     PutTile 8*(CursorX[CurPly]-CameraX)+32,8*(CursorY[CurPly]-CameraY),cursor                     Wait 2                               EndIf                If KEY89_ENTER And (GameMode < 2 Or CurPly = 0) Or Control=5 Then                     EntCtr = EntCtr +1                EndIf                                If EntCtr=3 And TabloView[CursorX[CurPly],CursorY[CurPly]]=9 Then                     EntCtr = 0                     OpenThisBloc CursorX[CurPly],CursorY[CurPly]                     DrawALL                     If TabloMines[CursorX[CurPly],CursorY[CurPly]]=1 Then                          MineFound                          Control = 0                          If GameMode > 0 Then                               Score[CurPly] = Score[CurPly]+1                               If Score[CurPly] = MinesNb/2+1 Then                                    Stop = 1                               EndIf                          Else                               OpenMines                               Stop = 1                          EndIf                     Else                          If GameMode > 0 Then                               If CurPly = 0 Then                                    CurPly = 1                               Else                                    CurPly = 0                                    Control = 0                               EndIf                          EndIf                          If CursorY[CurPly]<CameraY Then                               CameraY = CursorY[CurPly]                               DrawALL                          EndIf                          If CursorY[CurPly]-11>CameraY Then                               CameraY = CursorY[CurPly] - 11                               DrawALL                          EndIf                                         EndIf                     DrawScores Score[0],Score[1]                ElseIf EntCtr = 3 Then                     EntCtr = 0                EndIf                                            'Player's name highlighting..           '------------------------------------------------           HLCtr = HLCtr +1           If HLCtr = 4 Or HLCtr = 12 Then                If GameMode >0 Then                     If CurPly = 0 Then                          Font 0                          LightPlane                          Locate 0,24,"Player1",2                     ElseIf CurPly = 1 Then                          Font 0                          LightPlane                          Locate 0,64,"Player2",2                     EndIf                Else                     Font 0                     LightPlane                     Locate 0,5,"Mines:",2                EndIf           ElseIf HLCtr = 8 Or HLCtr = 16 Then                If GameMode > 0 Then                     If CurPly = 0 Then                          Font 0                          DarkPlane                          Locate 0,24,"Player1",2                     ElseIf CurPly = 1 Then                          Font 0                          DarkPlane                          Locate 0,64,"Player2",2                     EndIf                Else                     Font 0                     DarkPlane                     Locate 0,5,"Mines:",2                EndIf           EndIf           If HLCtr = 16 Then                HLCtr = 0           EndIf                      Wait 1           If KEY89_ESC Then                escctr = escctr +1           Else                escctr = 0           EndIf      Loop while escctr < 4 And Stop = 0            If Stop = 1 Then           'Someones won!           Font 2           PutTile 20,40,bord1           For escctr = 1 To 6                PutTile 20+16*escctr,40,bord2           Next           PutTile 20+16*escctr,40,bord3           If GameMode > 0 Then                If curply = 0 Then                     LightPlane                     Locate 23,42,"PLAYER 1 WINS!!",4                     DarkPlane                     Locate 23,42,"PLAYER 1 WINS!!",4                Else                     LightPlane                     Locate 23,42,"PLAYER 2 WINS!!",4                     DarkPlane                     Locate 23,42,"PLAYER 2 WINS!!",4                EndIf           Else                If MinesNb > 0 Then                     LightPlane                     Locate 47,42,"BOUM!!",4                     DarkPlane                     Locate 47,42,"BOUM!!",4                     MineFound                Else                     LightPlane                     Locate 22,42,"CONGRATULATIONS",4                     DarkPlane                     Locate 22,42,"CONGRATULATIONS",4                     MineFound                EndIf           EndIf           WaitKey           WaitKey      EndIf       Procedure MineFound()      ReverseScreenLight      Wait 3      ReverseScreenLight      Wait 3      ReverseScreenDark      Wait 3      ReverseScreenLight      Wait 3      ReverseScreenDark      Wait 3      ReverseScreenLight      Wait 3                 Procedure OpenMines      Local i as Integer      Local j as Integer      For i=0 To 15           For j=0 To 15                If TabloMines[i,j]=1 And TabloView[i,j]=9 Then                     TabloView[i,j]=12                EndIf           Next      Next      DrawALL       Procedure PutFlag(col as Integer,row as Integer)      If TabloView[col,row]=9 Then           TabloView[col,row] = 10           MinesNbDisp = MinesNbDisp -1           If TabloMines[col,row]=1 Then                MinesNb = MinesNb -1           EndIf      ElseIf TabloView[col,row]=10 Then           TabloView[col,row] = 9           MinesNbDisp = MinesNbDisp + 1           If TabloMines[col,row] = 1 Then                MinesNb = MinesNb +1           EndIf      EndIf            ShowBloc col,row       Procedure OpenThisBloc(col as Integer,row as Integer)      Local i as Integer      If col>=0 And col=<15 And row>=0 And row=<15 And TabloView[col,row]=9 Then           i = NghMineNumber(col,row)           TabloView[col,row] = i           If i=0 Then                OpenThisBloc col-1,row-1                OpenThisBloc col,row-1                OpenThisBloc col+1,row-1                OpenThisBloc col-1,row                OpenThisBloc col+1,row                OpenThisBloc col-1,row+1                OpenThisBloc col,row+1                OpenThisBloc col+1,row+1           EndIf      EndIf ' c'est la fonction qui donne le nombre de mines voisines ' retourne 10 si ca correspond à une mine Function NghMineNumber(col as Integer,row as Integer) as Integer      Local MinNb as Integer      MinNb = 0      If TabloMines[col,row]=0 Then           If col>0 And row>0 And TabloMines[col-1,row-1]= 1 Then                MinNb = MinNb +1           EndIf           If row>0 And TabloMines[col,row-1]= 1 Then                MinNb = MinNb +1           EndIf           If col<15 And row>0 And TabloMines[col+1,row-1]= 1 Then                MinNb = MinNb +1           EndIf           If col>0 And TabloMines[col-1,row]= 1 Then                MinNb = MinNb +1           EndIf           If col<15 And TabloMines[col+1,row]= 1 Then                MinNb = MinNb +1           EndIf           If col>0 And row<15 And TabloMines[col-1,row+1]= 1 Then                MinNb = MinNb +1           EndIf           If row<15 And TabloMines[col,row+1]= 1 Then                MinNb = MinNb +1           EndIf           If col<15 And row<15 And TabloMines[col+1,row+1]= 1 Then                MinNb = MinNb +1           EndIf           Return MinNb      Else           Return 10+CurPly      EndIf Procedure DrawScores(scoreA as Integer,scoreB as Integer)      'SCores      If GameMode = 0 Then           DrawMineNb           Return      EndIf      Font 2      DarkPlane      PutTile 2,30,scoreBack      Locate 4,35,scoreA,4      PutTile 2,70,scoreBack      Locate 4,75,scoreB,4      Font 0      ' Player text      Locate 0,24,"Player1",4      Locate 0,64,"Player2",4      LightPlane      Locate 0,24,"Player1",1      Locate 0,64,"Player2",1 Procedure DrawMineNb()      Font 0      PutTile 0,11,scoreBack      LightPlane      Locate 0,5,"Mines:",1      DarkPlane      Locate 0,5,"Mines:",4      Font 2      Locate 4,16,MinesNbDisp,4             Procedure DrawAll()      Local i as Integer      Local j as Integer      RectShown = 0      If CameraY = 4 Then           For i=96 To 100                LightPlane                Line 0,i,160,i,4                DarkPlane                Line 0,i,160,i,0           Next i      EndIf            For i=0 To 15           For j=0 To 15                ShowBloc i,j           Next      Next Procedure DrawMessage(msg as String,y as Integer)      Local i as Integer            Font 0      DarkPlane      If RectShown<>y Then           For i=y+1 To y+8                Line 34,i,154,i,0           Next           Line 33,y,155,y,4           Line 33,y,33,y+9,4           Line 33,y+9,155,y+9,4           Line 155,y+9,155,y,4      EndIf      Locate 35,y+2,msg,2      LightPlane      If RectShown<>y Then           For i=y+1 To y+8                Line 34,i,154,i,0           Next           Line 33,y,155,y,4           Line 33,y,33,y+9,4           Line 33,y+9,155,y+9,4           Line 155,y+9,155,y,4           RectShown = y      EndIf      Locate 35,y+2,msg,2 Procedure ShowBloc(col as Integer,row as Integer)      Local vL as Integer      Local vX as Integer      Local vY as Integer            vX = 8*(col-CameraX)+32      vY = 8*(row-CameraY)      vl = tabloview[col,row]      PutTile vX,vY,Tile1            If vX >= 0 And vX < 160 And vY >=0 And vY< 100 Then           If vl <> 9  Then                PutTile vX,8*(row-CameraY),opened           EndIf           If vl =1 Then                PutTile vX,vY,Tile1                     ElseIf vl =2 Then                PutTile vX,vY,Tile2                     ElseIf vl =3 Then                PutTile vX,vY,Tile3                     ElseIf vl =4 Then                PutTile vX,vY,Tile4                     ElseIf vl =5 Then                PutTile vX,vY,Tile5                     ElseIf vl =6 Then                PutTile vX,vY,Tile6                     ElseIf vl =7 Then                PutTile vX,vY,Tile7                     ElseIf vl =8 Then                PutTile vX,vY,Tile8           ElseIf vl =9 Then                PutTile vX,vY,closed                                    ElseIf vl =10 Then                PutTile vX,vY,mine           ElseIf vl = 11 Then                PutTile vX,vY,mine2           ElseIf vl = 12 Then                PutTile vX,vY,mineBombe           EndIf      EndIf       Procedure FillProba(i as Integer,j as Integer,prb as Integer)      If i>0 And j>0 And TabloView[i-1,j-1]=9 Then           TabloProba[i-1,j-1]=TabloProba[i-1,j-1]+prb      EndIf      If i>0 And TabloView[i-1,j]=9 Then           TabloProba[i-1,j]=TabloProba[i-1,j]+prb      EndIf      If i>0 And j<15 And TabloView[i-1,j+1]=9 Then           TabloProba[i-1,j+1]=TabloProba[i-1,j+1]+prb      EndIf      If j>0 And TabloView[i,j-1]=9 Then           TabloProba[i,j-1]=TabloProba[i,j-1]+prb      EndIf      If j<15 And TabloView[i,j+1]=9 Then           TabloProba[i,j+1]=TabloProba[i,j+1]+prb      EndIf      If i<15 And j>0 And TabloView[i+1,j-1]=9 Then           TabloProba[i+1,j-1]=TabloProba[i+1,j-1]+prb      EndIf      If i<15 And TabloView[i+1,j]=9 Then           TabloProba[i+1,j]=TabloProba[i+1,j]+prb      EndIf      If i<15 And j<15 And TabloView[i+1,j+1]=9 Then           TabloProba[i+1,j+1]=TabloProba[i+1,j+1]+prb      EndIf       Function NeighbourVisible(col as Integer,row as Integer,id as Integer) as Integer      Local Ctr as Integer      Ctr = 0      If col>0 And row>0 And TabloView[col-1,row-1]= id Then           Ctr = Ctr +1      EndIf      If col>0 And TabloView[col-1,row]= id Then           Ctr = Ctr +1      EndIf      If col>0 And row<15 And TabloView[col-1,row+1]= id Then           Ctr = Ctr +1      EndIf      If row>0 And TabloView[col,row-1]= id Then           Ctr = Ctr +1      EndIf      If row<15 And TabloView[col,row+1]= id Then           Ctr = Ctr +1      EndIf      If col<15 And row>0 And TabloView[col+1,row-1]= id Then           Ctr = Ctr +1      EndIf      If col<15 And TabloView[col+1,row]= id Then           Ctr = Ctr +1      EndIf      If col<15 And row<15 And TabloView[col+1,row+1]= id Then           Ctr = Ctr +1      EndIf      Return Ctr       Procedure Think()      Local i as Integer      Local j as Integer      Local max as Integer      Local prb as Integer            Do           For i=0 To 15                For j=0 To 15                     TabloProba[i,j]=1                Next           Next           For i=0 To 15                For j=0 To 15                     If TabloView[i,j]<9 Then                          ' probability = (NbOfMinesInNeighbours - NbOfDiscoveredMinesInNeighbours) / NbOfClosedNeighbours                          max = NeighbourVisible(i,j,9)                          If max > 0 Then                               prb = (TabloView[i,j] - NeighbourVisible(i,j,10) - NeighbourVisible(i,j,11))*4000 / max                          Else                               prb = 0                          EndIf                          FillProba i,j,prb                     EndIf                Next           Next           For i=0 To 15                For j=0 To 15                     If TabloView[i,j]<>9 Then                          TabloProba[i,j]=0                     EndIf                Next           Next                max = 0           For i=0 To 15                For j=0 To 15                     If TabloProba[i,j]>max Then                          BlocToTickX=i                          BlocToTickY=j                          max = TabloProba[i,j]                     EndIf                Next           Next            Loop while TabloView[BlocToTickX,BlocToTickY]<>9      

Sinon pour dire mon sentiment sur le sujet:

* coder super proprement c'est bien
* coder en penseant aux éventuellles futures modifications c'est bien (avec utilisation de patterns)

MAIS

* parfois il faut boucler un projet à une deadline super précise et pas 1 heure plus tard (je pense notamment aux logiciels sur mesure pour la finance)
* faut savoir si ça vaut le coup de passer 3 jours à réfléchir sur la structure d'un programme qu'on sait qu'il ne sera jamais relu/modifié/utilisé

et donc

* savoir super bien coder, c'est un talent, mais savoir faire concessions et être capable mesurer avantages/inconvénients à long terme c'est un autre talent
* avant de cracher sur ceux qui ont pondu du code mauvais, savoir exactement dans quel contexte ils ont fait ainsi: parce qu'ils savent pas coder proprement? ou parce qu'ils l'ont pas jugé pertinent? parce qu'ils avaient la flemme? etc.