當前位置:首頁 » 編程語言 » 大富翁c語言編程實例
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

大富翁c語言編程實例

發布時間: 2023-03-14 21:49:00

㈠ 一個C語言問題

應該這樣子,只需要計算富翁的收入就行了 不需要管陌生人的,無視一個月是38天吧。。。 另外 一分確實是0.01元。。。不是0.001
#include<stdio.h>
int main()
{
int i;
double sumfu=0,y=0.01,m;
scanf("%lf",&m);
for(i=1;i<=38;i++)
{
sumfu=sumfu+m-y;
y=y*2;
if(sumfu<0 ){printf("%d",i); getch();exit(0);}/*只要富翁的收入小於0 ,就說明他開始虧了*/
}
}

㈡ 求大富翁源代碼

#include<iostream.h>
#include<iomanip.h>
#include<string.h>

#define _GOLD 2 //標志有金子的格子
#define _TRAP 3 //標志有陷阱的格子
#define _OBSTACLE 4 //標志有障礙物的格子

class simgame
{
public:
simgame(char *nm,int);
void terminate(){delete []name;};
void init(int data[],int n);
void run();
void display();
private:
char *name;
int way[50]; //標志環道格子種類的數組
int location;
int life;
int money;
int isdead; //判斷是否死亡
int isforward; //判斷是順行還是逆行
};

simgame::simgame(char *nm,int isfd=1)
{
strcpy(name,nm);
isforward=isfd;
location=0;
life=money=100;
isdead=0;
}

void simgame::init(int data[],int n)
{
int nn=0; //用於循環data數組以保證把way數組完整賦值
int i;
way[0]=0;
if(isforward)
{
for(int i=1;i<50;i++)
{
if(nn=n)nn=0; //如果data數組到達末尾,從頭開始
way[i]=data[nn];
nn++;
}
}
else
{
nn=n-1;
for(i=1;i<50;i++)
{
if(nn<0)nn=n-1;
way[i]=data[nn];
nn--;
}
}
}

void simgame::display()
{
cout<<"老鼠"<<name<<":";
if(life>0)
{
cout<<"位置="<<setw(5)<<location;
cout<<"生命="<<setw(5)<<life;
cout<<"金錢="<<setw(5)<<money;
}
else
cout<<"Dead!";
}

void simgame::run()
{
int i;
int isstop=0;
if(isdead)return;
if(isforward) //正常行走的過程
{
for(i=1;i<5;i++)
{
if(location+i==50)
location-=50; //如果到達末尾則從頭開始走,並把位置變數重新賦值
if(way[location+i]==_OBSTACLE) //如果途中有障礙物,則停止
{
location+=i;
isstop=1; //標志,表示是否停留
break;
}
}
if(!isstop)
location+=4;
switch(way[location])
{
case _GOLD:money+=50;break;
case _TRAP:life-=80;break;
default:break;
}
if(life<=0)isdead=1;
}
else //逆行的過程
{
for(i=1;i<4;i++)
{
if(location+i==50)
location-=50;
if(way[location+i]==_OBSTACLE)
{
location+=i;
isstop=1;
break;
}
}
if(!isstop)
location+=3;
switch(way[location])
{
case _GOLD:money+=50;break;
case _TRAP:life-=80;break;
default:break;
}
if(life<=0)isdead=1;
}
}

void main()
{
simgame mice1("A");
simgame mice2("B",0);
int data[20]={1,2,2,2,3,2,3,4,1,2,3,4,1,2,3,4,3,2,2,1};
mice1.init(data,20);
mice2.init(data,20);
for(int i=0;i<5;i++)
{
mice1.run();
mice2.run();
cout<<"輪次:"<<i+1<<endl;
mice1.display();
mice2.display();
}
mice1.terminate();
mice2.terminate();
}
可以編譯,但不可以運行,求大蝦給診斷一哈,謝謝謝謝
問題補充:題目:一條由50個格子組成的環形跑道,其中一個格子是起點,兩只鼠都從起點按相反方向出發,一隻鼠按正方向前進且每次前進4格,另一隻鼠按反方向出發,且每次前進3個格子,每隻鼠出發時都有100點生命值和100個金子;跑道由普通格子,帶金幣的格子,帶陷阱的格子,帶障礙的格子等四種組成!

規則:a,起點是普通格子,任何普通格子鼠可以順利通過.
b.鼠每路過或停在一個帶金幣的格子上就增加50個金幣
c.鼠停留在陷阱的格子上,損失生命80點.
d.鼠路過帶障礙的格子時,本輪停止前進.

1.並實現相關的類,同時模擬此游戲
輸入:已在main()中提供一個大小為20的一維整型數組data,數值可為1,2,3,4,分別表示四種類型的格子,其中data(0)表示起點.
輸出:10輪次內,每輪走完後兩只老鼠的各自位置,生命,和擁有的金幣數.

要main()函數應為如下格式
void main()
{
int data[20]={1,2,2,2,3,2,3,4,1,2,3,4,1,2,3,4,3,2,2,1};
simgame game;
game.init(data,20);
game.run(5)
game.terminate();
}

輸出:
輪次1:
老鼠A:位置=##生命=##金錢=##
老鼠B:位置=##生命=##金錢=##
輪次2:
.......
宏:
#define _GOLD 2 //金子
#define _TRAP 3 //陷阱
#define _OBSTACLE 4 //障礙物

㈢ 作業``用C#編寫一個類似大富翁3的游戲

么你們的老師就不用當老師了嘛,天天就可以寫游戲來賣錢了撒。好笑

㈣ C語言問題 求助

代碼:

#include <stdio.h>

void main()
{
double a=10,b=1,sum[2]={0,0};
int i;

for (i=0;i<30;i++)
{
sum[0]+=a;
sum[1]+=b;
b*=2;
}
printf("陌生人共給了富翁%.0f萬元 ",sum[0]);
printf("富翁共給了陌生人%.6f萬元 ",sum[1]/1000000.0);
}

結果:

㈤ 用C語言寫大富翁源代碼

struct maptype
{
int money,belong;
char name[20];
}map[9][13]={0};
struct player
{
int x,y,money,di;
}man[3]={0};
int dx[5]={0,0,1, 0,-1};
int dy[5]={0,1,0,-1, 0};
int i,j,x,y;
int turn,step,res;
char out[1000];
char *s11="姓名史艷文";
char *s12="資金";
char *s21="姓名比卡超";
char *s22="資金";
char *s31="你需要付給對手";
char *s32="元";
char *s41="老友輪到你走啦";
char *s42="輪到對手走啦";
char *s51="買下此地要";
char *s52="買";
char *s53="不買";
char *s54="老大你的錢不夠";
char *z1="起點";
char *z2="休息處";
char *fa="經過起點發旅費";
char *m1="路過岳王廟";
char *m2="路過純白鎮";
char *m3="獲取錢三千";
char *m4="獲取錢六千";
char *zi1="行";
char *zi2="動";
char *zi3="查";
char *zi4="看";
char *zi5="離";
char *zi6="開";
char *last="你要花兩千元升級地價嗎";

#define ESC 0x011b
#define ENTER 0x1c0d
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define UP 0x4800
#define DOWN 0x5000

#include<stdio.h>
#include<stdlib.h>
#include"first.c"
#include<graphics.h>
#include "bmp16.h"
#include"files.c"

int graphdriver=VGA;
int graphmode=VGAHI;
FILE *hzk_p;
void open_hzk(void);
void get_hz(char incode[],char bytes[]);
void dishz(int x,int y,char code[],int color);
#include"rich2.c"

int main()
{
initgraph(&graphdriver,&graphmode,"");
cleardevice();
open_hzk();
first();

begin();

files();

setbkcolor(0);
while (1)
{
print(0);
step=random(6)+1;
{}
if (turn==1)
{
next3();
}
chuli(turn,step);
buy();
{}
turn=(turn+1)%2;
if (turn==0)
turn=2;
step=0;
}
return 0;
}

void open_hzk()
{
hzk_p=fopen("hzk16","rb");
if (!hzk_p)
{
printf("The file no\n");
getch();
closegraph();
exit(1);
}
}

void get_hz(char incode[],char bytes[])
{
unsigned char qh,wh;
unsigned long offset;
qh=incode[0]-0xa0;
wh=incode[1]-0xa0;
offset=(94*(qh-1)+(wh-1))*32L;
fseek(hzk_p,offset,SEEK_SET);
fread(bytes,32,1,hzk_p);
}

void dishz(int x0,int y0,char code[],int color)
{
unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int i,j,x,y,pos;
char mat[32];
get_hz(code,mat);
y=y0;
for(i=0;i<16;i++)
{
x=x0;
pos=2*i;
for (j=0;j<16;j++)
{
if ((mask[j%8]&mat[pos+j/8])!=NULL)
putpixel(x,y,color);
++x;
}
++y;
}
}