Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // MasterMind
- //
- // Created by Robin Theys on 1/12/11.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #include <stdio.h>
- #include <stdlib.h>
- #include <term.h>
- #include <string.h>
- #define COLORSMAX 8
- #define ROWS 4
- #define LINES 11
- #define MCOLORS 4
- void gameMenu (char * color[COLORSMAX], char * store[LINES][ROWS]);
- void printArray (char * store[LINES][ROWS], int mode);
- void colorGen (char * color[COLORSMAX], char * store[LINES][ROWS]);
- void resetArray (char * store[LINES][ROWS]);
- void playGame (char * color[COLORSMAX], char * store[LINES][ROWS]);
- int main () {
- char * color[COLORSMAX] = {"Rouge", "Jaune", "Vert", "Bleu", "Orange", "Blanc", "Violet", "Fuchsia"};
- char * store[LINES][ROWS];
- srand(8);
- gameMenu(color,store);
- return 0;
- }
- void gameMenu (char * color[COLORSMAX], char * store[LINES][ROWS]) {
- int choose;
- do {
- system("clear");
- printf("\t****************\n");
- printf("\t* *\n");
- printf("\t* MasterMind *\n");
- printf("\t* *\n");
- printf("\t****************\n");
- printf("\n");
- printf("\t1. Mode Débutant\n");
- printf("\t2. Mode Pro \n");
- printf("\n");
- printf("\t0. Quitter \n");
- printf("\n");
- printf("\n");
- printf("\t Votre sélection : ");
- scanf("%d", &choose);
- fpurge(stdin);
- switch (choose) {
- case 1:
- playGame(color, store);
- break;
- case 2:
- printArray(store, 1);
- //playGame(color, store);
- break;
- case 0:
- choose = 0;
- printf("\t\n Au Revoir.");
- break;
- default:
- break;
- }
- } while (choose != 0);
- }
- void printArray (char * store[LINES][ROWS], int mode) {
- int i, j, nbLines=10;
- system("clear");
- if (mode == 0) {
- printf(" S: ");
- for (i=0; i<LINES; i++) {
- for (j=0; j<ROWS; j++) {
- printf("%8s", store[i][j]);
- }
- printf("\n");
- printf("%3d. ", nbLines);
- nbLines--;
- }
- } else {
- printf(" S: * * * *\n");
- for (i=1; i<LINES; i++) {
- printf("%3d. ", nbLines);
- for (j=0; j<ROWS; j++) {
- printf("%8s", store[i][j]);
- }
- printf("\n");
- nbLines--;
- }
- }
- }
- void colorGen (char * color[COLORSMAX], char * store[LINES][ROWS]) {
- int i, number, max=COLORSMAX;
- for (i=0; i<MCOLORS; i++) {
- number = rand()%max;
- store[0][i] = color[number];
- color[number] = color[7];
- color[7] = store[0][i];
- max--;
- }
- }
- void resetArray (char * store[LINES][ROWS]) {
- int i, j;
- for (i=0; i<LINES; i++) {
- for (j=0; j<ROWS; j++) {
- store[i][j] = " - ";
- }
- }
- }
- void playGame (char * color[COLORSMAX], char * store[LINES][ROWS]) {
- int j, i = 10, essais = 0;
- char couleur[10];
- printf("\n");
- resetArray(store);
- colorGen(color, store);
- do {
- for (j=0; j<MCOLORS; j++) {
- printf("Votre Couleur : ");
- gets(couleur);
- store[i][j] = couleur;
- //printf("%s ", store[i][j]);
- //fpurge(stdin);
- }
- i--;
- essais++;
- } while (essais < 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement