-
简易游戏 2048 制作
- // Matrix.h
- #ifndef MATRIX_H
- #define MATRIX_H
-
- #include<iostream>
- #include<time.h>
- #include<stdlib.h>
-
- #define rows 4
- #define cols 4
- #define L 6
-
- using std::ostream;
-
- classMatrix{
- friend ostream&operator<<(ostream& out,constMatrix& matirx);
- // here is an output example
- // -----------------------------
- // | 16| 8| 4| 2|
- // | 8 | 8| 4| 2|
- // | | 4| 8| 2|
- // | | | 2| 2|
- // -----------------------------
- public:
- Matrix(int p1,int p2);
- bool moveLeft();// return true if the matrix changes
- bool moveRight();// return true if the matrix changes
- bool moveUp();// return true if the matrix changes
- bool moveDown();// return true if the matrix changes
- bool add(int p);// return true if the matrix changes
- void update2(){// add a 2 to a random position
- srand((unsigned)time(NULL));
- unsignedint seed;
- while(true){
- int n = rand_r(&seed)%(rows*cols);
- if(add(n))
- return;
- }
- }
-
- private:
- int num[rows][cols];
- };
-
- #endif
// Matrix.cpp
-
相关阅读:
SQL Server 存储过程
SQL数据类型介绍
XML文件操作指南
C# 程序集 与 反射
详解C#中System.IO.File类和System.IO.FileInfo类的用法
C# 之泛型详解
C#中HashTable的用法示例2
C#中HashTable的用法示例1
DEDECMS5.7 首页和栏目页调用文章按权重排序
linux创建用户,指定组
-
原文地址:https://www.cnblogs.com/sysu-zhengwsh/p/3717892.html
Copyright © 2020-2023
润新知