Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define W 20
  5. #define H 14
  6.  
  7. int main(){
  8. int x=3, y=2, xp=0, yp=0, punteggio=0, contrighe=1, contcolonne=0, del, xn=0, yn=0, turno=0; char dir;
  9.  
  10. xp=(rand() % (W-1)) + 1;
  11. yp=(rand() % (H-1)) + 1;
  12. xn=(rand() % (W-1)) + 1;
  13. yn=(rand() % (H-1)) + 1;
  14. while(true){
  15. printf("\n\nPUNTEGGIO: %d", punteggio);
  16. printf("\n\n000000000000000000000\n");
  17. while(contrighe<H){
  18. if(contcolonne==0){
  19. printf("0");
  20. ++contcolonne;
  21. }
  22. else if(contcolonne==W){
  23. printf("0\n");
  24. contcolonne=0;
  25. ++contrighe;
  26. }
  27. else if(contrighe==yn&&contcolonne==xn){
  28. printf("%c", 'X');
  29. ++contcolonne;
  30. }
  31. else if(contrighe==y&&contcolonne==x){
  32. printf("%c", '@');
  33. ++contcolonne;
  34. }
  35. else if(contrighe==yp&&contcolonne==xp){
  36. printf("%c", '°');
  37. ++contcolonne;
  38. }
  39. else{
  40. printf(" ");
  41. ++contcolonne;
  42. }
  43. }
  44. contrighe=1;
  45. contcolonne=0;
  46. printf("000000000000000000000\n\n\n");
  47. if(x==xn&&y==yn){
  48. printf("----------\nGAME OVER!\n----------");
  49. return 0;
  50. }
  51. printf("Tu: (%d,%d)\n", x, y);
  52. printf("Nemico: (%d,%d)\n", xn, yn);
  53. printf("Cibo: (%d,%d)\n", xp, yp);
  54. printf("Dove vuoi muoverti? (wasd): ");
  55. scanf("%c", &dir);
  56. if(dir=='w'){
  57. if(y>1)
  58. y-=1;
  59. }
  60. if(dir=='s'){
  61. if(y<H-1)
  62. y+=1;
  63. }
  64. if(dir=='a'){
  65. if(x>1)
  66. x-=1;
  67. }
  68. if(dir=='d'){
  69. if(x<W-1)
  70. x+=1;
  71. }
  72. do{
  73. scanf("%c", &dir);
  74. }while(dir!='\n');
  75. if(x==xp&&y==yp){
  76. punteggio++;
  77. xp=(rand() % (W-1)) + 1;
  78. yp=(rand() % (H-1)) + 1;
  79. }
  80. if(x==xn&&y==yn){
  81. printf("----------\nGAME OVER! (plz non andargli addosso)\n----------");
  82. return 0;
  83. }
  84. if(turno==1){
  85. if(x<xn)
  86. --xn;
  87. if(y<yn)
  88. --yn;
  89. if(y>yn)
  90. ++yn;
  91. if(x>xn)
  92. ++xn;
  93. turno=0;
  94. }
  95. else
  96. turno=1;
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement