Matlab实现别踩白块小游戏的示例代码

目录
  • 游戏效果
  • 游戏说明
  • 完整代码
    • pianoKeys.m(主函数)
    • getMusic.m(用于获取音乐数据)

游戏效果

游戏说明

‘A’,‘S’,‘D’,F’按键代表四条通路(点击S开始),按错按钮或黑块接触底限均为失败。

完整代码

分两个m文件,应放在同一文件夹

pianoKeys.m(主函数)

function pianoKeys
%======================%========
[v1,notes,fs]=getMusic;%读取音乐
%======================%========

fig=uifigure;
fig.Position=[10 50 4*90 4*150];
fig.NumberTitle='off';
fig.MenuBar='none';
fig.Resize='off';
fig.Name='pianoKeys';

ax=uiaxes(fig);
ax.Position=[-22 -15 4*90+36 4*150+40];
ax.XLim=[0 4*90];
ax.YLim=[0 4*150];
ax.XColor=[0 0 0];
ax.YColor=[0 0 0];
ax.Box='on';
ax.XTick=0:90:360;
ax.YTick=[0 600];
ax.XGrid='on';
ax.GridColor=[0 0 0];
ax.GridAlpha=1;
ax.Toolbar.Visible='off';

%==========================================================================

blockList(1)=drawBlock(changeData(1),0,{'开始';'游戏'},v1{1});
noDeleteList=1:4;
newBlockY=600;
newBlockNum=5;
startFlag=0;
gameOver=0;
for i=2:4
    x=changeData(i);
    blockList(i)=drawBlock(x,(i-1)*150,'',v1{i});
end

%==========================================================================
set(fig,'KeyPressFcn',@keyPressFcn)
%==========================================================================
fps=10;
PKtimer=timer('ExecutionMode', 'fixedRate', 'Period',1/fps, 'TimerFcn', @pianoGame);
start(PKtimer)
%==========================================================================

function pianoGame(~,~)
    if startFlag
        if newBlockY<=600&&newBlockNum<=length(v1)
            tempX=changeData(newBlockNum);
            blockList(newBlockNum)=drawBlock(tempX,newBlockY,'',v1{newBlockNum});
            noDeleteList=[noDeleteList,newBlockNum];
            newBlockNum=newBlockNum+1;
            newBlockY=newBlockY+150;
        end
        for ii=noDeleteList
            blockList(ii).Position(2)=blockList(ii).Position(2)-150/8;
        end
        newBlockY=newBlockY-150/8;
        if (~isempty(noDeleteList))&&blockList(noDeleteList(1)).Position(2)<-10
            gameOverFcn(1);
            gameOver=1;
            %tempStr=blockList(noDeleteList(1)).UserData;
            %sound(notes.(tempStr),fs)
            %delete(blockList(noDeleteList(1)))
            %noDeleteList(1)=[];
        end
    end
end

    function gameOverFcn(coe)
        sound([notes.do0f,notes.do1f,notes.do2f,notes.do2f],fs)
        switch coe
            case 1
                blockList(noDeleteList(1)).BackgroundColor=[0.6 0 0];
                blockList(noDeleteList(1)).Text={'游戏';'失败'};
                startFlag=0;
            otherwise
                object=uilabel(fig);
                object.Text={'游戏';'失败'};
                object.Position=[coe,0+3-18.75,90,150];
                object.FontSize=26;
                object.FontWeight='bold';
                object.FontColor=[1 1 1];
                object.BackgroundColor=[0.6 0 0];
                object.HorizontalAlignment='center';

        end
    end

function keyPressFcn(~,event)
    switch event.Key
        case 'a',xPos=0+3;
        case 's',xPos=90+3;
        case 'd',xPos=180+3;
        case 'f',xPos=270+3;
        otherwise,xPos=-1;
    end
    if (~isempty(noDeleteList))&&blockList(noDeleteList(1)).Position(1)==xPos&&gameOver==0
        tempStr=blockList(noDeleteList(1)).UserData;
        sound(notes.(tempStr),fs)
        delete(blockList(noDeleteList(1)))
            if noDeleteList(1)==1
                startFlag=1;
            end
        noDeleteList(1)=[];
    elseif blockList(noDeleteList(1)).Position(1)~=xPos&&xPos~=-1&&gameOver==0&&startFlag==1
        startFlag=0;
        gameOverFcn(xPos);
        gameOver=1;
    end

end
%==========================================================================
    function x=changeData(sort)
        note=v1{sort};
        switch note(1)
            case 'd',x=0;
            case 'r',x=0;
            case 'm',x=90;
            case 'f',x=90;
            case 's',x=180;
            case 'l',x=180;
            case 't',x=270;
            case 'b',x=270;
        end
    end

    function object=drawBlock(x,y,string,note)
        object=uilabel(fig);
        object.Text=string;
        object.Position=[x+3,y+3,90,150];
        object.FontSize=26;
        object.FontWeight='bold';
        object.FontColor=[1 1 1];
        object.BackgroundColor=[0 0 0];
        object.HorizontalAlignment='center';
        object.UserData=note;
    end
end

getMusic.m(用于获取音乐数据)

function [v1,notes,fs]=getMusic
% Most shining national wind//最炫民族风 on Matlab
% The Modification is from "canon", not by me

fs = 44100; % sample rate
dt = 1/fs;

T16 = 0.125;

t16 = 0:dt:T16;
[~,k] = size(t16);

t4 = linspace(0,4*T16,4*k);
t8 = linspace(0,2*T16,2*k);

[~,i] = size(t4);
[~,j] = size(t8);

% Modification functions
mod4=(t4.^4).*exp(-30*(t4.^0.5));
mod4=mod4*(1/max(mod4));
mod8=(t8.^4).*exp(-50*(t8.^0.5));
mod8=mod8*(1/max(mod8));
mod16=(t16.^4).*exp(-90*(t16.^0.5));
mod16=mod16*(1/max(mod16));

f0 = 2*146.8; % reference frequency

ScaleTable = [2/3 3/4 5/6 15/16 ...
1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...
2 9/4 5/2 8/3 3 10/3 15/4 4 ...
1/2 9/16 5/8];

% 1/4 notes
notes.do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);
notes.re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);
notes.mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);

notes.fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);
notes.so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);
notes.la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);
notes.ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);
notes.do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);
notes.re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);
notes.mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);
notes.fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);
notes.so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);
notes.la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);
notes.tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);
notes.ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);
notes.do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);
notes.re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);
notes.mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);
notes.fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);
notes.so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);
notes.la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);
notes.ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);
notes.do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);
notes.blkf = zeros(1,i);

% 1/8 notes
notes.do0e = mod8.*cos(2*pi*ScaleTable(21)*f0*t8);
notes.re0e = mod8.*cos(2*pi*ScaleTable(22)*f0*t8);
notes.mi0e = mod8.*cos(2*pi*ScaleTable(23)*f0*t8);

notes.fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);
notes.so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);
notes.la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);
notes.ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);
notes.do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);
notes.re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);
notes.mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);
notes.fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);
notes.so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);
notes.la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);
notes.tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);
notes.ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);
notes.do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);
notes.re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);
notes.mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);
notes.fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);
notes.so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);
notes.la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);
notes.ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);
notes.do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);
notes.blke = zeros(1,j);

% 1/16 notes
notes.do0s = mod16.*cos(2*pi*ScaleTable(21)*f0*t16);
notes.re0s = mod16.*cos(2*pi*ScaleTable(22)*f0*t16);
notes.mi0s = mod16.*cos(2*pi*ScaleTable(23)*f0*t16);

notes.fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);
notes.so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);
notes.la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);
notes.ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);
notes.do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);
notes.re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);
notes.mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);
notes.fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);
notes.so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);
notes.la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);
notes.tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);
notes.ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);
notes.do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);
notes.re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);
notes.mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);
notes.fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);
notes.so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);
notes.la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);
notes.ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);
notes.do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);
notes.blks = zeros(1,k);

% Melody by Schau_mal
part0={'mi1f' 'la0e' 'la0e' 'do1f' 'mi1f' ...
're1e' 're1s' 'mi1s' 're1e' 'do1e' 're1e' 'do1e' 'la0f' ...
'mi1f' 'la0e' 'la0e' 'do1f' 'mi1f' ...
'so1e' 're1s' 'mi1s' 're1e' 'do1e' 're1e' 'do1e' 'ti0e' 'so0e' ...
'mi1f' 'la0e' 'la0e' 'do1f' 'mi1f' ...
're1e' 're1s' 'mi1s' 're1e' 'do1e' 're1e' 'do1e' 'la0e' 'so0e' ...
'mi1f' 'la0e' 'la0e' 'do1f' 'mi1f' ...
'so1e' 'mi1e' 'blkf' 'blkf' 'blkf' };

part1={'la0f' 'la0e' 'so0e' 'la0f' 'la0e' 'do1e' ...
'do1f' 're1e' 'do1e' 'la0f' 'la0f' ...
'do1f' 'do1e' 'so0e' 'do1e' 're1e' 'mi1e' 'so1e' ...
'so1e' 'mi1e' 're1f' 'mi1f' 'mi1f' ...
'la1e' 'la1e' 'la1e' 'so1e' 'mi1e' 'mi1f' 'do1e' ...
'la0e' 'la0e' 'la0e' 'mi1e' 're1s' 'mi1s' 're1e' 're1f' ...
'mi1e' 'mi1e' 'so1e' 'mi1e' 're1e' 'mi1e' 're1e' 'do1e' ...
'la0f' 'so0f' 'la0f' 'la0f' ...
};

part2={'mi1e' 'mi1e' 'so1e' 'mi1e' 'mi1e' 'so1e' 'so1e' 'la1e' ...
'do2e' 'la1e' 'so1f' 'la1s' 'do2s' 'la1e' 'la1f' ...
'la0f' 'la0e' 'so0e' 'la0f' 'do1f' ...
're1e' 'mi1s' 're1s' 'do1e' 're1e' 'mi1f' 'mi1f' ...
'la0e' 'la1e' 'la1e' 'so1e' 're1e' 'mi1s' 're1s' 'do1e' 're1e' ...
'mi1f' 'mi1f' 'blke' 'blke' 'blkf' ...
'do1e' 'la0e' 'la0e' 'do1e' 're1f' 'so0e' 'so0e' ...
'mi1e' 'so1e' 'mi1e' 're1e' 'do1f' 'do1f' ...
'la0e' 'do1e' 're1e' 'mi1e' 're1e' 'do1e' 'so0e' 'mi0e' ...
'la0f' 'la0f' 'blke' 'blke' 'blkf' ...
};

part3={'la0f' 'la0e' 'so0e' 'la0f' 'do1f' ...
're1e' 'mi1s' 're1s' 'do1e' 're1e' 'mi1f' 'mi1f' ...
'la0e' 'la1e' 'la1e' 'so1e' 're1e' 'mi1s' 're1s' 'do1e' 're1e' ...
'mi1f' 'mi1f' 'blke' 'blke' 'blkf' ...
'do1e' 'la0e' 'la0e' 'do1e' 're1f' 'so0e' 'so0e' ...
'mi1e' 'so1e' 'mi1e' 're1e' 'do1f' 'do1e' 'do1e' ...
'la0e' 'do1e' 're1e' 'mi1e' 'so1e' 'mi1e' 'mi1e' 'so1e' ...
'la1f' 'la1f' 'la1f' 'la1f' ...
};

part4={'la1e' 'la1s' 'la1s' 'la1e' 'la1e' 'la1e' 'la1s' 'so1s' 'mi1e' 're1e' ...
're1e' 're1s' 're1s' 'mi1e' 'mi1s' 'so1s' 'mi1e' 'mi1s' 're1s' 'do1e' 'do1s' 'la0s' ...
'la0f' 'la0e' 'so0e' 'la0f' 'la0e' 'do1e' ...
're1e' 'mi1s' 're1s' 'do1e' 're1e' 'mi1f' 'mi1f' ...
'la1e' 'so1e' 'mi1e' 're1e' 'so1e' 'mi1e' 're1e' 'do1e' ...
'do1f' 'do1f' 'la0s' 'do1s' 're1s' 'mi1s' 're1s' 'do1s' 'la0s' 'do1s'};

part5={'do2e' 'do2s' 'do2s' 'la1e' 'la1s' 'la1s' 'so1e' 'so1s' 'so1s' 'mi1e' 'mi1s' 'mi1s' ...
're1e' 'mi1s' 're1s' 'do1e' 'la0s' 'so0s' 'la0s' 'so0s' 'do1s' 're1s' 'mi1s' 'so1s' 'la1s' 're2s' ...
'do2f' 'do2f' 'blks' 'blks' 'blks' 'blks' 'do1e' 're1e' ...
'mi1f' 'mi1f' 'mi1f' 'so1e' 'mi1e' ...
'la1f' 'la1f' 'la1e' 'do1e' 'so1e' 'mi1e' ...
're1f' 're1e' 're1s' 're1s' 're1e' 're1e' 'do1e' 're1e' ...
'mi1f' 'mi1e' 'mi1s' 'mi1s' 'mi1e' 're1s' 'do1s' 'ti0e' 'do1s' 're1s' ...
'mi1f' 'mi1f' 'mi1f' 'so1e' 'mi1e' ...
'do2f' 'la1f' 'la1f' 'la1e' 'do1e' ...
're1f' 'so1f' 'so1f' 'la1f' ...
'ti1f' 'ti1f' 'ti1f' 'ti1f' ...
};

part6={'blkf' 'blkf' 'mi1e' 'so1e' 'mi1e' 'so1e' ...
'mi1f' 'la0e' 'la0s' 'la0s' 'do1f' 'la0e' 'mi1s' 'la0s' ...
'do1e' 'do1s' 'do1s' 're1e' 'do1s' 're1s' 'mi1f' 'mi1f' ...
'mi1f' 'la0e' 'la0s' 'la0s' 'so1f' 're1e' 're1s' 're1s' ...
'mi1f' 'mi1f' 'mi1s' 're1s' 'do1s' 'la0s' 'mi0s' 're0s' 'mi0s' 'so0s' ...
'do1f' 'la0e' 'la0s' 'la0s' 're1f' 'so0e' 'so0s' 'so0s' ...
'mi0f' 'so0e' 'so0s' 'so0s' 'do1f' 'do1f' ...
'la0f' 'do1e' 'do1s' 'la0s' 'mi1e' 'mi1s' 'mi1s' 're1e' 're1s' 'mi1s' ...
};

% Combination, v1 is complete version, v2 is simple version.
v1 = [part0 part1 part1 part2 part3 part4 part0 part1 part1 part2 part3 part5 part3 part6 part3];
%v2 = [part0 part1 part1 part2 part3 part5 part3 part6 part3];
end

到此这篇关于Matlab实现别踩白块小游戏的示例代码的文章就介绍到这了,更多相关Matlab别踩白块游戏内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Javascript别踩白块儿(钢琴块儿)小游戏实现代码

    游戏唯一的一个规则,我们只需要不断踩着黑色方块前进即可,这里根据方向键来踩白块 在规定时间内,每走一次分数加100 游戏内的每一排都是一个有四个元素的数组,当正确的踩到黑块前进后,前一个数组内所有的对象样式属性(backgroundColor)赋值给其后一个数组内的对应位置处的对象,便实现了前进的功能,很简单的思想 <!DOCTYPE html><html> <head lang="en"> <meta charset="UTF-8&

  • 原生JS实现《别踩白块》游戏(兼容IE)

    兼容了IE,每得20分就加速一次!!! 效果如下: 图(1) 游戏初始 图(2) 游戏开始 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> *{ margin: 0; padding: 0; } .box { margin: 50px auto 0 auto; width: 400px; height:

  • jQuery实现的别踩白块小游戏完整示例

    本文实例讲述了jQuery实现的别踩白块小游戏.分享给大家供大家参考,具体如下: 首先引入jquery.js 1.css html, body, .contain { width: 100%; height: 96%; overflow: hidden; background-color: #FFFFCC; } .text-center { text-align: center; } .score { font-size: 25px; color: #CB2D01; margin-top: 20

  • PyQt5实现类似别踩白块游戏

    本文实例为大家分享了PyQt5实现类似别踩白块游戏的具体代码,供大家参考,具体内容如下 #引入可能用到的库 from PyQt5.QtWidgets import (QWidget, QApplication,QPushButton,QMessageBox,QLabel,QDesktopWidget,QMainWindow) from PyQt5.QtCore import Qt,QRect,QSize,QPoint,QTimer from PyQt5.QtGui import QPainter

  • MATLAB实现五子棋游戏(双人对战、可悔棋)

    本文实例为大家分享了MATLAB实现五子棋游戏的具体代码,供大家参考,具体内容如下 程序介绍: 1.此游戏只可用于双人对战. 2.棋盘颜色.棋盘格数.棋子颜色等参数均可自由设置 3.鼠标点击非棋盘区域可悔棋. 一.游戏界面 二.主程序及函数 1.主程序 %Author:LeiZhen %Date:2018-03-12 %此程序只下五子棋,并判断胜负关系 clear all; clc %定义颜色 Color_QiPanBack=[135,206,255]; Color_ChessLine=[100

  • 如何利用Matlab制作一款真正的拼图小游戏

    效果: 简单原理介绍: 1构造0,1矩阵作为每片拼图的透明度,可以构造出不规则形状的拼图(image函数有alphaData属性可以设置) jigsawMask=zeros(101*5,101*5); jigsawMask(102:404,102:404)=1; [xMesh,yMesh]=meshgrid(1:101*5,1:101*5); dis1=sqrt((xMesh-51).^2+(yMesh-253).^2); dis2=sqrt((xMesh-505+50).^2+(yMesh-2

  • 利用Matlab制作一款3D版2048小游戏

    其实逻辑和2维版本完全一样,就不进行详细解说了,直接看效果: 效果: 目前界面还不咋好看,期待大家的优化 还是键盘↑↓←→操作嗷 完整代码: function game20483D global squaremap global colorlist global fontsizelist global baseX baseY baseZ global barHdl textHdl global txtBest txtScore global best fig=figure('units','pi

  • Matlab实现别踩白块小游戏的示例代码

    目录 游戏效果 游戏说明 完整代码 pianoKeys.m(主函数) getMusic.m(用于获取音乐数据) 游戏效果 游戏说明 ‘A’,‘S’,‘D’,F’按键代表四条通路(点击S开始),按错按钮或黑块接触底限均为失败. 完整代码 分两个m文件,应放在同一文件夹 pianoKeys.m(主函数) function pianoKeys %======================%======== [v1,notes,fs]=getMusic;%读取音乐 %=================

  • js实现一款简单踩白块小游戏(曾经很火)

    效果图如下所示: html <div class="bigbox"> <!-- 显示游戏的区域 --> <div class="gamequyu"> <!-- 上面显示一个游戏开始的按钮 --> <div class="start">游戏开始</div> <!-- 再显示一个游戏的主体部分 --> <div class="zhuti"&g

  • 使用jquery实现别踩白块小游戏的方法实例

    目录 前言 html 首页字体 中间的表格 实现每一行的黑块随机显示 按键事件 key事件 adds speedup 源码 总结 前言 掘金真的是太懂了,写游戏的活动,想不参加都难!第一个,别踩白块! 先来看效果~ 如上图所示,jkl三个键对应三列,左上是得分,得分右边是时间(没做倒计时...)敲击对应的按键来进行游戏,如果敲错了就会弹出得分与所用时间 接下来就开始肢解这个小游戏,来一步一步的分析究竟是怎么实现的,let's go~ html <body> <div class=&quo

  • Matlab实现贪吃蛇小游戏的示例代码

    由于老师说如果拿MATLAB制作出游戏或者有趣的动画的话.. 平时成绩可以拿满分 于是..开始尝试制作各种matlab小游戏 最初通过Alex的贪吃蛇学到了一些东西,然后制作了一个类似的俄罗斯方块在课堂上展示的(都是动的方块嗯哒). 后来自己也尝试写着玩了一些其他版本的贪吃蛇,并做出了一些改进. 补动图: 没错这就有点类似贪吃蛇大作战里的蛇啦 然后做出的改进包括: 在关闭窗口时不报错的设置,因为用了timer这个函数,在关闭图像时他会报错,我们就可以加入一个回调函数: set(gcf,'tag'

  • Python快速实现简易贪吃蛇小游戏的示例代码

    贪吃蛇(也叫做贪食蛇)游戏是一款休闲益智类游戏,有PC和手机等多平台版本.既简单又耐玩.该游戏通过控制蛇头方向吃蛋,从而使得蛇变得越来越长. 贪吃蛇游戏最初为单机模式,后续又陆续推出团战模式.赏金模式.挑战模式等多种玩法. 另外还有一种名为“贪吃蛇”钻井测井技术,是运用旋转导向系统.随钻测井系统等的油气田定向钻井.随钻测井技术,可完成海上“丛式井”和复杂油气层的开采需求,大幅降低油气田开发综合成本. 依然是基于pygame库,pip install pygame安装即可 完整代码如下: # 导入

  • C语言实现经典扫雷小游戏的示例代码

    目录 一.游戏简介 二.游戏实现 1.初始化棋盘 2.打印棋盘 3.布置雷 4.排查雷 三.源文件 1.game.h 2.game.c 3.Test.c 一.游戏简介 游戏初始界面有两个选择,选项“1”为开始游戏,选项“0”为退出游戏:选择开始游戏之后将会打印出9*9的棋盘,此时系统已经为游戏设置了10个雷,输入坐标之后将会打印出此坐标周围八个位置有几个雷,如果踩到了雷,那么游戏结束,打印出所有雷的位置. 二.游戏实现 1.初始化棋盘 void InitBoard(char board[ROWS

  • Java实现接月饼小游戏的示例代码

    目录 前言 主要设计 功能截图 代码实现 游戏启动类 核心类 画面绘制 总结 前言 <接月饼小游戏>是一个基于java的自制游戏,不要被月亮砸到,尽可能地多接月饼. 此小项目可用来巩固JAVA基础语法,swing的技巧用法. 主要设计 设计游戏界面,用swing实现 设计背景 设计得分物体-月饼,碰到加一分 设计障碍物-月亮,碰到会死亡 监听鼠标的左右键,用来控制篮子左右移动 设计积分系统 将resource文件夹设为resource(Project Manage中可以设置),因为要用里面的图

  • 基于Unity3D实现3D迷宫小游戏的示例代码

    目录 一.前言 二.构思 三.正式开发 3-1.搭建场景 3-2.设置出入口 3-3.添加角色 3-4.实现角色移动 3-5.出入口逻辑 四.总结 一.前言 闲来无事,从零开始整个<3D迷宫>小游戏. 本篇文章会详细介绍构思.实现思路,希望可以帮助到有缘人. 二.构思 首先,要实现一个小游戏,心里肯定要有一个大概的想法,然后就是将想法完善起来. 我的想法就是一个用立体的墙搭建的迷宫,然后控制人物在迷宫中移动,最后找到出口,就这么简单. 当然,这是一个雏形,比如可以加点音效.背景.关卡.解密等.

  • Vue实现红包雨小游戏的示例代码

    目录 0 写在前面 1 准备工作 2 设计HTML+CSS样式 3 设计JavaScript逻辑 4 完整代码 0 写在前面 红包也叫压岁钱,是过农历春节时长辈给小孩儿用红纸包裹的礼金.据传明清时期,压岁钱大多数是用红绳串着赐给孩子.民国以后,则演变为用红纸包裹.中国的红包传统民族文化在民间如此,社区.公司也奉行如仪.除了春节以外,在其他喜庆场合,例如婚礼.新店开张等亦有送红包的习俗. 本期迎新春专题用代码制作一个 红包雨小游戏 ,效果如下所示.看完本文相信你也可以完成这样一个小游戏设计. 1

随机推荐