求一个用于表白的C语言或C++的程序,谢谢大家了

求一个用于表白的C语言或C++的程序,谢谢大家了,第1张

#include <stdioh>

#include <mathh>

#include <stdlibh>

#define I 20

#define R 340

#include <stringh>

int main()

{

char answer[10];

printf("遇到你\n我才发现\n曾经所有的条件\n似乎都成了我等你的借口\n\n");

printf("我对你的感情已经决堤\n所以\n请允许我,从今往后映入你\n明媚的眼\n");

printf("我\n想和你\n耳鬓厮磨,相濡以沫!");

printf("答应我吧!\n输入yes,你可以看到我的真心\n");

scanf("%s", answer);

float y, x, z, f;

for (y = 15f; y > -15f; y -= 01f)

{

for (x = -15f; x < 15f; x += 005f)

{

z = x x + y y - 1;

f = z zz - x xyyy;

putchar(f <= 00f ""[(int)(f-80f)] : ' ');

}

putchar('\n');

}

long time;

for (;;)

{

system("color a");

for (time = 0; time<99999999; time++);

system("color b");

for (time = 0; time<99999999; time++);

system("color c");

for (time = 0; time<99999999; time++);

system("color d");

for (time = 0; time<99999999; time++);

system("color e");

for (time = 0; time<99999999; time++);

system("color f");

for (time = 0; time<99999999; time++);

system("color 0");

for (time = 0; time<99999999; time++);

system("color 1");

for (time = 0; time<99999999; time++);

system("color 2");

for (time = 0; time<99999999; time++);

system("color 3");

for (time = 0; time<99999999; time++);

system("color 4");

for (time = 0; time<99999999; time++);

system("color 5");

for (time = 0; time<99999999; time++);

system("color 6");

for (time = 0; time<99999999; time++);

system("color 7");

for (time = 0; time<99999999; time++);

system("color 8");

for (time = 0; time<99999999; time++);

system("color 9");

}

getchar();

return 0;

}

运行效果:

扩展资料:

printf函数使用注意事项

1、域宽

%d:按整型数据的实际长度输出。

如果想输出指定宽度可以指定域宽,%md--&gt;m域宽,打印出来以后,在控制台上,显示m位;

如果我们要打印的数的位数如果超过我们设定m则原样输出;

如果我们要打印的数的位数如果小于我们设定的位数,则补空白,具体如下:

如果m为正数,则左对齐(左侧补空白);

如果m为负数,则右对齐(右侧补空白)。

2、转义字符

如果想输出字符"%",则应该在“格式控制”字符串中用连续两个%表示。

如:printf("%f%%",1.0/3);输出结果:0.333333%。

试试这个吧。

import numpy as np

import pygame

import sys

import traceback

import copy

from pygamelocals import

pygameinit()

pygamemixerinit()

#颜色

background=(201,202,187)

checkerboard=(80,80,80)

button=(52,53,44)

#音乐

play_chess_sound = pygamemixerSound("music/play_chesswav")

play_chess_soundset_volume(02)

button_sound = pygamemixerSound("music/buttonwav")

button_soundset_volume(02)

victor_sound = pygamemixerSound("music/victorywav")

victor_soundset_volume(02)

#绘制棋盘

def Draw_a_chessboard(screen):

#填充背景色

screenfill(background)

Background=pygameimageload("backgroundjpg")convert_alpha()

screenblit(Background,(0,0))

#画棋盘

for i in range(21):

pygamedrawline(screen, checkerboard, (40i+3, 3), (40i+3, 803))

pygamedrawline(screen, checkerboard, (3, 40i+3), (803, 40i+3))

#画边线

pygamedrawline(screen, checkerboard, (3, 3), (803, 3),5)

pygamedrawline(screen, checkerboard, (3, 3), (3, 803),5)

pygamedrawline(screen, checkerboard, (803, 3), (803, 803),5)

pygamedrawline(screen, checkerboard, (3, 803), (803, 803),5)

#画定位点

pygamedrawcircle(screen, checkerboard, (163, 163), 6)

pygamedrawcircle(screen, checkerboard, (163, 643), 6)

pygamedrawcircle(screen, checkerboard, (643, 163), 6)

pygamedrawcircle(screen, checkerboard, (643, 643), 6)

pygamedrawcircle(screen, checkerboard, (403, 403), 6)

#画‘悔棋’‘重新开始’跟‘退出’按钮

pygamedrawrect(screen,button,[900,350,120,100],5)

pygamedrawrect(screen,button,[900,500,200,100],5)

pygamedrawrect(screen,button,[900,650,200,100],5)

s_font=pygamefontFont('fontttf',40)

text1=s_fontrender("悔棋",True,button)

text2=s_fontrender("重新开始",True,button)

text3=s_fontrender("退出游戏",True,button)

screenblit(text1,(920,370))

screenblit(text2,(920,520))

screenblit(text3,(920,670))

#绘制棋子(横坐标,纵坐标,屏幕,棋子颜色(1代表黑,2代表白))

def Draw_a_chessman(x,y,screen,color):

if color==1:

Black_chess=pygameimageload("Black_chesspng")convert_alpha()

screenblit(Black_chess,(40x+3-15,40y+3-15))

if color==2:

White_chess=pygameimageload("White_chesspng")convert_alpha()

screenblit(White_chess,(40x+3-15,40y+3-15))

#绘制带有棋子的棋盘

def Draw_a_chessboard_with_chessman(map,screen):

screenfill(background)

Draw_a_chessboard(screen)

for i in range(24):

for j in range(24):

Draw_a_chessman(i+1,j+1,screen,map[i][j])

#定义存储棋盘的列表,

#列表为24列24行是因为判断是否胜利函数里的索引会超出19

#列表大一点不会对游戏有什么影响

map=[]

for i in range(24):

mapappend([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])

#清零map列表

def clear():

global map

for i in range(24):

for j in range(24):

map[i][j]=0

#判断是否胜利

def win(i, j):

k = map[i][j]

p=[]

for a in range(20):

pappend(0)

for i3 in range(i-4,i+5):

for j3 in range(j-4,j+5):

if (map[i3][j3] == k and i3 - i == j3 - j and i3 <= i and j3 <= j):

p[0]+=1

if (map[i3][j3] == k and j3 == j and i3 <= i and j3 <= j):

p[1]+=1

if (map[i3][j3] == k and i3 == i and i3 <= i and j3 <= j):

p[2]+=1

if (map[i3][j3] == k and i3 - i == j3 - j and i3 >= i and j3 >= j):

p[3]+=1

if (map[i3][j3] == k and j3 == j and i3 >= i and j3 >= j):

p[4]+=1

if (map[i3][j3] == k and i3 == i and i3 >= i and j3 >= j):

p[5]+=1

if (map[i3][j3] == k and i - i3 == j3 - j and i3 <= i and j3 >= j):

p[6]+=1

if (map[i3][j3] == k and i3 - i == j - j3 and i3 >= i and j3 <= j):

p[7]+=1

if (map[i3][j3] == k and j - j3 == i - i3 and i3 <= i + 1 and i3 >= i - 3 and j3 <= j + 1 and j3 >= j - 3):

p[8]+=1

if (map[i3][j3] == k and j == j3 and i3 <= i + 1 and i3 >= i - 3 and j3 <= j + 1 and j3 >= j - 3):

p[9]+=1

if (map[i3][j3] == k and i == i3 and i3 <= i + 1 and i3 >= i - 3 and j3 <= j + 1 and j3 >= j - 3):

p[10]+=1

if (map[i3][j3] == k and j - j3 == i - i3 and i3 >= i - 1 and i3 <= i + 3 and j3 >= j - 1 and j3 <= j + 3):

p[11]+=1

if (map[i3][j3] == k and j == j3 and i3 >= i - 1 and i3 <= i + 3 and j3 >= j - 1 and j3 <= j + 3):

p[12]+=1

if (map[i3][j3] == k and i == i3 and i3 >= i - 1 and i3 <= i + 3 and j3 >= j - 1 and j3 <= j + 3):

p[13]+=1

if (map[i3][j3] == k and i - i3 == j3 - j and i3 <= i + 1 and i3 >= i - 3 and j3 >= j - 1 and j3 <= j + 3):

p[14]+=1

if (map[i3][j3] == k and i3 - i == j - j3 and i3 >= i - 1 and i3 <= i + 3 and j3 <= j + 1 and j3 >= j - 3):

p[15]+=1

if (map[i3][j3] == k and j - j3 == i - i3 and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):

p[16]+=1

if (map[i3][j3] == k and j == j3 and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):

p[17]+=1

if (map[i3][j3] == k and i == i3 and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):

p[18]+=1

if (map[i3][j3] == k and i - i3 == j3 - j and i3 <= i + 2 and i3 >= i - 2 and j3 <= j + 2 and j3 >= j - 2):

p[19]+=1

for b in range(20):

if p[b]==5:

return True

return False

#绘制提示器(类容,屏幕,字大小)

def text(s,screen,x):

#先把上一次的类容用一个矩形覆盖

pygamedrawrect(screen,background,[850,100,1200,100])

#定义字体跟大小

s_font=pygamefontFont('fontttf',x)

#定义类容,是否抗锯齿,颜色

s_text=s_fontrender(s,True,button)

#将字放在窗口指定位置

screenblit(s_text,(880,100))

pygamedisplayflip()

#用于控制顺序

t=True

#用于结束游戏后阻止落子

running=True

#主函数

def main():

#将 t,map,running设置为可改的

global t,map,running,maps,r,h

#将map置零

clear()

#定义储存所有棋盘状态的列表(用于悔棋)

map2=copydeepcopy(map)

maps=[map2]

#定义窗口

screen = pygamedisplayset_mode([1200,806])

#定义窗口名字

pygamedisplayset_caption("五子棋")

#在窗口画出棋盘,提示器以及按钮

Draw_a_chessboard(screen)

pygamedisplayflip()

clock=pygametimeClock()

while True:

#只有running为真才能落子,主要用于游戏结束后防止再次落子

if running:

if t:

color=1

text('黑棋落子',screen,54)

else:

color=2

text('白棋落子',screen,54)

for event in pygameeventget():

#点击x则关闭窗口

if eventtype ==pygameQUIT:

pygamequit()

sysexit()

#点击窗口里面类容则完成相应指令

elif eventtype == MOUSEBUTTONDOWN:

if eventbutton == 1:

x,y=eventpos[0],eventpos[1]

for i in range(19):

for j in range(19):

#点击棋盘相应位置

if i40+3+20<x<i40+3+60 and j40+3+20<y<j40+3+60 and not map[i][j] and running:

#在棋盘相应位置落相应颜色棋子

Draw_a_chessman(i+1,j+1,screen,color)

#播放音效

play_chess_soundplay(0)

#在map里面记录落子位置

map[i][j]=color

#将map存入maps

map3=copydeepcopy(map)

mapsappend(map3)

#判断落子后是否有五子一线

if win(i,j):

if t:

text('黑棋胜利,请重新游戏',screen,30)

else:

text('白棋胜利,请重新游戏',screen,30)

#播放音效

victor_soundplay(0)

#阻止再往棋盘落子

running=False

pygamedisplayflip()

t=not t

#如果点击‘重新开始’

if 900<x<1100 and 500<y<600:

#取消阻止

running=True

#播放音效

button_soundplay(0)

#重新开始

main()

#点击‘退出游戏’,退出游戏

elif 900<x<1100 and 650<y<750:

#播放音效

button_soundplay(0)

pygamequit()

sysexit()

#点击‘悔棋’

elif 900<x<1020 and 350<y<450 and len(maps)!=1:

#播放音效

button_soundplay(0)

#删除maps里最后一个元素

del maps[len(maps)-1]

#再将最后一个元素copy给map

map=copydeepcopy(maps[len(maps)-1])

#切换顺序

t=not t

#将map显示出来

Draw_a_chessboard_with_chessman(map,screen)

#悔棋完成,阻止再次悔棋

x,y=0,0

clocktick(60)

if __name__ == "__main__":

try:

main()

except SystemExit:

pass

except:

tracebackprint_exc()

pygamequit()

input()

A main函数是程序的入口,但是位置可以随意,不过只能有1个main函数。

B C不像phython这类语言,C是以分号作为语句分界的。只要有分号;就视为一条完整的语句。而不是回车。

C 正确选项。C的输入输出是依靠库函数完成的。printf(),scanf()就是2个最基本的库函数。一个语句可以调用一个或多个函数,但语句不等于函数。

D C/C++的编译器在编译时会忽略掉注释的内容。同样,你可以在注释里写任何内容。。。你甚至可以用星号描绘一张图给自己做签名。。。。

欢迎分享,转载请注明来源:表白网

原文地址:https://h5.hunlipic.com/biaobai/4166151.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2024-04-20
下一篇2024-04-20

发表评论

登录后才能评论

评论列表(0条)

    保存