ccccccccccccc

#include <graphics.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>
#include<iostream>
#include<string.h>
#include <tchar.h>
#include <mmsystem.h>//导入声音头文件
#pragma comment(lib,"Winmm.lib")


#define MAP_HEIGHT 30
#define MAP_WIDE 30
#define SIZE 16
#define SPEED 200

//定义蛇的结点
typedef struct Snakes
{
    int x;//蛇的结点的位置坐标
    int y;
    struct Snakes* next;
}snake;

snake* head, * tail;
//定义食物的结构
struct Food
{
    int x;
    int y;
}food;

int grow = 0; 
int aa = -1;
//int COUNT = 0;
char ch1 = 1;
int a1 = 0, a2 = 1, a3 = 0;;//grow =0 表示没吃到食物,grow = 1表示吃到食物
TCHAR str[100];
TCHAR str1[100];
TCHAR str2[100];
TCHAR str3[100];
int score = 0;
int count=1;
char ch = 'a';//初始方向向左
void BGM()
{
    PlaySound(TEXT("平凡之路.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);


}
void login()                                                  //登录界面//
{
    char name[100];
    initgraph(1200, 900);
    setbkcolor(BLUE);
    cleardevice();
    settextcolor(WHITE);
    setfont(100, 0, _T("华文行楷"));
    outtextxy(300, 150, _T("WELCOME"));
    wchar_t username[1000];
    errno_t err;
    //FILE* fb;
    InputBox(username, 100, _T("请输入你的昵称"));
    FILE* fb = fopen("username.txt", "a");
    fprintf(fb, "%S ", username);
    fprintf(fb, "%c", '\n');
    fclose(fb);
   // err = fopen_s(&fp, "username.txt", "a");
    //fprintf(fp, "%d", username);
    //fclose(fp);
}
void Count()
{

    FILE* fp11 = fopen("count.txt", "r");
    fscanf(fp11, "%d", &aa);
    aa = aa + 1;
    fclose(fp11);
    FILE* fp111 = fopen("count.txt", "w");
    fprintf(fp111, "%d", aa);
    fclose(fp111);


}
//void Count()
//{
   
   // FILE* fp11 = fopen("count.txt", "r+");
   // fscanf(fp11, "%d", &aa);
   // aa = aa + 1;
   // fclose(fp11);
   // FILE* fp111 = fopen("count.txt", "w");
   // fprintf(fp111, "%d", aa);
   // fclose(fp111);

//}

void DrawMap()//打印地图
{
    setbkcolor(YELLOW);
    cleardevice(); //调用清屏cleardevice用背景色刷新背景
    for (int i = 0; i < MAP_WIDE; i++)
    {
        setfillcolor(BLUE);
        //上边框
        fillrectangle(i * SIZE, 0, (i + 1) * SIZE, SIZE);
        //下边框
        fillrectangle(i * SIZE, (MAP_HEIGHT - 1) * SIZE, (i + 1) * SIZE, MAP_HEIGHT * SIZE);
    }
    for (int i = 0; i < MAP_HEIGHT; i++)
    {
        setfillcolor(BLUE);
        //左边框
        fillrectangle(0, i * SIZE, SIZE, (i + 1) * SIZE);
        //右边框
        fillrectangle((MAP_WIDE - 1) * SIZE, i * SIZE, MAP_WIDE * SIZE, (i + 1) * SIZE);

    }
    settextcolor(GREEN);
    _stprintf_s(str1, _T("%d"), score);

    outtextxy(500, 20, str1);
}
//打印结点
void PrintNode(int x, int y)
{
    setfillcolor(RED);
    fillcircle(x * SIZE, y * SIZE, SIZE / 2);
    setcolor(WHITE);
    circle(x * SIZE, y * SIZE, SIZE / 2);
}
//删除结点
void DeleteNode(int x, int y)
{
    setfillcolor(YELLOW);
    fillcircle(x * SIZE, y * SIZE, SIZE / 2);
    setcolor(YELLOW);
    circle(x

  • 9
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是输出植树地图的完整代码: ```python tree_data = [ ['A', 14.8, 23.8, 18500, 8.0], ['G', 18.8, 28.1, 20800, 7.0], ['F', 24.1, 22.2, 31000, 6.2], ['C', 35.3, 19.9, 28000, 7.3], ['E', 16.5, 10.5, 15000, 4.2] ] # 计算每个树在地图上应该显示的半径 max_radius = max([t[4] for t in tree_data]) for t in tree_data: t.append(int(t[4] / max_radius * 10)) # 构建地图二维数组 map_data = [[' ' for i in range(71)] for j in range(21)] for t in tree_data: x, y, water, radius, display_radius = t[1:] row = int(y / 2) col = int(x * 2) for i in range(-display_radius, display_radius+1): for j in range(-display_radius, display_radius+1): if i**2 + j**2 <= radius**2: map_data[row+i][col+j] = t[0] # 输出地图 for i in range(20, -1, -1): row_str = 'S3: {:>2} + '.format(i*10) for j in range(71): row_str += map_data[i][j] + ' ' if j == 29: row_str += '+ ' print(row_str) col_str = 'S3: 0 ' for i in range(7): col_str += '{:>8}{:<8}'.format(i*10, i*10+10) print(col_str) ``` 解释一下代码: 1. 将树的数据设置为二维数组 `tree_data`,其中每个元素表示一棵树的信息,包括编号、x 坐标、y 坐标、所需水量和半径。 2. 计算每个树在地图上应该显示的半径,将其存储在 `display_radius` 中,并将所有 `display_radius` 中的最大值除以 10。 3. 构建地图二维数组 `map_data`,其中每个元素表示地图上对应位置的树的编号,如果该位置没有树则为空格。 4. 输出地图,首先输出每一行的坐标,并在第 30 列后加上一个 `+`,然后逐行输出地图上的树的位置。注意,由于 Python 中的二维数组是行优先存储的,因此在循环中对行和列的访问要倒过来。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值