小编Bio*_*yth的帖子

C数组的值随机变化

好吧所以我一直在研究像游戏这样的小胭脂来教我自己但是我无法弄清楚为什么数组在初始化后最终会随机变化.这是我的代码:

// ConsoleApplication2.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

const int x=10;
const int y=10;

int rexit[]={5,5};
int player[]={1,1};
int enemy[]={x,y};
int useless[]={1,1};




/*
int getinput(int len){
    char temp[100];
    return(atoi(strtok(fgets(temp,len+1,stdin),"\n")));

}
*/


void bad(){
  float bob;
  float temp[8]={1,1};
  temp[1]=player[1]-enemy[1];
  temp[2]=player[2]-enemy[2];
  bob=pow(temp[1],2)+pow(temp[2],2);
  printf("%f\n",bob);

   if (sqrt(bob)<=5){
    if (abs(player[1]-enemy[1])>abs(player[2]-enemy[2])){
        if (player[1]-enemy[1]<0 && enemy[1]-1>=0){
         enemy[1]=enemy[1]-1;
        }
        else if (enemy[1]+1<=x && player[1]-enemy[1]!=0){
            enemy[1]=enemy[1]+1;
        }
    }
    else;
     if …
Run Code Online (Sandbox Code Playgroud)

c arrays visual-studio-2012

-1
推荐指数
1
解决办法
1131
查看次数

标签 统计

arrays ×1

c ×1

visual-studio-2012 ×1