//题目就不附加了,很累!
//努力AC!每天AC!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int x_bound,y_bound;
int grid[60][60];
int wall_cost;
int bumpers_num;
int bumpers_value[100][100],bumpers_cost[100][100];
int ball[4];
int next[4][2]={ {1,0}, {0,1}, {-1,0}, {0,-1} };
int play_game(int ball[]);
int main()
{
int i,j,totalpoints=0,ballpoints=0,temp_x,temp_y;
scanf("%d%d",&x_bound,&y_bound);
for(i=1;i<=x_bound;i++)
for(j=1;j<=y_bound;j++)
{
if(i==1||j==1||i==x_bound||j==y_bound)
grid[i][j]=1;
else
grid[i][j]=0;
}
scanf("%d",&wall_cost);
scanf("%d",&bumpers_num);
for(i=1;i<=bumpers_num;i++)
{
scanf("%d%d",&temp_x,&temp_y);
scanf("%d",&bumpers_value[temp_x][temp_y]);
scanf("%d",&bumpers_cost[temp_x][temp_y]);
grid[temp_x][temp_y]=2;
}
while(scanf("%d",&ball[1])!=EOF)
{
for(i=2;i<=4;i++)
scanf("%d",&ball[i]);
ballpoints=play_game(ball);
totalpoints+=ballpoints;
printf("%d\n",ballpoints);
i++;
}
printf("%d\n",totalpoints);
}
int play_game(int ball[])
{
int points=0;
int next_x,next_y;
while(ball[4]>1)
{
ball[4]--;
next_x=ball[1]+next[ball[3]][0];
next_y=ball[2]+next[ball[3]][1];
if(grid[next_x][next_y]==2)
{
ball[3]--;
if(ball[3]<0)
ball[3]=3;
if(ball[4]>0)
{
points+=bumpers_value[next_x][next_y];
ball[4]-=bumpers_cost[next_x][next_y];
}
}
else if(grid[next_x][next_y]==1)
{
if((next_x==1&&ball[3]==2)||(next_x==x_bound&&ball[3]==0)
||(next_y==1&&ball[3]==3)||(next_y==y_bound&&ball[3]==1))
{
ball[3]--;
if(ball[3]<0)
ball[3]=3;
ball[4]-=wall_cost;
}
}
else
{
ball[1]=next_x;
ball[2]=next_y;
}
}
return points;
}
很恶心的题目,读懂规则后就容易了!
注意:碰到wall或者bumper,都会弹回原来的位置(指的是碰撞上一秒的位置),但是方向改变了!还有必须ball的lifetime要减掉1,还要减掉碰撞的cost!
本文介绍了一个游戏编程挑战的实现过程,通过解析游戏规则并利用 C++ 实现了一个简单的弹球游戏模拟器。该模拟器考虑了边界、障碍物及反弹器等元素,并计算得分。
3522

被折叠的 条评论
为什么被折叠?



