Advertisement
Guest User

Untitled

a guest
May 14th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. /*
  2. * Desarrollador: Alberto Jose Guilarte
  3. * Proyecto: Hacker-Game
  4. * Version: John Bonham (1948 - 1980)
  5. * Plataforma: Windows
  6. * Venezuela, Margarita.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <windows.h> // Mantiene la funcion _SetConsoleTitleA()
  13. #include <time.h> // Mantiene la funcion _Sleep()
  14.  
  15. struct {
  16. char nick[10];
  17. int nivel;
  18. int puntos;
  19. int mensajes;
  20. } datos, *p_datos;
  21.  
  22. struct {
  23. char teclado[20];
  24. char ping[15];
  25. } estructura, *p_tructura;
  26.  
  27.  
  28. void toolbar()
  29. {
  30. printf("Bienvenido %s, tienes (%i) mensaje(s), teclea msj para revisarlo o info para informacion. \n", p_datos -> nick, p_datos -> mensajes);
  31. }
  32.  
  33. void load()
  34. {
  35. FILE *load;
  36. load = fopen("Files/save/partida.hg", "r");
  37. fread(&datos, sizeof(datos), 1, load);
  38. fclose(load);
  39. }
  40.  
  41. void save()
  42. {
  43. FILE *save;
  44. save = fopen( "Files/save/partida.hg", "a" );
  45. fwrite(&datos, sizeof(datos), 1, save);
  46. fclose(save);
  47. }
  48.  
  49. void mensajes()
  50. {
  51. char *dir[3] = {"Files/msj1.hg", "Files/msj2.hg"};
  52. char mensajes;
  53. FILE *msj;
  54. msj = fopen(dir[p_datos -> nivel -1], "r");
  55. mensajes = getc(msj);
  56. while (feof(msj) == 0)
  57. {
  58. printf("%c", mensajes);
  59. mensajes = getc(msj);
  60. }
  61. printf("\n\n");
  62. }
  63.  
  64. void bash()
  65. {
  66. toolbar();
  67. do {
  68. printf("%s@[Terminal]$ ", p_datos -> nick); fflush(stdout);
  69. gets(p_tructura -> teclado);
  70. if (strcmp(p_tructura -> teclado, "msj") == 0)
  71. {
  72. mensajes();
  73. p_datos -> mensajes--;
  74. }else if (strcmp(p_tructura -> teclado, "me") == 0)
  75. {
  76. printf("Usuario: %s \nNivel: %i \n", p_datos -> nick, p_datos -> nivel);
  77. }
  78. else if (strcmp(p_tructura -> teclado, "clear") == 0)
  79. {
  80. system("cls");
  81. toolbar();
  82. }
  83. else if (strcmp(p_tructura -> teclado, "save") == 0)
  84. {
  85. save();
  86. }
  87. else if (strcmp(p_tructura -> teclado, "load") == 0)
  88. {
  89. load();
  90. printf("Archivo cargado... \n");
  91. system("cls");
  92. toolbar();
  93. }
  94. else if (strcmp(p_tructura -> teclado, "exit") == 0)
  95. {
  96. exit(1);
  97. }
  98. else if (!strncmp(p_tructura -> teclado, "ping ", 5) != 0)
  99. {
  100. char *ping[3] = {"201.23.43.01"};
  101. sscanf((p_tructura -> teclado +5), "%s", p_tructura -> ping);
  102. if (strcmp(p_tructura -> ping, ping[p_datos -> nivel -1]) == 0)
  103. {
  104. printf("Haciendo ping a %s con 32 bytes de datos: \n", p_tructura -> ping);
  105. Sleep(400);
  106. printf("Respuesta desde %s tiempo < 43m \n", p_tructura -> ping);
  107. Sleep(500);
  108. printf("Respuesta desde %s tiempo < 40m \n", p_tructura -> ping);
  109. Sleep(500);
  110. printf("> El servidor %s esta ACTIVO \n", p_tructura -> ping);
  111. }
  112. else if (strcmp(p_tructura -> ping, ping[p_datos -> nivel -1]) >= -1)
  113. {
  114. Sleep(800);
  115. printf("El servidor no existe. \n");
  116. }
  117. }
  118. else if (strcmp(p_tructura -> teclado, "") != 0)
  119. {
  120. printf("El comando introducido es invalido, teclea info para mas informacion. \n");
  121. }
  122. } while(strcmp(p_tructura -> teclado, "exit") != 0);
  123. }
  124.  
  125. int main()
  126. {
  127. p_datos = &datos;
  128. p_tructura = &estructura;
  129. /* Hacemos las definiciones aqui */
  130. p_datos -> nivel = 1;
  131. p_datos -> mensajes = 1;
  132. /* -------------------------------- */
  133. SetConsoleTitleA("Hacker-Game --;Version: John Bonham (1948 - 1980)");
  134. system("cls");
  135. printf("> Introduce el nombre para tu usuario: "); fflush(stdout);
  136. gets(p_datos -> nick);
  137. bash();
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement