轮播图系列教程(一)——和派孔明

//<span style="font-size: 18px; "><strong>简易左右切换轮播图系列教程(一),欢迎阅读javascript轮播图系列教程,本教程将由简单到复杂逐布实现轮播图效果。</strong></span>
<style>
*{margin:0;padding:0;list-style:none;}
img{border:none;}
body{background:#ecfaff;}
.box{width:1000px;height:409px;overflow:hidden;
position:relative;margin:0 auto;background:#ccc;}
.box ul{position:absolute;top:0;left:0;z-index:1;width:99999px;}
.box ul li{float:left;width:1000px;height:409;}
.box ul img{float:left;width:1000px;height:409;}

.box p{width:60px;height:60px;line-height:60px;
color:#fff;text-align:center;background:#333px;
border:1px solid #ccc;position:absolute;top:170px;
z-index:2;cursor:pointer;font-size:50px;}
.box .prev{left:10px;}
.box .next{right:10px;}
</style>


<pre name="code" class="javascript"><span style="font-size:18px;"><strong><script>
window.οnlοad=function(){
	var oBanner=document.getElementById('banner');
	var oUl=oBanner.getElementsByTagName('ul')[0];
	var aLi=oUl.children;
	var oPrev=oBanner.getElementsByTagName('p')[0];
	var oNext=oBanner.getElementsByTagName('p')[1];
	var now=0;

	//ul宽度
	oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';

	oNext.οnclick=function(){
		now++; //计算
		if(now==aLi.length) now=0;
		oUl.style.left=-now*aLi[0].offsetWidth+'px';
	};

	oPrev.οnclick=function(){
		now--;//计算
		if(now==-1) now=aLi.length-1;
		oUl.style.left=-now*aLi[0].offsetWidth+'px';
	};
};
</script></strong></span>

 

<span style="font-size:18px;"><strong><div class="box" id="banner">
	<p id="prev" class="prev">«</p>
	<p id="next" class="next">»</p>
<ul>
	<li><a href="javascript:;"><img src="images/1.jpg" alt="广告一" /></a></li>
	<li><a href="javascript:;"><img src="images/2.jpg" alt="广告一" /></a></li>
	<li><a href="javascript:;"><img src="images/3.jpg" alt="广告一" /></a></li>
	<li><a href="javascript:;"><img src="images/4.jpg" alt="广告一" /></a></li>
	<li><a href="javascript:;"><img src="images/5.jpg" alt="广告一" /></a></li>
</ul>
</div></strong></span>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
没有问题,我可以为您提供编写孔明棋的代码片段,您可以在此基础上进行开发。需要提醒的是,该代码仅为示例,可能会存在不足之处,需要您根据实际情况进行完善和改进。以下是代码片段: ```python import pygame # 初始化pygame pygame.init() # 定义颜色 BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) # 设置屏幕尺寸 SIZE = (700, 700) screen = pygame.display.set_mode(SIZE) # 设置窗口标题 pygame.display.set_caption("孔明棋") # 定义棋盘格子的大小 GRID_SIZE = 80 # 初始化棋盘状态 board = [[0] * 9 for i in range(9)] board[0][0] = board[8][8] = 1 board[0][8] = board[8][0] = 2 # 画棋盘函数 def draw_board(): for i in range(9): for j in range(9): x = j * GRID_SIZE y = i * GRID_SIZE if (i + j) % 2 == 0: pygame.draw.rect(screen, WHITE, [x, y, GRID_SIZE, GRID_SIZE]) else: pygame.draw.rect(screen, BLACK, [x, y, GRID_SIZE, GRID_SIZE]) pygame.display.flip() # 画棋子函数 def draw_piece(row, col, color): x = col * GRID_SIZE y = row * GRID_SIZE pygame.draw.circle(screen, color, [x + GRID_SIZE//2, y + GRID_SIZE//2], GRID_SIZE//3) pygame.display.flip() # 判断位置是否合法 def is_legal_position(row, col): if row < 0 or row > 8 or col < 0 or col > 8: return False if board[row][col] != 0: return False return True # 落子函数 def place_piece(row, col, color): if not is_legal_position(row, col): return False board[row][col] = color draw_piece(row, col, color) return True # 判断是否有五子连珠 def is_win(color): for i in range(9): for j in range(9): if board[i][j] == color: if j+4 < 9 and board[i][j+1] == color and board[i][j+2] == color and board[i][j+3] == color and board[i][j+4] == color: return True if i+4 < 9 and board[i+1][j] == color and board[i+2][j] == color and board[i+3][j] == color and board[i+4][j] == color: return True if i+4 < 9 and j+4 < 9 and board[i+1][j+1] == color and board[i+2][j+2] == color and board[i+3][j+3] == color and board[i+4][j+4] == color: return True if i+4 < 9 and j-4 >= 0 and board[i+1][j-1] == color and board[i+2][j-2] == color and board[i+3][j-3] == color and board[i+4][j-4] == color: return True return False # 定义当前玩家颜色和落子状态 current_color = 1 is_placed = False # 游戏主循环 while True: # 处理事件 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() elif event.type == pygame.MOUSEBUTTONDOWN: x, y = event.pos row, col = y // GRID_SIZE, x // GRID_SIZE is_placed = place_piece(row, col, current_color) # 判断游戏是否结束 if is_win(current_color): print("游戏结束,{}方获胜!".format(current_color)) break if is_placed: current_color = 3 - current_color # 切换玩家 is_placed = False # 绘制棋盘和棋子 draw_board() for i in range(9): for j in range(9): if board[i][j] != 0: draw_piece(i, j, RED if board[i][j] == 1 else GREEN) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值