zoukankan      html  css  js  c++  java
  • 第十四周问题总结

    #include "stdio.h"
    #include "windows.h"
    #include "time.h"

    char env[200][200];
    int x=99,y=99,head[2]={99,85},tail[2]={99,80};

    void showstart ()
    {
    printf("*****************************");
    printf("* *");
    printf("* snake *");
    printf("* press 9 to qiut !!! *");
    printf("*****************************");
    Sleep(1000);
    System("cls");
    }


    void init()

    {
    int i,j;
    for(i=0;i<200;i++)
    for(j=0;j<200;j++)
    {
    if(i==0||i==199||j==0||j==199)
    env[i][j]='#';
    if(i==99&&j==99)
    env[x][y]='@';
    if(i=99&&(j>=80&&j<=85))
    env[i][j]='*';

    }

    }

    void show ()

    {
    int i,j;
    for(i=0;i<200;i++)
    for(j=0;j<200;j++)
    {
    printf("%c",env[i][j]);
    }
    }

    void move (int der)

    {
    switch (der)
    {
    case 8:
    {
    if(env[head[0]-1][head[1]]=='*');
    else{
    if((head[0]-1)==x&&head[1]==y)
    {
    head[0]--;
    env[head[0]][head[1]]='*';

    }
    head[0]--;
    env[head[0]][head[1]]='*';
    env[tail[0]][tail[1]]=' ';
    if(env[tail[0]-1][tail[1]]=='*')
    tail[0]--;
    if(env[tail[0]][tail[1]-1]=='*')
    tail[1]--;
    if(env[tail[0]+1][tail[1]]=='*')
    tail[0]++;
    if(env[tail[0]][tail[1]+1]=='*')
    tail[1]++;
    }


    }
    case 2:
    {

    if((head[0]+1)==x&&head[1]==y)
    {
    head[0]++;
    env[head[0]][head[1]]='*';
    }
    head[0]++;
    env[head[0]][head[1]]='*';
    env[tail[0]][tail[1]]=' ';
    if(env[tail[0]-1][tail[1]]=='*')
    tail[0]--;
    if(env[tail[0]][tail[1]-1]=='*')
    tail[1]--;
    if(env[tail[0]+1][tail[1]]=='*')
    tail[0]++;
    if(env[tail[0]][tail[1]+1]=='*')
    tail[1]++;

    }
    case 4:
    {
    if(env[head[0]][head[1]-1]=='*');
    else{
    if(head[0]==x&&(head[1]-1)==y)
    {
    head[1]--;
    env[head[0]][head[1]]='*';
    }
    head[1]--;
    env[head[0]][head[1]]='*';
    env[tail[0]][tail[1]]=' ';
    if(env[tail[0]-1][tail[1]]=='*')
    tail[0]--;
    if(env[tail[0]][tail[1]-1]=='*')
    tail[1]--;
    if(env[tail[0]+1][tail[1]]=='*')
    tail[0]++;
    if(env[tail[0]][tail[1]+1]=='*')
    tail[1]++;
    }

    }
    case 6:
    {

    if(head[0]==x&&(head[1]+1)==y)
    {
    head[1]++;
    env[head[0]][head[1]]='*';
    }
    head[1]++;
    env[head[0]][head[1]]='*';
    env[tail[0]][tail[1]]=' ';
    if(env[tail[0]-1][tail[1]]=='*')
    tail[0]--;
    if(env[tail[0]][tail[1]-1]=='*')
    tail[1]--;
    if(env[tail[0]+1][tail[1]]=='*')
    tail[0]++;
    if(env[tail[0]][tail[1]+1]=='*')
    tail[1]++;


    }
    default:
    {
    if(env[head[0]-1][head[1]]=='*')
    {
    head[0]++;
    if(head[0]==x&&head[1]==y)
    env[head[0]][head[1]]='*';
    head[0]++;
    env[head[0]][head[1]]='*';
    }
    if(env[head[0]+1][head[1]]=='*')
    {
    head[0]--;
    if(head[0]==x&&head[1]==y)
    env[head[0]][head[1]]='*';
    head[0]--;
    env[head[0]][head[1]]='*';
    }
    if(env[head[0]][head[1]-1]=='*')
    {
    head[1]++;
    if(head[0]==x&&head[1]==y)
    env[head[0]][head[1]]='*';
    head[1]++;
    env[head[0]][head[1]]='*';
    }
    if(env[head[0]][head[1]+1]=='*')
    {
    head[1]--;
    if(head[0]==x&&head[1]==y)
    env[head[0]][head[1]]='*';
    head[1]--;
    env[head[0]][head[1]]='*';
    }


    env[tail[0]][tail[1]]=' ';
    if(env[tail[0]-1][tail[1]]=='*')
    tail[0]--;
    if(env[tail[0]][tail[1]-1]=='*')
    tail[1]--;
    if(env[tail[0]+1][tail[1]]=='*')
    tail[0]++;
    if(env[tail[0]][tail[1]+1]=='*')
    tail[1]++;


    }
    }
    }

    void main()
    {
    int der=0,sig=1;
    init();
    showstart ();

    while (sig)
    {
    scanf("%d",&der);
    if(der!=8&&der!=2&&der!=4&&der!=6)
    der=0;
    if(der==9)
    sig=0;
    move(der);
    show();

    }


    }

  • 相关阅读:
    2.六角星绘制
    1.五角星绘制
    Redis
    javaScript
    反射
    区分'方法'和'函数'
    递归,二分法
    匿名函数,排序函数,过滤函数,映射函数,
    生成器,生成器函数,推导式,生成器表达式.
    函数,闭包,迭代器
  • 原文地址:https://www.cnblogs.com/besti145306/p/6212439.html
Copyright © 2011-2022 走看看