boardGenerator.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include "game_server.h"
  5. char* boardGenerator(){
  6. char* diceList[] = {
  7. "RIFOBX","IFEHEY","DENOWS","UTOKND",
  8. "HMSRAO","LUPETS","ACITOA","YLGKUE",
  9. "QBMJOA","EHISPN","VETIGN","BALIYT",
  10. "EZAVND","RALESC","UWILRG","PACEMD"
  11. };
  12. char* boardValues;
  13. boardValues = malloc(16);
  14. int dieSelected[16];
  15. for(int i = 0; i < 16; i++){
  16. dieSelected[i] = 0;
  17. }
  18. srand(time(0));
  19. int dieChoice;
  20. int dieSide;
  21. int boardValueCounter = 0;
  22. while(boardValueCounter < 16){
  23. dieChoice = rand() % 16;
  24. if(dieSelected[dieChoice]==1){
  25. continue;
  26. }
  27. dieSide = rand() % 6;
  28. dieSelected[dieChoice] = 1;
  29. boardValues[boardValueCounter] = diceList[dieChoice][dieSide];
  30. boardValueCounter++;
  31. }
  32. return boardValues;
  33. }
  34. void boardCreator(char* boardValues){
  35. printf("---------\n");
  36. printf("|%c|%c|%c|%c|\n",boardValues[0],boardValues[1],boardValues[2],boardValues[3]);
  37. printf("|-------|\n");
  38. printf("|%c|%c|%c|%c|\n",boardValues[4],boardValues[5],boardValues[6],boardValues[7]);
  39. printf("|-------|\n");
  40. printf("|%c|%c|%c|%c|\n",boardValues[8],boardValues[9],boardValues[10],boardValues[11]);
  41. printf("|-------|\n");
  42. printf("|%c|%c|%c|%c|\n",boardValues[12],boardValues[13],boardValues[14],boardValues[15]);
  43. printf("---------\n");
  44. }