Advertisement
Guest User

Untitled

a guest
Dec 19th, 2011
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.99 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  MasterMind
  4. //
  5. //  Created by Robin Theys on 1/12/11.
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <term.h>
  12. #include <string.h>
  13.  
  14. #define COLORSMAX 8
  15. #define ROWS 4
  16. #define LINES 11
  17. #define MCOLORS 4
  18.  
  19.  
  20. void gameMenu (char * color[COLORSMAX], char * store[LINES][ROWS]);
  21. void printArray (char * store[LINES][ROWS], int mode);
  22. void colorGen (char * color[COLORSMAX], char * store[LINES][ROWS]);
  23. void resetArray (char * store[LINES][ROWS]);
  24. void playGame (char * color[COLORSMAX], char * store[LINES][ROWS]);
  25.  
  26.  
  27.  
  28. int main () {
  29.    
  30.     char * color[COLORSMAX] = {"Rouge", "Jaune", "Vert", "Bleu", "Orange", "Blanc", "Violet", "Fuchsia"};
  31.     char * store[LINES][ROWS];
  32.    
  33.     srand(8);
  34.    
  35.     gameMenu(color,store);
  36.    
  37.     return 0;
  38. }
  39.  
  40. void gameMenu (char * color[COLORSMAX], char * store[LINES][ROWS]) {
  41.    
  42.     int choose;
  43.    
  44.     do {
  45.         system("clear");
  46.         printf("\t****************\n");
  47.         printf("\t*              *\n");
  48.         printf("\t*  MasterMind  *\n");
  49.         printf("\t*              *\n");
  50.         printf("\t****************\n");
  51.         printf("\n");
  52.         printf("\t1. Mode Débutant\n");
  53.         printf("\t2. Mode Pro     \n");
  54.         printf("\n");
  55.         printf("\t0. Quitter      \n");
  56.         printf("\n");
  57.         printf("\n");
  58.         printf("\t Votre sélection : ");
  59.         scanf("%d", &choose);
  60.         fpurge(stdin);
  61.        
  62.         switch (choose) {
  63.            
  64.             case 1:
  65.                 playGame(color, store);
  66.                 break;
  67.                
  68.             case 2:
  69.                 printArray(store, 1);
  70.                 //playGame(color, store);
  71.                 break;
  72.                
  73.             case 0:
  74.                 choose = 0;
  75.                 printf("\t\n Au Revoir.");
  76.                 break;
  77.                
  78.             default:
  79.                 break;
  80.         }
  81.     } while (choose != 0);
  82. }
  83.  
  84. void printArray (char * store[LINES][ROWS], int mode) {
  85.    
  86.     int i, j, nbLines=10;
  87.    
  88.     system("clear");
  89.    
  90.     if (mode == 0) {
  91.        
  92.         printf("  S: ");
  93.        
  94.         for (i=0; i<LINES; i++) {
  95.            
  96.             for (j=0; j<ROWS; j++) {
  97.                
  98.                 printf("%8s", store[i][j]);
  99.                
  100.             }
  101.             printf("\n");
  102.             printf("%3d. ", nbLines);
  103.            
  104.             nbLines--;
  105.         }
  106.     } else {
  107.        
  108.         printf("  S:       *       *       *       *\n");
  109.        
  110.         for (i=1; i<LINES; i++) {
  111.            
  112.             printf("%3d. ", nbLines);
  113.            
  114.             for (j=0; j<ROWS; j++) {
  115.                
  116.                 printf("%8s", store[i][j]);
  117.                
  118.             }
  119.             printf("\n");
  120.                        
  121.             nbLines--;
  122.         }
  123.     }                
  124. }
  125.  
  126. void colorGen (char * color[COLORSMAX], char * store[LINES][ROWS]) {
  127.    
  128.     int i, number, max=COLORSMAX;
  129.    
  130.     for (i=0; i<MCOLORS; i++) {
  131.        
  132.         number = rand()%max;
  133.         store[0][i] = color[number];
  134.         color[number] = color[7];
  135.         color[7] = store[0][i];
  136.                
  137.         max--;
  138.     }  
  139. }
  140.  
  141. void resetArray (char * store[LINES][ROWS]) {
  142.    
  143.     int i, j;
  144.    
  145.     for (i=0; i<LINES; i++) {
  146.        
  147.         for (j=0; j<ROWS; j++) {
  148.            
  149.             store[i][j] = " - ";
  150.         }
  151.     }
  152. }
  153.  
  154. void playGame (char * color[COLORSMAX], char * store[LINES][ROWS]) {
  155.    
  156.     int j, i = 10, essais = 0;
  157.     char couleur[10];
  158.     printf("\n");
  159.     resetArray(store);
  160.     colorGen(color, store);
  161.    
  162.     do {
  163.        
  164.         for (j=0; j<MCOLORS; j++) {
  165.            
  166.             printf("Votre Couleur : ");
  167.             gets(couleur);
  168.             store[i][j] = couleur;
  169.             //printf("%s ", store[i][j]);
  170.             //fpurge(stdin);
  171.            
  172.         }
  173.         i--;
  174.         essais++;
  175.      } while (essais < 3);
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement