当前位置:首页 » 操作系统 » 控制台程序源码

控制台程序源码

发布时间: 2023-08-29 19:50:22

1. 用C#写一个类似cmd的控制台程序,实现ping的功能!!!(求完整程序源代码!)

using System;
using System.Net;
using System.Net.NetworkInformation;
class Program
{
static void Main(string[] args)
{
int count = 4;
IPAddress addr = IPAddress.Parse("220.181.111.86");
Ping ping = new Ping();
long timeSum = 0;
int succCount = 0;
//发送
Console.WriteLine("正在ping {0}", addr);
for (int i = 0; i < count; ++i)
{
PingReply pr = ping.Send(addr);
if (pr.Status == IPStatus.TimedOut)
Console.WriteLine("超时");
else if (pr.Status == IPStatus.Success)
{
Console.WriteLine("延时:{0}毫秒", pr.RoundtripTime);
++succCount;
timeSum += pr.RoundtripTime;
}
}
if (timeSum != 0)
Console.WriteLine("平均延时{0}毫秒,丢包率{1}%", 1.0 * timeSum / succCount, (count - succCount) * 100.0 / count);
else
Console.WriteLine("丢包率100%");
return;
}
}

2. 控制台C或者C++程序,打印出自身源代码

#include <iostream>
#include <fstream>

#define FILENAME "example.cpp" // 这里指定文件名

using namespace std;

int main()
{
ifstream ifs(FILENAME);

char data[1024];

while (!ifs.eof())
{
ifs >> data;
cout << data;
}

ifs.close();
return 0;
}

3. 求用控制台应用程序(不使用MFC)C++语言编写的坦克大战游戏源代码 . 本人新手 写了一个

C++实例编程:简单坦克大战2010-11-2212:40:22作者:佚名来源:IT哇咔搜集整理我要评论进入论坛字号:T|T核心提示:因为有些东西以前练过了,而有些东西没练过,还有很多不足之处.#include#include#include#include#include#defineKEY_ESC0x01#defineKEY_SPACE0x39#defineKEY_UP0x48#defineKEY_LEFT0x4b#defineKEY_RIGHT0x4d#defineKEY_DOWN0x50/*1石头,2砖块,3水,5老家,8玩家,9敌人*/intmap[20][20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,2,2,0,0,2,2,2,2,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,2,0,0,2,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,2,2,2,2,2,2,0,0,0,0,0,0,0,2,2,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,1,1,0,1,1,1,1,3,3,3,3,0,0,0,0,0,0,0,2,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,3,3,3,0,1,1,0,0,0,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,3,3,3,1,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,1,1,0,2,2,0,0,0,0,2,2,2,0,0,0,2,2,0,0,0,1,1,0,0,0,0,0,0,8,2,5,2,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};strUCtf{intx;inty;intdirection;};structplay{intx;/*行坐标*/inty;/*列坐标*/intdirection;/*方向*/structffire[5];/*5颗子弹*/intscore;/*分数*/}Playone;structa{intx;inty;intcolor;intdirection;intdirectiontwo;/*用来判断走的路是否往返*/intfireplay;/*是否攻击的变量,随机生成*/structffire;}amy[5];/*敌人的结构体,其实可以添加不同的颜色来表示不同种类的坦克*/charkey_state[128],key_pressed[128];voidInit();/*图象驱动开始*/voidEnd();/*图象驱动结束*/voidDrawMap();/*画地图*/voidDrawWater(intx,inty);/*画水*/voidDrawBrick(intx,inty);/*画砖*/voidDrawTone(intx,inty);/*画石头*/voidDrawHome(intx,inty);/*画老家*/voidDrawBlack(intx,inty);/*去除内容*/voidDrawPlay(intx,inty);/*画玩家*/voidDrawAmy(intx,inty,inti);/*画敌人*/voidScore();/*输出分数*/voidGamePlay();/*玩游戏过程*/voidGameOver();/*游戏失败*/voidTimeDelay(unsignedlongmicrosec);/*延时函数传入微秒数*/intGetKey(intScanCode);/*这里开始都是按键函数*/voidinterruptfar(*OldInt9Handler)();voidfarinterruptNewInt9();voidInstallKeyboard();voidShutDownKeyboard();voidmain(void){Init();DrawMap();GamePlay();End();}voidTimeDelay(unsignedlongmicrosec)/*延时函数传入微秒数*/{unionREGSr;r.h.ah=0x86;r.x.cx=microsec>>16;r.x.dx=microsec;int86(0x15,&r,&r);}voidInit()/*图象驱动开始*/{intgd=DETECT,gm;initgraph(&gd,&gm,"d:\\tc\\tc");cleardevice();InstallKeyboard();}voidEnd()/*图象驱动结束*/{ShutDownKeyboard();closegraph();}voidDrawTone(intx,inty)/*画石头*/{setfillstyle(SOLID_FILL,7);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);}voidDrawWater(intx,inty)/*画水*/{setfillstyle(SOLID_FILL,BLUE);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);}voidDrawBrick(intx,inty)/*画砖*/{setfillstyle(SOLID_FILL,6);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);setcolor(15);line(100+x*20-9,50+y*20-4,100+x*20+9,50+y*20-4);line(100+x*20-9,50+y*20+4,100+x*20+9,50+y*20+4);line(100+x*20-4,50+y*20-9,100+x*20-4,50+y*20+9);line(100+x*20+4,50+y*20-9,100+x*20+4,50+y*20+9);}voidDrawHome(intx,inty)/*画老家*/{setcolor(0);setfillstyle(SOLID_FILL,GREEN);fillellipse(100+x*20,50+y*20,9,9);}voidDrawBlack(intx,inty)/*去除内容*/{setcolor(0);setfillstyle(SOLID_FILL,0);bar(100+x*20-9,50+y*20-9,100+x*20+9,50+y*20+9);}voidDrawPlay(intx,inty)/*画玩家*/{setcolor(4);/*玩家为红色*/circle(100+x*20,50+y*20,7);switch(Playone.direction)/*判断玩家方向*/{case1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);break;/*上*/case2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);break;/*右*/case3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);break;/*下*/case4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);break;/*左*/}}voidDrawAmy(intx,inty,inti)/*画敌人*/{if(amy[i].color==12)setcolor(12);elseif(amy[i].color==13)setcolor(13);else/*这里是判断三种颜色的坦克*/setcolor(14);circle(100+x*20,50+y*20,7);switch(amy[i].direction)/*判断玩家方向*/{case1:line(100+x*20,50+y*20,100+x*20,50+y*20-9);break;/*上*/case2:line(100+x*20,50+y*20,100+x*20+9,50+y*20);break;/*右*/case3:line(100+x*20,50+y*20,100+x*20,50+y*20+9);break;/*下*/case4:line(100+x*20,50+y*20,100+x*20-9,50+y*20);break;/*左*/}}voidScore()/*输出分数*/{chars[10];Playone.score+=10;sprintf(s,"%d",Playone.score);setfillstyle(SOLID_FILL,0);bar(550,100,640,130);settextstyle(0,0,2);setcolor(YELLOW);outtextxy(550,115,s);}voidDrawMap()/*画地图*/{inti,j,k;for(i=0;i<20;i++){for(j=0;j<20;j++)if(map[i][j]==1)DrawTone(j,i);elseif(map[i][j]==2)DrawBrick(j,i);elseif(map[i][j]==3)DrawWater(j,i);elseif(map[i][j]==5)DrawHome(j,i);elseif(map[i][j]==8){Playone.x=i;Playone.y=j;Playone.direction=1;DrawPlay(j,i);for(k=0;k<5;k++)Playone.fire[k].direction=-1;/*5颗子弹的方向都为-1,表示不存在*/}elseif(map[i][j]==9){amy[0].x=1;amy[0].y=1;amy[0].direction=amy[0].directiontwo=3;/*第一个敌人*/--

热点内容
android下拉刷新通用 发布:2025-02-01 05:03:51 浏览:905
紫光存储最近 发布:2025-02-01 04:58:49 浏览:380
sqlserver重命名 发布:2025-02-01 04:56:24 浏览:428
iisftp被动模式 发布:2025-02-01 04:41:50 浏览:350
车载安卓怎么安装软件 发布:2025-02-01 04:30:50 浏览:469
安卓系统su程序是什么 发布:2025-02-01 04:25:42 浏览:475
android代码行数统计 发布:2025-02-01 04:20:47 浏览:216
快速喊话脚本 发布:2025-02-01 04:16:48 浏览:885
如何分辨普拉多的配置 发布:2025-02-01 04:11:45 浏览:681
linuxc文件删除 发布:2025-02-01 04:11:33 浏览:218