html5游戏开发之-----祖玛小游戏<原创>

</pre><pre name="code" class="javascript">
</pre><pre name="code" class="javascript">
</pre><pre name="code" class="javascript">
/*祖玛小游戏相信很多人玩过,
		今天我尝试在html5的画布上尝试用js写了一个小游戏,
		开过过程的感悟是:
		遇到一堆代码的时候,应该首先得出一个整体的框架
		然后根据这个粗略的框架进行分块开发
		即使刚开始的时候毫无头绪
		也要即刻动手
		昨天在看jQuery源码的时候
		看着8千行的代码
		如果硬着头皮从第一行开始看
		保证过不了多久便放弃了
		正确的做法是
		从刚开始通读全文划分功能块
		先从简单的或者跟现有知识相关联的入手
		然后各个击破
		在每一个板块集中全部精力攻克
		不想其他的模块或者是整体
		这应该是模块化设计的东西吧
		这才是真理..........嘿嘿 */



<!DOCTYPE html>
		
	

<html>
	<head>
		<meta charset="UTF-8">
		
		<title></title>
		<style type="text/css">
		*{margin: 0; padding: 0;}
		body{background: black;}
		#div1{background:white; width: 600px; margin: 20px auto;}
		</style>
		<script type="text/javascript">
		window.οnlοad=function(){
			//加载画布
			var oC=document.getElementById('c1');
			var oGc=oC.getContext('2d');  //有这句话才能在画布上写东西
			var i=0;
			var iRotate=0; //青蛙旋转速度
			
			var yImg=new Image();  //加载青蛙
			
			yImg.src='img/person.
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的使用 C 语言实现的祖玛游戏代码示例,供您参考: ```c #include <stdio.h> #include <stdlib.h> #include <time.h> #define BALL_NUM 5 // 祖玛球颜色数 #define BALLS_PER_ROW 21 // 每行祖玛球的数量 // 定义祖玛球的颜色 enum BallColor { RED = 1, YELLOW, GREEN, BLUE, PURPLE }; // 定义祖玛球的结构体 typedef struct ball { int color; struct ball* prev; struct ball* next; } Ball; // 初始化祖玛球链表 void initBalls(Ball** head, Ball** tail) { *head = (Ball*)malloc(sizeof(Ball)); *tail = (Ball*)malloc(sizeof(Ball)); (*head)->prev = NULL; (*head)->next = *tail; (*tail)->prev = *head; (*tail)->next = NULL; } // 在祖玛球链表尾部插入新球 void insertBall(Ball* tail, int color) { Ball* ball = (Ball*)malloc(sizeof(Ball)); ball->color = color; ball->prev = tail->prev; ball->next = tail; tail->prev->next = ball; tail->prev = ball; } // 生成随机的祖玛球 int getRandBall() { return rand() % BALL_NUM + 1; } // 打印祖玛球链表 void printBalls(Ball* head) { Ball* p = head->next; while (p->next != NULL) { printf("%d ", p->color); p = p->next; } printf("\n"); } // 删除祖玛球链表中的连续球 int removeBalls(Ball* head, Ball* tail) { int cnt = 0; Ball* p = head->next; Ball* q = p; while (p->next != NULL) { if (p->color == p->next->color) { cnt++; } else { if (cnt >= 2) { while (cnt--) { Ball* tmp = q; q = q->next; q->prev = tmp->prev; tmp->prev->next = q; free(tmp); } head->next = q; p = q; cnt = 0; } else { q = p->next; cnt = 0; p = p->next; } } } if (cnt >= 2) { while (cnt--) { Ball* tmp = q; q = q->next; q->prev = tmp->prev; tmp->prev->next = q; free(tmp); } head->next = q; } return cnt; } // 插入新的祖玛球序列 void insertBalls(Ball* head, Ball* tail) { int cnt = 0; Ball* p = head->next; while (p->next != NULL) { cnt++; p = p->next; } while (cnt < BALLS_PER_ROW) { insertBall(tail, getRandBall()); cnt++; } } // 判断是否游戏结束 int isGameOver(Ball* head, Ball* tail) { Ball* p = head->next; while (p->next != NULL) { if (p->color == p->next->color) { return 0; } p = p->next; } return 1; } // 主函数 int main() { srand(time(NULL)); Ball* head, * tail; initBalls(&head, &tail); int score = 0; insertBalls(head, tail); while (1) { printf("当前得分:%d\n", score); printf("祖玛球序列:"); printBalls(head); int index; printf("请选择要发射的祖玛球颜色(1-5):"); scanf("%d", &index); if (index < 1 || index > 5) { printf("输入错误,请重新选择!\n"); continue; } Ball* p = tail->prev; while (p != head) { if (p->color == index) { break; } p = p->prev; } if (p == head) { printf("发射的祖玛球颜色不存在,请重新选择!\n"); continue; } Ball* q = p; while (q->next != tail && q->next->color == p->color) { q = q->next; } Ball* newBall = (Ball*)malloc(sizeof(Ball)); newBall->color = index; newBall->prev = q; newBall->next = q->next; q->next->prev = newBall; q->next = newBall; int cnt = removeBalls(head, tail); if (cnt > 0) { score += cnt; } insertBalls(head, tail); if (isGameOver(head, tail)) { printf("游戏结束!\n"); printf("最终得分:%d\n", score); break; } } return 0; } ``` 上述代码实现了一个简单的祖玛游戏,包括初始化祖玛球链表、插入新球、打印祖玛球链表、删除连续球、插入新的祖玛球序列、判断是否游戏结束等功能。您可以根据需要进行修改和扩展。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值