2048 of the command line, 2048 of the command line

Source: Internet
Author: User

2048 of the command line, 2048 of the command line
Command Line 2048What is the implementation of a 2048 fire game in command line? I tried it. Here I would like to thank the css gods for debugging. There is also the special character used in the game space, so the program may run garbled characters in linux. you can adjust it manually.
Games:









Code:

# Include <iostream> # include <ctime> # include <cstdlib> # include <cstring> # include <conio. h> # include <cstdlib> # include <windows. h> # define Coord_x 15 # define Coord_y 15 # define Height 20 # define Width 16 using namespace std; class Game {public: int score; int num [5] [5]; public: Game (int s = 0); bool control (char ch); void init (); void make ();} G; class Console {public: void gotoxy (HANDLE hOut, int x, int y ); Void enter_game (); void window (); void show (); void start_game (); void end_game (); friend class Game;} C; Game: Game (int s) {score = s; memset (num, 0, sizeof (num);} void Console: gotoxy (HANDLE hOut, int x, int y) {COORD pos; pos. X = x; pos. Y = y; SetConsoleCursorPosition (hOut, pos);} void Console: enter_game () {HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); HANDLE handle = GetStdHandle (STD_OUTPUT_HANDL E); system ("title 2048 by Tc"); gotoxy (hOut, Coord_x + Width-1, Coord_y-12); SetConsoleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN ); cout <"Welcome to 2 0 4 8"; SetConsoleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN); gotoxy (hOut, Coord_x + Width-25, Coord_y-8 ); cout <"********" <endl; gotoxy (hOut, Coord_x + Width-25, Coord_y-7); cout <"****** ** "<Endl; gotoxy (hOut, Coord_x + Width-25, Coord_y-6); cout <" ******** "<endl; gotoxy (hOut, Coord_x + Width-25, Coord_y-5); cout <"******" <endl; gotoxy (hOut, Coord_x + Width-25, coord_y-4); cout <"************" <endl; gotoxy (hOut, Coord_x + Width-25, Coord_y-3 ); cout <"******" <endl; gotoxy (hOut, Coord_x + Width-25, Coord_y-2 ); cout <"********" <endl; g Otoxy (hOut, Coord_x + Width-25, Coord_y-1); cout <"***********" <endl; gotoxy (hOut, coord_x + Width + 1, Coord_y + 3); SetConsoleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_RED); cout <"press enter to enter GAME \ n" <endl; while (1) {char c; if (kbhit () {c = getch (); if (c = 13) {system ("CLS"); C. start_game () ;}}if (getch () = 27) {C. end_game () ;}} void Console: end_game () {HANDLE handle = Get StdHandle (STD_OUTPUT_HANDLE); HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); system ("CLS"); gotoxy (hOut, Coord_x + Width + 5, Coord_y-10); SetConsoleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_RED); cout <"game end"; gotoxy (hOut, Coord_x + Width + 5, Coord_y-7); cout <"Final score:" <G. score <endl; SetConsoleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); exit (0);} voi D Console: window () {HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); HANDLE handle = GetStdHandle (STD_OUTPUT_HANDLE); system ("title 2 0 4 8 by Tc "); system ("color 0C"); gotoxy (hOut, Coord_x + Width-2, Coord_y-13); cout <"******"; gotoxy (hOut, coord_x + Width-2, Coord_y-12); cout <"2 0 4 8"; gotoxy (hOut, Coord_x + Width-2, Coord_y-11 ); cout <"********"; gotoxy (hOut, Coord_x + 2 * Width + 3, Coord_y + 6); SetCons OleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); gotoxy (hOut, Coord_x + 2 * Width + 3 + 2, Coord_y-8); cout <"w key: up "<" s key: Down "; gotoxy (hOut, Coord_x + 2 * Width + 3 + 2, Coord_y-6); cout <" a key: to the left "<" d key: Right "; gotoxy (hOut, Coord_x + 2 * Width + 3 + 2, Coord_y-4); cout <" Esc: exit ";} void Console: show () {HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE); HANDLE handle = G EtStdHandle (STD_OUTPUT_HANDLE); SetConsoleTextAttribute (handle, handle | FOREGROUND_GREEN | FOREGROUND_RED); gotoxy (hOut, Coord_x + 2 * Width + 3 + 2, Coord_y-10 ); cout <"; gotoxy (hOut, Coord_x + 2 * Width + 3 + 2, Coord_y-10); cout <" score: "<G. score; for (int I = 0; I <4; I ++) {for (int j = 0; j <4; j ++) {if (G. num [I] [j]! = 0) {cout <"; SetConsoleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_RED); gotoxy (hOut, Coord_x + 6 + j * 8, Coord_x-8 + I * 4 ); cout <G. num [I] [j];} else {cout <""; SetConsoleTextAttribute (handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN); gotoxy (hOut, Coord_x + 6 + j * 8, coord_x-8 + I * 4); cout <"■" ;}} cout <endl ;}} bool Game: control (char dir) {int num2 [4] [4]; for (I Nt n = 0; n <4; n ++) for (int m = 0; m <4; m ++) num2 [n] [m] = num [n] [m]; bool IsMove = false; if (dir = 'W' | dir = 'W ') {for (int j = 0; j <4; j ++) {int ii = 0, temp = 5; for (int I = 0; I <4; I ++) {if (num [I] [j] = 0) continue; else {temp = I; break ;}} if (temp = 5) continue; num [ii] [j] = num [temp] [j]; for (int I = temp + 1; I <4; I ++) {if (num [I] [j] = 0) continue; else if (num [I] [j]! = 0 & num [I] [j] = num [ii] [j]) {num [ii] [j] * = 2; G. score + = num [ii] [j]; num [I] [j] = 0;} else if (num [I] [j]! = 0 & num [I] [j]! = Num [ii] [j]) num [++ ii] [j] = num [I] [j];} while (ii <4) num [++ ii] [j] = 0; for (int n = 0; n <4; n ++) {for (int m = 0; m <4; m ++) {if (num2 [n] [m]! = Num [n] [m]) {IsMove = true; break ;}} if (IsMove) break ;}} return IsMove ;} else if (dir = 's' | dir = 's') {for (int j = 0; j <4; j ++) {int ii = 3, temp = 5; for (int I = 3; I> = 0; I --) {if (num [I] [j] = 0) continue; else {temp = I; break;} if (temp = 5) continue; num [ii] [j] = num [temp] [j]; for (int I = temp-1; I> = 0; I --) {if (num [I] [j] = 0) continue; else if (num [I] [j]! = 0 & num [I] [j] = num [ii] [j]) {num [ii] [j] * = 2; G. score + = num [ii] [j]; num [I] [j] = 0;} else if (num [I] [j]! = 0 & num [I] [j]! = Num [ii] [j]) num [-- ii] [j] = num [I] [j];} while (ii> = 0) num [-- ii] [j] = 0; for (int n = 0; n <4; n ++) {for (int m = 0; m <4; m ++) {if (num2 [n] [m]! = Num [n] [m]) {IsMove = true; break ;}} if (IsMove) break ;}} return IsMove ;} else if (dir = 'A' | dir = 'A') {for (int I = 0; I <4; I ++) {int jj = 0, temp = 5; for (int j = 0; j <4; j ++) {if (num [I] [j] = 0) continue; else {temp = j; break;} if (temp = 5) continue; num [I] [jj] = num [I] [temp]; for (int j = temp + 1; j <4; j ++) {if (num [I] [j] = 0) continue; else if (num [I] [j]! = 0 & num [I] [j] = num [I] [jj]) {num [I] [jj] * = 2; G. score + = num [I] [jj]; num [I] [j] = 0;} else if (num [I] [j]! = 0 & num [I] [j]! = Num [I] [jj]) {num [I] [++ jj] = num [I] [j] ;}} while (jj <4) {num [I] [++ jj] = 0 ;}for (int n = 0; n <4; n ++) {for (int m = 0; m <4; m ++) {if (num2 [n] [m]! = Num [n] [m]) {IsMove = true; break ;}} if (IsMove) break ;}} return IsMove ;} else if (dir = 'D' | dir = 'D') {for (int I = 0; I <4; I ++) {int jj = 3, temp = 5; for (int j = 3; j> = 0; j --) {if (num [I] [j] = 0) continue; else {temp = j; break;} if (temp = 5) continue; num [I] [jj] = num [I] [temp]; for (int j = temp-1; j> = 0 & jj> 0; j --) {if (num [I] [j] = 0) continue; else if (num [I] [j]! = 0 & num [I] [j] = num [I] [jj]) {num [I] [jj] * = 2; G. score + = num [I] [jj]; num [I] [j] = 0;} else if (num [I] [j]! = 0 & num [I] [j]! = Num [I] [jj]) num [I] [-- jj] = num [I] [j];} while (jj> 0) num [I] [-- jj] = 0; for (int n = 0; n <4; n ++) {for (int m = 0; m <4; m ++) {if (num2 [n] [m]! = Num [n] [m]) {IsMove = true; break ;}} if (IsMove) break ;}} return IsMove ;}return false ;} void Game :: init () {srand (unsigned int) time (NULL); int x = rand () % 4; int y = rand () % 4; G. num [x] [y] = 2; int xx = rand () % 4; int yy = rand () % 4; while (1) {if (xx! = X & yy! = Y) {G. num [xx] [yy] = 2; break;} xx = rand () % 4; yy = rand () % 4 ;}} void Game: make () {int count = 0; for (int I = 0; I <4; I ++) {for (int j = 0; j <4; j ++) {if (num [I] [j]) count ++ ;}} if (count = 16) C. end_game (); int xx = rand () % 4; int yy = rand () % 4; while (1) {if (num [xx] [yy] = 0) {num [xx] [yy] = 2; break;} xx = rand () % 4; yy = rand () % 4 ;}} void Console: start_game () {G. init (); window (); show (); char dir; while (true) {bool flag = false; dir = getch (); if (dir = 27) end_game (); if (dir = 'W' | dir = 'A' | dir = 'S' | dir = 's' | dir = 'D ') {flag = G. control (dir); window (); if (flag) G. make (); show () ;}} int main () {C. enter_game ();}



Cg_invalidCmdHintBlinkInterval find him and change the following number to 2048 (the original parameter is 600 ).

About cod7 ..
Your mission 7 folder .. Find the players folder, right-click config. cfg, open it in notepad, and search cg_invalidCmdHintBlinkInterval ..... Next there is a value. Just change it.

Okay, it's all nonsense .. That is the old method that didn't optimize the patch before.
Go directly to 3DM to find the Mission 7 optimization patch. I will give you the link HI. I cannot send it here. Du Niang will eat the link.
However, you must ensure that the 3DM Chinese version is the star henghua version of youxia .. The patch is invalid.

If it doesn't work, you can give me a message. I usually spend hundreds of times at night... Try to answer...

Use the PING command to write a PING 1011018 host PING packet value of 2048, PING 5 times

Ping 10.1.10.18-l 2048-n 5
Ping Parameters
Ping [-t] [-a] [-n count] [-l length] [-f] [-I ttl] [-v tos] [-r count] [- s count] [[-j computer-list] | [-k computer-list] [-w timeout]

[Parameter description]
-T: ping the specified computer without stopping until Ctrl + C is pressed.

-A: Resolve the address to the computer NetBios name.

-N: Number of ECHO data packets specified by count. You can use this command to define the number of sent messages, which is helpful for measuring the network speed. Test the average return time of the sent data packet and the speed of the time. The default value is 4.

-L: Send the ECHO data packet of the specified data volume. The default value is 32 bytes. The maximum value is 65500byt.

-F: the packet will not be segmented by the gateway on the route when the "Do Not segment" flag is sent in the packet. Generally, the packets you send will be sent to the other party through the route segment. After this parameter is added, the route will not be processed in segments.

-I: Set the "survival time" field to the value specified by TTL. Specifies the time when the TTL value stays in the target system. Check the network running status at the same time.

-V: tos sets the "service type" field to the value specified by tos.

-R: records the routes of outgoing and returned data packets in the "Record Route" field. Generally, the sent data packet arrives at the target address through a series of routes. You can set this parameter to detect the number of routes. Only nine routes can be tracked.

-S: Specifies the timestamp of the number of hops specified by count. Similar to the-r parameter, but this parameter does not record the route through which data packets are returned. A maximum of four routes can be recorded.

-J: Route data packets using the computer list specified by computer-list. The maximum number of consecutive computers that can be separated by the Intermediate Gateway (routing sparse source) IP addresses is 9.

-K: The computer-list uses the computer list specified by the computer-list to route data packets. The maximum number of IP addresses allowed by consecutive computers to be separated by intermediate gateways (strictly source routes) is 9.

-W: Specifies the timeout interval in milliseconds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.