Translate

giovedì 5 febbraio 2015

GIOCO-DADO 'C++'

#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void gotoxy(int x, int y)
{
 HANDLE hCon;
 COORD dwPos;
 dwPos.X = x;
 dwPos.Y = y;
 hCon = GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleCursorPosition(hCon, dwPos);
}
void marcodado(void)
{
 gotoxy(20, 1); printf("%c%c%c%c%c%c%c", 201, 205, 205,205,205, 205, 187);
 gotoxy(20, 2); printf("%c     %c", 186, 186);
 gotoxy(20, 3); printf("%c     %c", 186, 186);
 gotoxy(20, 4); printf("%c     %c", 186, 186);
 gotoxy(20, 5); printf("%c%c%c%c%c%c%c", 200, 205, 205,205,205, 205, 188);
 gotoxy(50, 1); printf("%c%c%c%c%c%c%c", 201, 205, 205, 205, 205, 205, 187);
 gotoxy(50, 2); printf("%c     %c", 186, 186);
 gotoxy(50, 3); printf("%c     %c", 186, 186);
 gotoxy(50, 4); printf("%c     %c", 186, 186);
 gotoxy(50, 5); printf("%c%c%c%c%c%c%c", 200, 205, 205, 205, 205, 205, 188);
}
void dado6_1(void)
{
 gotoxy(22, 2); printf("%c", 207);
 gotoxy(24, 2); printf("%c", 207);
 gotoxy(22, 3); printf("%c", 207);
 gotoxy(24, 3); printf("%c", 207);
 gotoxy(22, 4); printf("%c", 207);
 gotoxy(24, 4); printf("%c", 207);
}
void dado6_2(void)
{
 gotoxy(52, 2); printf("%c", 207);
 gotoxy(54, 2); printf("%c", 207);
 gotoxy(52, 3); printf("%c", 207);
 gotoxy(54, 3); printf("%c", 207);
 gotoxy(52, 4); printf("%c", 207);
 gotoxy(54, 4); printf("%c", 207);
}
void dado5_1(void)
{
 gotoxy(22, 2); printf("%c", 207);
 gotoxy(24, 2); printf("%c", 207);
 gotoxy(23, 3); printf("%c", 207);
 gotoxy(22, 4); printf("%c", 207);
 gotoxy(24, 4); printf("%c", 207);
}
void dado5_2(void)
{
 gotoxy(52, 2); printf("%c", 207);
 gotoxy(54, 2); printf("%c", 207);
 gotoxy(53, 3); printf("%c", 207);
 gotoxy(52, 4); printf("%c", 207);
 gotoxy(54, 4); printf("%c", 207);
}
void dado4_1(void)
{
 gotoxy(22, 2); printf("%c", 207);
 gotoxy(24, 2); printf("%c", 207);
 gotoxy(22, 4); printf("%c", 207);
 gotoxy(24, 4); printf("%c", 207);
}
void dado4_2(void)
{
 gotoxy(52, 2); printf("%c", 207);
 gotoxy(54, 2); printf("%c", 207);
 gotoxy(52, 4); printf("%c", 207);
 gotoxy(54, 4); printf("%c", 207);
}
void dado3_1(void)
{
 gotoxy(22, 2); printf("%c", 207);
 gotoxy(23, 3); printf("%c", 207);
 gotoxy(24, 4); printf("%c", 207);
}
void dado3_2(void)
{
 gotoxy(52, 2); printf("%c", 207);
 gotoxy(53, 3); printf("%c", 207);
 gotoxy(54, 4); printf("%c", 207);
}
void dado2_1(void)
{
 gotoxy(23, 2); printf("%c", 207);
 gotoxy(23, 4); printf("%c", 207);
}
void dado2_2(void)
{
 gotoxy(53, 2); printf("%c", 207);
 gotoxy(53, 4); printf("%c", 207);
}
void dado1_1(void)
{
 gotoxy(23, 3); printf("%c", 207);
}
void dado1_2(void)
{
 gotoxy(53, 3); printf("%c", 207);
}
int main()
{
 printf("\t\t\tGIOCO DL DADO\n\n");
 printf("-> GIOCATORE N-1\n\n");
 printf("  [ 1=SI ] <----> [ 0=NO ]\n\n");
 printf("GIOCHI ? : ");
 int giochiono;
 scanf("%d", &giochiono);
 srand(time(NULL));
 int totalN1 = 0;
 //primo giocarote
 if (giochiono == 1){
  printf("\n\n\nBUONA FORTUNA");
  for (int i = 0; i < 75; i++)
  {
   i++;
   gotoxy(i, 11); printf("%c", 207);
   Sleep(100);
  }
  int dadogiocatore1 = 0;
  int dadogiocatore2 = 0;
  dadogiocatore1 = rand() % 6 + 1;
  dadogiocatore2 = rand() % 6 + 1;
   system("cls");
  // printf("->numero [%d]", dadogiocatore1);
      marcodado();
   if (dadogiocatore1 == 1)dado1_1();
   if (dadogiocatore1 == 2)dado2_1();
   if (dadogiocatore1 == 3)dado3_1();
   if (dadogiocatore1 == 4)dado4_1();
   if (dadogiocatore1 == 5)dado5_1();
   if (dadogiocatore1 == 6)dado6_1();
 
   if (dadogiocatore2 == 1)dado1_2();
   if (dadogiocatore2 == 2)dado2_2();
   if (dadogiocatore2 == 3)dado3_2();
   if (dadogiocatore2 == 4)dado4_2();
   if (dadogiocatore2 == 5)dado5_2();
   if (dadogiocatore2 == 6)dado6_2();
  
   totalN1 = dadogiocatore1 + dadogiocatore2;
 }
 else printf("LOL");
 for (int i = 0; i < 75; i++)
 {
  i++;
  gotoxy(i, 11); printf("%c", 207);
  Sleep(200);
 }
 system("cls");
 printf("-> GIOCATORE N-2\n\n");
 printf("  [ 1=SI ] <----> [ 0=NO ]\n\n");
 printf("GIOCHI ? : ");
 int giochiono2;
 scanf("%d", &giochiono2);
 int totalN2 = 0;
 //primo giocarote
 if (giochiono2 == 1){
  printf("\n\n\nBUONA FORTUNA");
  for (int i = 0; i < 75; i++)
  {
   i++;
   gotoxy(i, 11); printf("%c", 207);
   Sleep(100);
  }
  int dadogiocatore3 = 0;
  int dadogiocatore4 = 0;
  dadogiocatore3 = rand() % 6 + 1;
  dadogiocatore4 = rand() % 6 + 1;
  system("cls");
  // printf("->numero [%d]", dadogiocatore1);
  marcodado();
  if (dadogiocatore3 == 1)dado1_1();
  if (dadogiocatore3 == 2)dado2_1();
  if (dadogiocatore3 == 3)dado3_1();
  if (dadogiocatore3 == 4)dado4_1();
  if (dadogiocatore3 == 5)dado5_1();
  if (dadogiocatore3 == 6)dado6_1();
  if (dadogiocatore4 == 1)dado1_2();
  if (dadogiocatore4 == 2)dado2_2();
  if (dadogiocatore4 == 3)dado3_2();
  if (dadogiocatore4 == 4)dado4_2();
  if (dadogiocatore4 == 5)dado5_2();
  if (dadogiocatore4 == 6)dado6_2();
  
  totalN2 = dadogiocatore3 + dadogiocatore4;
 }
 else printf("LOL");
 for (int i = 0; i < 75; i++)
 {
  i++;
  gotoxy(i, 11); printf("%c", 207);
  Sleep(200);
 }
    if (totalN1 < totalN2)printf("\n\nIL VINCITORE E IL GIOCATORE NUMERO 2");
 if (totalN1 > totalN2)printf("\n\nIL VINCITORE E IL GIOCATORE NUMERO 1");
    if (totalN1 == totalN2)printf("\n\nPAREGIO");
 system("pause>registro");
 return 0;
}

Nessun commento:

Posta un commento