C#“猜猜看”——物联网工程1122 黄炜彬
2015-07-07 17:16
330 查看
本次猜猜看游戏是基于Unity 3D平台进行开发,采用C scripts编写游戏脚本语言。
主要代码如下:
![](http://img.blog.csdn.net/20150707171955337?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20150707172034307?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](http://img.blog.csdn.net/20150707172051341?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
作业下载连接:http://pan.baidu.com/s/1i3eWmYp
主要代码如下:
using UnityEngine; using System.Collections; using UnityEngine.UI; public class ChangeImage : MonoBehaviour { public Text name; public Image image1; public Image image2; public Image image3; //三个用来接收图片号的数 static int a; static int b; static int c; static int d; string[] name2 = {"傻蛋","鸭蛋","茶叶蛋","熊蛋包儿","大混蛋","恐龙蛋", "荷包蛋","小笨蛋","狗蛋儿","小丸子","小黄人", "伊利莎白","皮卡丘","多啦A梦","路飞","维尼" }; public Sprite[] sprite; //Random r = new Random(); void Start() { Change_Images(); } public void Change_Images() { //产生的三个数 int []result2 = RandomNum(16); a = result2[0]; b = result2[1]; c = result2[2]; //随机取出三个名字中的一个 int[] num = new int[3]{ a, b, c }; System.Random f = new System.Random(); d = num[f.Next(3)]; name.text = name2[d]; //显示图片 image1.overrideSprite = sprite[a]; image2.overrideSprite = sprite[b]; image3.overrideSprite = sprite[c]; Debug.Log(a); Debug.Log(b); Debug.Log(c); Debug.Log("图片名字为" + d); } //判断图片是否对应 public void Click_button1() { Debug.Log(a); int a1 = a; if (a1 == d) { Debug.Log("猜对了"); //Change_Images(); Application.LoadLevel(1); } else { Application.LoadLevel(2); Debug.Log("猜错了"); } } public void Click_button2() { Debug.Log(b); int b1 = b; if (b1 == d) { Debug.Log("猜对了"); Application.LoadLevel(1); } else { Debug.Log("猜错了"); Application.LoadLevel(2); } } public void Click_button3() { Debug.Log(c); int c1 = c; if (c1 == d) { Debug.Log("猜对了"); Application.LoadLevel(1); } else { Debug.Log("猜错了"); Application.LoadLevel(2); } } //产生不重复的随机数 public static int[] RandomNum(int length) { int[] index = new int[16]; for (int i = 0; i < 15; i++) index[i] = i; //接收产生结果的数组 int[] result = new int[3]; int site = 16; int id; for (int j = 0; j < 3; j++) { id = Random.Range(1, site - 1); result[j] = index[id]; index[id] = index[site - 1]; site--; } return result; } }切换场景代码:
using UnityEngine; using System.Collections; public class BacktoMain : MonoBehaviour { public void Back_to_Main() { Application.LoadLevel(0); } }游戏运行演示:
作业下载连接:http://pan.baidu.com/s/1i3eWmYp
相关文章推荐
- linux iotop安装
- linux iotop安装
- 用AudioTrack进行音频录制传输
- Wind River Opens IoT Marketplace for VxWorks OS
- 物联网WiFi/BT/ZigBee芯片
- 『智能物联网』QQ群 419130936
- 物联网操作系统HelloX开发者入门指南
- 物联网操作系统HelloX开发者入门指南
- 物联网操作系统HelloX开发者入门指南
- Google输了官司,物联网恐怕也不能用Java了吧
- ARM--mbed物联网操作系统------初探
- 嵌入式物联网开发平台解读---之RTOS
- 物联网探步--工具篇之安装qvb
- 使用AudioTrack进行音频播放
- 【HDU 4609】3-idiots(FFT)
- iotop源码分析一
- 物联网系统的搭建(十)
- 物联网系统的搭建(九)
- 物联网系统的搭建(八)
- 物联网系统的搭建(七)