zoukankan      html  css  js  c++  java
  • 就下一百成,简单版

    #include<stdio.h>
    #include<stdlib.h>
    #include<Windows.h>
    #include<conio.h>
    
    
    #define High 25
    #define Width 40
    
    int people_x, people_y;
    int canvas[High+1][Width+1];
    int b1_left[3],b1_right[3];
    int score = 0;
    int vv = 30, v_b = 8;
    
    void HideCursor()
    {
    	CONSOLE_CURSOR_INFO cursor_info = { 1,0 };
    	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
    }
    void gotoxy(int x, int y)
    {
    	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    	COORD pos;
    	pos.X = x;
    	pos.Y = y;
    	SetConsoleCursorPosition(handle, pos);
    
    }
    
    void startup()
    {
    	int i, j, k;
    	for (i = 3; i <= 24; i += 3)
    	{	
    		int t = 0;
    		for (int k = 0; k < 3; k++)
    		{
    			b1_left[k] = rand() % (Width - 6);
    			b1_right[k] = b1_left[k] + 5;
    
    		}
    		t = 3;
    		while (t--) {
    			for (j =b1_left[t] ; j <b1_right[t]; j++)
    			{
    				canvas[i][j] = 2;
    			}
    		}
    
    	}
    	people_x = 2;
    	people_y = 6;
    	canvas[people_x][people_y] = 1;
    	for (i = 0; i < High; i++)
    	{
    		canvas[i][0] = -2;
    		canvas[i][Width - 1] = -2;
    	}
    	for (j = 0; j < Width; j++)
    	{
    		canvas[0][j] = -1;
    		canvas[High - 1][j] = -1;
    	}
    
    
    }
    
    void show()
    {
    	gotoxy(0, 0);
    	int i, j;
    	for (i = 0; i < High; i++)
    	{
    		for (j = 0; j < Width; j++)
    		{
    			if (canvas[i][j] == 2)
    				printf("-");
    			else if (canvas[i][j] == 1)
    				printf("o");
    			else if (canvas[i][j] == -1)
    				printf("T");
    			else if (canvas[i][j] == -2)
    				printf("|");
    			else printf(" ");
    		}
    		printf("\n");
    	}
    	printf("得分:%d\n", score);
    }
    
    
    void updataWithoutInput()
    {
    
    	int i, j,k;
    	static int v_bord = 0,v_ball=0;
    	bool flag = false;
    	int oldps_x, oldps_y;
    	if (v_bord < vv)
    		v_bord++;
    	if (v_bord == vv) {
    		for (i = 1; i <= High - 2; i++)
    		{
    			for (j = 1; j <= Width - 2; j++)
    			{
    				if (canvas[i][j] == 2 && i - 1 != 0)
    				{
    					canvas[i][j] = 0;
    					if (canvas[i - 1][j] == 1)
    					{
    						people_x = i - 2; people_y = j;
    						canvas[people_x][people_y] = 1;
    						canvas[i - 1][j] = 2;
    					}
    					else
    						canvas[i - 1][j] = 2;
    				}
    				else
    				{
    					if (i - 1 == 0 && canvas[i][j] == 2) {
    						canvas[i][j] = 0;
    						flag = true;
    					}
    
    				}
    			}
    		}
    		v_bord = 0;
    	}
    	for (i = 1; i <= Width - 2; i++)
    	{
    		if (canvas[people_x][i] == 2)
    		{
    			score++;
    			break;
    		}
    	}
    	if (v_ball < v_b)
    		v_ball++;
    
    	if (v_ball==v_b&&canvas[people_x + 1][people_y] == 0)
    	{
    		canvas[people_x][people_y] = 0;
    		people_x++;
    		canvas[people_x][people_y] = 1;
    		v_ball = 0;
    	}
    	if (people_x == 0 || people_x == High - 2)
    	{
    		printf("GAMEOVER!\n");
    		system("pause");
    		exit(0);
    	}
    
    	if (flag)
    	{
    		int t = 0;
    		for (int k = 0; k < 3; k++)
    		{
    			b1_left[k] = rand() % (Width - 7)+1;
    			b1_right[k] = b1_left[k] + 5;
    
    		}
    		t = 3;
    		while (t--) {
    			for (j = b1_left[t]; j < b1_right[t]; j++)
    			{
    				canvas[23][j] = 2;
    			}
    		}
    		
    	}
    	//Sleep(200);
    	
    }
    
    void updataWithInput()
    {
    	char input;
    	if (_kbhit())
    	{
    		input = _getch();
    		if (input == 'a')
    		{
    			canvas[people_x][people_y] = 0;
    			people_y--;
    			canvas[people_x][people_y] = 1;
    		}
    		if (input == 'd')
    		{
    			canvas[people_x][people_y] = 0;
    			people_y++;
    			canvas[people_x][people_y] = 1;
    		}
    
    	}
    
    }
    
    int main()
    {
    	HideCursor();
    	startup();
    	while (1)
    	{
    		show();
    		updataWithoutInput();
    		updataWithInput();
    	}
    
    }
    
    追求吾之所爱
  • 相关阅读:
    人脸识别算法初次了解
    白话经典算法系列之二 直接插入排序的三种实现
    常见浏览器兼容性问题与解决方式
    MP3的频率、比特率、码率与音质的关系
    程序猿接私活经验总结,来自csdn论坛语录
    Java虚拟机工作原理具体解释
    簡單SQL存儲過程實例
    全栈JavaScript之路(七)学习 Comment 类型节点.
    strdup函数的使用方法
    POJ 2823 Sliding Window 【单调队列】
  • 原文地址:https://www.cnblogs.com/rstz/p/14391093.html
Copyright © 2011-2022 走看看