C++实现推箱子小游戏源码

本文实例为大家分享了C++实现推箱子小游戏的具体代码,供大家参考,具体内容如下

功能尚为完善。

// ConsoleApplication2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
#include<windows.h>
#define KEY_DOWN(vk_code) GetAsyncKeyState(vk_code) & 0x8000 ? 1 : 0
using namespace std;

void Map();
void PlayerMove();
void Menu();
void BoxMove();

//extern int Array[15][20];
//定义菜单状况
int nMenuState = 1;
//定义选关设置
int nSetState = 1;
//定义关卡状态
int PassState = 1;
//定义选关情况
bool bslect = false;

int Array1[15][20] = {
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
};
int Array2[15][20] = {
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
};
int Array3[15][20] = {
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1 },
 { 1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,1 },
 { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
};
int Array[15][20] = {};

struct Player {
 int P_row;
 int P_col;
 int P_rowBk;
 int P_colBk;
 Player() {
 P_row = 0;
 P_col = 0;
 P_rowBk = 0;
 P_colBk = 0;
 }
 Player(int x = 10, int y = 10) {
 P_row = x;
 P_col = y;
 P_rowBk = x;
 P_colBk = y;
 }
 void BackUp() {
 P_rowBk = P_row;
 P_colBk = P_col;
 }
 void restore() {
 P_row = P_rowBk;
 P_col = P_colBk;
 }
};
//Player splayer(1, 1); //初始化玩家坐标
Player splayer = {1,1};

struct Box {
 int box_x;
 int box_y;
 int box_xx;//用来备份坐标
 int box_yy;
 Box() {
 box_x = 0;
 box_y = 0;
 box_xx = 0;
 box_yy = 0;
 }
 Box(int x = 10, int y = 10) {
 box_x = x;
 box_y = y;
 box_xx = box_x;
 box_yy = box_y;
 }
 void BackUp() {
 box_xx = box_x;
 box_yy = box_y;
 }
 void restore() {
 box_x = box_xx;
 box_y = box_yy;
 }
};
//第一关箱子坐标初始化
Box sbox[3] = {
 { 5,5 },
 { 6,6 },
 { 7,7 }
};

//坑结构体
struct Destinate {
 int Des_x;
 int Des_y;
 Destinate(int a, int b) {
 Des_x = a;
 Des_y = b;
 }
};
Destinate sdestinate[3] = {
 { 8,8 },
 { 9,9 },
 { 10,10 }
};

//选关设置
void SetChoise() {
 while (1) {
 system("cls");
 if (KEY_DOWN(VK_UP)) {
 //cout << "向上被按下" << endl;
 --nSetState;
 if (nSetState < 1) { nSetState = 3; }
 }
 if (KEY_DOWN(VK_DOWN)) {
 //cout << "向下被按下" << endl;
 ++nSetState;
 if (nSetState > 3) { nSetState = 1; }
 }

 switch (nSetState) {
 case 1: cout << "********游戏选关设置********" << endl;
 cout << " -> 1、关卡一" << endl;
 cout << "  2、关卡二" << endl;
 cout << "  3、关卡三" << endl;
 system("pause");
 break;
 case 2: cout << "********游戏选关设置********" << endl;
 cout << "  1、关卡一" << endl;
 cout << " -> 2、关卡二" << endl;
 cout << "  3、关卡三" << endl;
 system("pause");
 break;
 case 3: cout << "********游戏选关设置********" << endl;
 cout << "  1、关卡一" << endl;
 cout << "  2、关卡二" << endl;
 cout << " -> 3、关卡三" << endl;
 system("pause");
 break;
 }
 if (KEY_DOWN(VK_RETURN)) {
 if (1 == nSetState) {
 memcpy(Array, Array1, sizeof(Array));
 splayer.P_row = 1;
 splayer.P_col = 1;
 PassState = 1;
 for (int i = 0; i < 3; i++) {
  sbox[i].box_x = 5 + i;
  sbox[i].box_y = 5 + i;
  sdestinate[i].Des_x = 8 + i;
  sdestinate[i].Des_y = 8 + i;
 }
 }
 else if (2 == nSetState) {
 memcpy(Array, Array2, sizeof(Array));
 splayer.P_row = 1;
 splayer.P_col = 1;
 PassState = 2;
 for (int i = 0; i < 3; i++) {
  sbox[i].box_x = 5 + i;
  sbox[i].box_y = 5 + i;
  sdestinate[i].Des_x = 3 + i;
  sdestinate[i].Des_y = 3;
 }
 }
 else if (3 == nSetState) {
 memcpy(Array, Array3, sizeof(Array));
 splayer.P_row = 1;
 splayer.P_col = 1;
 PassState = 3;
 memcpy(Array, Array3, sizeof(Array));
 for (int i = 0; i < 3; i++) {
  sbox[i].box_x = 10;
  sbox[i].box_y = 7 + i;
  sdestinate[i].Des_x = 2 + i;
  sdestinate[i].Des_y = 2;
 }
 }
 bslect = true;
 break;
 }
 }
}
//判断玩家移动
void PlayerMove() {
 splayer.BackUp();
 if (KEY_DOWN(VK_UP)) {
 --splayer.P_row;
 }
 if (KEY_DOWN(VK_DOWN)) {
 ++splayer.P_row;
 }
 if (KEY_DOWN(VK_LEFT)) {
 --splayer.P_col;
 }
 if (KEY_DOWN(VK_RIGHT)) {
 ++splayer.P_col;
 }
 if (1 == Array[splayer.P_row][splayer.P_col]) {//判断玩家是否越墙
 splayer.restore();
 }
}
//判断箱子移动
void BoxMove() {
 for (int i = 0; i < 3; i++) {
 sbox[i].BackUp();
 }
 int skew_x = 0; //临时偏移量
 int skew_y = 0;
 for (int s = 0; s < 3; s++) { //利用坐标偏移量求箱子新位置
 if (splayer.P_row == sbox[s].box_x && splayer.P_col == sbox[s].box_y) {
 skew_x = sbox[s].box_x - splayer.P_rowBk;
 skew_y = sbox[s].box_y - splayer.P_colBk;
 sbox[s].box_x = sbox[s].box_x + skew_x;
 sbox[s].box_y = sbox[s].box_y + skew_y;
 /*sbox[s].restore();*/
 }
 }
 for (int a = 0; a < 3; a++) {
 for (int b = 0; b < 3; b++) {
 if (a != b && (sbox[a].box_x == sbox[b].box_x && sbox[a].box_y == sbox[b].box_y)) {
 splayer.restore();
 sbox[a].restore();
 }
 }
 }
 for (int s = 0; s < 3; s++) { //判断箱子是否越界
 if (1 == Array[sbox[s].box_x][sbox[s].box_y]) {
 splayer.restore();
 sbox[s].restore();
 }
 }
}

//判断胜利
void JudgeWin() {
 int nCorrectNum = 0; //判断箱子推到正确位置的数量
 for (int i = 0; i < 3; i++) {
 for (int j = 0; j < 3; j++) {
 if (sdestinate[i].Des_x == sbox[j].box_x && sdestinate[i].Des_y == sbox[j].box_y) {
 ++nCorrectNum;
 break;
 }
 }
 if (3 <= nCorrectNum) {
 //system("cls");
 cout << "You Win!" << endl;
 ++PassState;
 if (2 == PassState) {
 memcpy(Array, Array2, sizeof(Array));
 //更新玩家位置
 splayer.P_row = 1;
 splayer.P_col = 1;
 //更新箱子和坑状态
 for (int i = 0; i < 3; i++) {
  sbox[i].box_x = 5 + i;
  sbox[i].box_y = 5 + i;
  sdestinate[i].Des_x = 3 + i;
  sdestinate[i].Des_y = 3;
 }
 }
 if (3 == PassState) {
 splayer.P_row = 1;
 splayer.P_col = 1;
 memcpy(Array, Array3, sizeof(Array));
 for (int i = 0; i < 3; i++) {
  sbox[i].box_x = 10;
  sbox[i].box_y = 7 + i;
  sdestinate[i].Des_x = 2 + i;
  sdestinate[i].Des_y = 2;
 }
 }

 //system("pause");
 break;
 }
 /*system("pause");*/
 }

}

//打印游戏菜单
void Menu() {
 if (KEY_DOWN(VK_UP)) {
 //cout << "向上被按下" << endl;
 --nMenuState;
 if (nMenuState < 1) { nMenuState = 3; }
 }

 if (KEY_DOWN(VK_DOWN)) {
 //cout << "向下被按下" << endl;
 ++nMenuState;
 if (nMenuState > 3) { nMenuState = 1; }
 }

 switch (nMenuState) {
 case 1: system("cls");
 cout << "********游戏界面菜单********" << endl;
 cout << " -> 1、游戏开始" << endl;
 cout << "  2、游戏设置" << endl;
 cout << "  3、退出游戏" << endl << endl;
 cout << " ->按小键盘↑↓←→移动<- " << endl;
 cout << " ->按F1 F2 F3可切换关卡<- " << endl;
 system("pause");
 break;
 case 2: system("cls");
 cout << "********游戏界面菜单********" << endl;
 cout << "  1、游戏开始" << endl;
 cout << " -> 2、游戏设置" << endl;
 cout << "  3、退出游戏" << endl << endl;
 cout << " ->按小键盘↑↓←→移动<- " << endl;
 cout << " ->按F1 F2 F3可切换关卡<- " << endl;
 system("pause");
 break;
 case 3: system("cls");
 cout << "********游戏界面菜单********" << endl;
 cout << "  1、游戏开始" << endl;
 cout << "  2、游戏设置" << endl;
 cout << " -> 3、退出游戏" << endl << endl;
 cout << " ->按小键盘↑↓←→移动<- " << endl;
 cout << " ->按F1 F2 F3可切换关卡<- " << endl;
 system("pause");
 break;
 }
}

void Map() {
 while (1) {
 system("cls");
 PlayerMove();
 BoxMove();
 JudgeWin();
 if (4 == PassState) {
 cout << "恭喜通关" << endl;
 PassState = 1;
 memcpy(Array, Array1, sizeof(Array));
 //更新玩家位置
 splayer.P_row = 1;
 splayer.P_col = 1;
 //更新箱子和坑状态
 for (int i = 0; i < 3; i++) {
 sbox[i].box_x = 5 + i;
 sbox[i].box_y = 5 + i;
 sdestinate[i].Des_x = 8 + i;
 sdestinate[i].Des_y = 8 + i;
 }
 system("pause");
 break;
 }
 if (KEY_DOWN(VK_F1)) {
 memcpy(Array, Array1, sizeof(Array));
 PassState = 1;
 //更新玩家位置
 splayer.P_row = 1;
 splayer.P_col = 1;
 //更新箱子和坑状态
 for (int i = 0; i < 3; i++) {
 sbox[i].box_x = 5 + i;
 sbox[i].box_y = 5 + i;
 }
 }
 if (KEY_DOWN(VK_F2)) {
 memcpy(Array, Array2, sizeof(Array));
 PassState = 2;
 //更新玩家位置
 splayer.P_row = 1;
 splayer.P_col = 1;
 //更新箱子和坑状态
 for (int i = 0; i < 3; i++) {
 sbox[i].box_x = 3 + i;
 sbox[i].box_y = 5;
 sdestinate[i].Des_x = 3 + i;
 sdestinate[i].Des_y = 3;
 }
 }
 if (KEY_DOWN(VK_F3)) {
 memcpy(Array, Array3, sizeof(Array));
 PassState = 3;
 //更新玩家位置
 splayer.P_row = 1;
 splayer.P_col = 1;
 //更新箱子和坑状态
 for (int i = 0; i < 3; i++) {
 sbox[i].box_x = 10;
 sbox[i].box_y = 7 + i;
 sdestinate[i].Des_x = 2 + i;
 sdestinate[i].Des_y = 2;
 }
 }
 //打印地图
 for (int i = 0; i < 15; i++) {
 for (int j = 0; j < 20; j++) {
 bool bDrawBox = false; //判断箱子
 for (int m = 0; m < 3; m++) {
  if (i == sbox[m].box_x && j == sbox[m].box_y) {
  bDrawBox = true;
  break;
  }
 }
 bool bDrawDes = false; //判断坑
 for (int m = 0; m < 3; m++) {
  if (i == sdestinate[m].Des_x && j == sdestinate[m].Des_y) {
  bDrawDes = true;
  break;
  }
 }
 if (1 == Array[i][j]) {
  cout << "■";
 }
 else if (i == splayer.P_row && j == splayer.P_col) {
  cout << "♀";
 }
 else if (true == bDrawBox) { //将true放在前面,不然出现全是箱子都不知道怎么错的……
  cout << "箱";
 }
 else if (true == bDrawDes) {
  cout << "坑";
 }
 else {
  cout << " ";
 }
 }
 cout << endl;
 }
 system("pause");
 }
}

int _tmain(int argc, _TCHAR* argv[])
{
 memcpy(Array, Array1, sizeof(Array));
 while (1) {
 //if (KEY_DOWN(VK_RETURN)){
 // if (1 == nMenuState) {
 // Map();
 // }
 // else if (2 == nMenuState) {
 // SetChoise();
 // /* cout << "wwww";
 // system("pause");*/
 // }
 // else if (3 == nMenuState)
 // return 0;
 //}
 if (3 == nMenuState && KEY_DOWN(VK_RETURN)) { //可以
 return 0;
 }
 else if (2 == nMenuState && KEY_DOWN(VK_RETURN)) {
 SetChoise();
 if (bslect) {
 Map();
 }
 }
 else if (1 == nMenuState && KEY_DOWN(VK_RETURN)) {
 Map();
 }
 //if (KEY_DOWN(VK_RETURN) && 3 == nMenuState) { //KEY_DOWN(VK_RETURN)不能进行与或运算 ??
 // return 0;
 //}
 //else if (KEY_DOWN(VK_RETURN) && 1 == nMenuState) {
 // Map();
 //}
 else {
 Menu();
 }
 }
 //Map();
 system("pause");
 return 0;
}

代码效果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • C/C++仿华容道小游戏

    本文实例介绍了C++模仿华容道小游戏实现代码,分享给大家供大家参考,具体内容如下 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <stdbool.h> #define maxnum 16 #define colnum 4 bool numexists(int *numbers, int length, int num); int getnumber(int **number

  • C++实现产生随机数和相应的猜拳小游戏实例代码

    一.简介 c++中,产生随机数的通用方法就是调用 srand()和 rand()  函数. Rand 单纯的rand()会返回一个0至RAND_MAX之间的随机数值,而RAND_MAX的值与int位数有关,最小是32767.不过rand()是一次性的,因为系统默认的随机数种子为1,只要随机数种子不变,其生成的随机数序列就不会改变. 其实,对于rand()的范围,我们是可以进行人为设定的,只需要在宏定义中定义一个random(int x)函数,就可以生成范围为0至x的随机数值.当然,也可以定义为r

  • 用VC++6.0的控制台实现2048小游戏的程序

    首先感谢这位大侠的无私分享,仔细学习这个程序以后收获很多,试着添加一些注释 源程序是从开源中国看到的,原作者是 刘地(sir?) 地址为http://www.oschina.net/code/snippet_593413_46040 geek_monkey于2015年3月5日为拜读该程序,受益匪浅 为了方便自己,以及更多初学者阅读,我试着写了写了注释供参考 我是C语言初学者,如有错误希望指正.轻喷 复制代码 代码如下: #include <stdlib.h> #include <stdi

  • C++小游戏BrickHit实例代码

    打砖块小游戏.材料:EasyX图形库. 碰撞的处理,木板移动方法还需要优化. //定义 Circle,Brick,Broad #include<cmath> #include<graphics.h> #ifndef _PROPERTY_H_ #define _PROPERTY_H_ struct Circle { int x0, y0, r; int mvX, mvY; COLORREF color; virtual ~Circle() {} Circle(int x0_, int

  • C++基于控制台实现的贪吃蛇小游戏

    本文实例讲述了C++基于控制台实现的贪吃蛇小游戏.分享给大家供大家参考.具体实现方法如下: #include <windows.h> #include <time.h> #include <stdio.h> #define MAX 100 #define UP 1 #define DOWN 2 #define LEFT 3 #define RIGHT 4 #define MOVING 5 #define STOP 0 HANDLE hMain_Out = NULL; H

  • C++面向对象实现五子棋小游戏

    尽量将面向对象的思想融入进程序中 ChessBoard.h //ChessBoard.h #pragma once #define ROW 15 #define COL 15 #include<iostream> using namespace std; class ChessBoard//棋盘类 { public: char m_cSquare[ROW][COL]; public: ChessBoard(); void show(); }; ChessBoard.cpp //ChessBoa

  • C++实现推箱子小游戏源码

    本文实例为大家分享了C++实现推箱子小游戏的具体代码,供大家参考,具体内容如下 功能尚为完善. // ConsoleApplication2.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include<windows.h> #define KEY_DOWN(vk_code) GetAsyncKeyState(vk_code) & 0x8000 ? 1 : 0 using

  • C语言代码实现推箱子小游戏

    本文实例为大家分享了C语言实现推箱子小游戏的具体代码,供大家参考,具体内容如下 本次游戏是个推箱子第一关最简单的小游戏 有详细注释,下面是做出来的游戏界面 游戏操作说明和功能说明: 1.按wasd控制小人的上下左右移动. 2.按 r 重新开始游戏 3.游戏开始有操作介绍 4.游戏结束有胜利提示 游戏原理分析 1.游戏开始时的星星个数 = 箱子在星星上的个数时 , 游戏胜利. 2.按 r 键重新开始游戏, 我们需要定义一个量 map_1[8][8] 来保存游戏初始时的界面, 操作时我们将其赋值给

  • jQuery网页版打砖块小游戏源码分享

    这是一款基于jQuery实现网页版打砖块小游戏源码,满满的童年回忆. 为大家分享的jQuery实现网页版打砖块小游戏源码如下 效果演示 源码下载 <!DOCTYPE html> <html lang="en" > <head> <meta charset="gb2312" /> <title>jQuery网页版打砖块小游戏源码</title> <link href="css/ma

  • Java编程经典小游戏设计-打砖块小游戏源码

    [程序中使用的数据结构和符号说明] HitBrick类 GreenBallThread控制小球路线 xUp,yUp,bouncing定义变量存储16位数值形式 x,y小球坐标 xDx,yDy坐标增量 MAX_X,MAX_Y坐标最大值 renew初始化 label标签 Rx,Ry横板坐标 Brick[]砖块 ball小球 HitBrick()定义小球横板及砖块位置坐标 keyPressd(keyEent)定义小球启动键(按空格键启动) keyReleased(keyEvent)接收键盘事件侦听器接

  • js推箱子小游戏步骤代码解析

    推箱子小游戏大家肯定都玩过,之所以写这篇文章,是觉得这个小游戏足够简单好理解 demo: 步骤解析: 本文代码已经放在了github上面了,里面也进行了很详细的代码注释,可以copy下来,在本地运行一下看看. 1. 渲染地图 html结构: html结构十分简单,只要弄一堆div,来放置地图的class就可以了,我这里初始化了12*9个div,地图里最多九行高度. 这些div都是同样大小,地图渲染出来区别的只是颜色的不同. 地图函数: var box=$('.box div'); //地图使用的

  • DEVC++实现推箱子小游戏

    推箱子小游戏(基于DEVC++),供大家参考,具体内容如下 #include<iostream> #include<stdio.h> #include<conio.h> #include <windows.h> using namespace std; void Game_Menu(HANDLE hout); void Game_description(HANDLE hout); void gotoxy(HANDLE hout, int x, int y);

  • linux实现猜数字小游戏源码

    一个简单的linux猜数字小游戏源码 游戏规则: 猜数字游戏通常由两个人玩,一方出数字,一方猜.出数字的人要想好一个没有重复数字的 4 个数,不能让猜的人知道.猜的人就可以开始猜.每猜一个数字,出数者就要根据这个数字给出几 A 几 B,其中 A 前面的数字表示位置正确的数的个数,而 B 前的数字表示数字正确而位置不对的数的个数.如正确答案为 5234,而猜的人猜 5346,则是 1A2B,其中有一个 5 的位置对了,记为 1A,而 3 和 4 这两个数字对了,而位置没对,因此记为 2B,合起来就

  • java二维数组实现推箱子小游戏

    本文实例为大家分享了java实现推箱子小游戏的具体代码,供大家参考,具体内容如下 二维数组 二维数组:类似于二维表格(有很多层,每一层有多个房间的楼房) 数组声明: 数据类型[][]数据名 = new 数据类型[行数][列数]; 获取二维数组的长度:数组名.lengt 得到的是行数 数组名[行下标].length 得到的是列数 推箱子小游戏 import java.util.Random; import java.util.Scanner; /* * 推箱子的小游戏 */ public clas

  • C++实现推箱子小游戏

    本文实例为大家分享了C++实现推箱子小游戏的具体代码,供大家参考,具体内容如下 游戏效果 简单易懂的推箱子闯关小游戏. 游戏代码 #include <bits/stdc++.h> #include <windows.h> #include <conio.h> using namespace std; #define VERSION "2.2" #define M 55 int n, m, wall[M][M], hole[M][M], box[M][

  • java实战之飞机大战小游戏(源码加注释)

    一.工程文件 二.Main.java 主函数,实现类 package ui; //主函数实现 public class Main { public static void main(String[] args) { //创建窗体 GameFrame frame = new GameFrame(); //创建面板 GamePanel panel = new GamePanel(frame); //调用开始游戏的方法启动游戏 panel.action(); //将面板加入到窗体中 frame.add

随机推荐