#Linux中的GCC规划# Lottery system

c

Lottery Management System

1. Function introduction

Three identities: ordinary user, notary, and administrator.

  • Ordinary users: register, log in, recharge, buy lottery tickets, etc.
  1. Register: Enter account number, check duplicates, enter password. This information is stored in the linked list and written to a local file.
  2. Login: Enter the account number, password, and the password must be covered with "*". Need to enter the verification code.
  3. View personal information: After logging in, come to the secondary page. Users can view their own information (number, user name, password, balance).
  4. Modify password: The new password cannot be consistent with the old password, otherwise it will prompt a modification error.
  5. Account recharge: Enter the amount to recharge and confirm.
  6. Purchase lottery tickets: There are lottery tickets being issued in the periodical withdrawal, otherwise you cannot purchase them; the lottery tickets are issued by the administrator. Users can randomly generate lottery numbers or fill in by hand.
  7. View history: users can own their past purchase records. Find the node you purchased from the lottery list.
  • Notary:
  1. The account and password are fixed as: notery
  2. When logging in, you need to hide your password and ask for a verification code.
  3. Draw: After logging in, (provided that there is already a lottery ticket being issued) draw. And determines. Randomly generate several numbers as the winning numbers.
  4. After the draw is over, the notary can decide whether to issue the bonus immediately.
  5. Notaries can play games in their spare time. So far, only "Rock Paper Scissors" has been completed. There are also "Snake Snake" and "Tank Battle" to be developed.
  • administrator:
  1. Can view the information of all users.
  2. You can query the information of a single user.
  3. Lottery tickets are issued, and the lottery number is automatically generated based on the date and time. The unit price of the lottery must be set by the administrator.
  4. You can sort the user list (according to name or ID) and save it.
  5. Bonuses are issued. Under the lottery lottery number currently being issued, it is determined that a user has purchased it, and the notary will draw the lottery. According to the user's lottery number, the prize is taken out of the prize pool and distributed to the winning user.
  6. Manually add money to the prize pool.
  7. delete users. The administrator can delete a user.
  8. View all purchase information. From the lottery list, all lottery information is displayed.

The interactive interface involves:

This project adopts MVC architecture design, namely module, interface, and control.

In src/lotview.c, use system("clear"); and printf(); to refresh the screen continuously to achieve a dynamic interactive effect.

In src/lotcontrol.c, the control logic of each interface is constituted by switch and case.
One of the more core functions is: choose=key_udrl(choose,4,3); this function is the core of interactive dynamic effects. Modify the choose value through the up, down, left, and right buttons and numbers on the keyboard to enter the corresponding logic. And dynamically refresh in lotview.c.

Technical Difficulties:

  • The database is not used, but a linked list is created and saved to a local file.
  • In the process of using the linked list, the application and release of dynamic memory are involved.
  • For the first time in life, I began to realize the terrible segfault and the good habit of preventing segfaults.

2. Code

Project code download address: https://github.com/Kshine2017/My_GCC/tree/master/lottery_Kshine201708

The project directory is as follows:

root@kshine-virtual-machine:/home/kshine/桌面/lottery_Kshine201708# tree
.
├── bin
│   └── main
├── common.bin
├── include
│   ├── freelink.h
│   ├── fun.h
│   ├── gamejsb.h
│   ├── loadsave.h
│   ├── lotcontrol.h
│   ├── lottery.h
│   ├── lotview.h
│   ├── pic.h
│   └── udrl.h
├── iss.bin
├── makefile
├── obj
│   ├── freelink.o
│   ├── fun.o
│   ├── gamejsd.o
│   ├── loadsave.o
│   ├── lotcontrol.o
│   ├── lottery.o
│   ├── lotview.o
│   ├── main.o
│   ├── pic.o
│   └── udrl.o
├── src
│   ├── freelink.c
│   ├── fun.c
│   ├── gamejsd.c
│   ├── loadsave.c
│   ├── lotcontrol.c
│   ├── lottery.c
│   ├── lotview.c
│   ├── main.c
│   ├── pic.c
│   ├── udrl.c
│   └── 锛_
├── tic.bin
└── user.bin

Pick up a few files or functions and do a simple display analysis:

  1. udrl.c (up down right left)
#include <stdio.h>
#include <stdlib.h>
#include "lotview.h"
int key_udrl(int choose,int menu_num,int mode)
{
 	printf("\n\033[47;31m\t\t\t敲击Enter继续!\033[0m\n");
 	getchar();
while (1)
{
	char c =0;
	if(mode==1)
  	{
   		V_main_menu_move(choose);
  	}
  	else if(mode==2)
  	{
  		 V_game_move(choose);
 	 }
	 else if(mode==3)
 	 {
   		V_other_move(choose);
  	}
	else if(mode==4)
  	{
   		V_sort_move(choose);
  	}
 	 else if(mode==5)
  	{
  	 V_admin_menu_move(choose);
 	 }
 	 else if(mode==6)
 	 {
   		V_user_menu_move(choose);
 	 }
 	 else if(mode==7)
 	 {
  		 V_notery_menu_move(choose);
  	}
	while(1) //自动清掉奇怪的符号
  	{
  		 system("stty -icanon");//关闭缓冲区,输入字符无需回车直接接受
                    c=getchar();  
   		if(c=='\n')
   		{
    		 	return choose;
 	 	}
                 if((c>='a'&&c<='z')&& (c>='A'&&c<='Z') && (c>='9'&&c<='0')) 
  		{
    			printf("\b");
    			continue;
   		}
   		else  //是字母或者数字
  		 {
    			break;
   		}
       }
	//得到上下左右或者字母数字 
       	 if(c<='9'&&c>='0')//返回数值,直接控制
   	 {
  	 	choose = (int)(c-'0');//不要急着返回
    	}
  	else
  	{
   		if(c=='A')//up
   		{
    			choose--;
   		}
   		if(c=='B')//down
   		{
    			choose++;
   		}
   		if(c=='D')//left
   		{
    			choose=0;
   		}
  		if(c=='C')//right
   		{
   	 		//进入当前的choose菜单
    			break;
   		}
 	}
	//--------------------
  	if(choose<0)
  	{
   		choose += menu_num;
  	}
 	 if(choose>menu_num-1)
  	{
   		choose -=(menu_num); 
 	 }
 	 //-----动态显示
  	//V_main_menu_move(choose);
  	//----
    }
 	return choose;
 }

In the fun.c file

  1. //Block the input value
char* secret_num(char* str)
{
 	char ch=0;
        int i=0;
        getchar();
        while(1)
        {
                system("stty -icanon");//关闭缓冲区,输入字符无需回车直接接受
	      ch=getchar();
                printf("\b@");
                if(ch=='\n')
	      {
                        break;
                }
        str[i++]=ch;
        }
        str[i]='\0';
        return str;
}
  1. //Verification code

int identifying_code()
{
 	char array[100]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"};
 	char a[5]="";
 	char b[5]="";
	srand(time(NULL));
 	a[0]=array[rand()%62];
 	a[1]=array[rand()%62];
 	a[2]=array[rand()%62];
 	a[3]=array[rand()%62];
	printf("验证码是:");
 	printf("\033[42;31m%s\033[0m\n",a);
 	printf("请输入您的验证码:");
 	scanf("%s",b);
 	if(strcmp(a,b)==0)
 	{
  		printf("验证成功!\n");
  		return 0;
	 }
	 else
 	{
  		printf("验证失败!");
  		return 1;
	 }
 	return 0;
}

3. Compile and run

The makefile is written in the project, and the user can directly enter make or make clean.

CC:=gcc
DEPEND:=obj/main.o
DEPEND+=obj/lotcontrol.o
DEPEND+=obj/fun.o
DEPEND+=obj/udrl.o
DEPEND+=obj/lotview.o
DEPEND+=obj/loadsave.o
DEPEND+=obj/freelink.o
DEPEND+=obj/pic.o
DEPEND+=obj/lottery.o
DEPEND+=obj/gamejsd.o
bin/main:$(DEPEND)
 $(CC)    $^ -o $@
obj/%.o:src/%.c
 $(CC) -c $^ -o $@ -Iinclude
clean:
 rm -rf obj/$(DEPEND)
 rm -rf src/*.c~

4. Run display

Welcome Screen:

Welcome Screen

Main interface:
Main interface

User login:
User login

User Interface
User Interface

User-view history
Users view historical purchase records

Notary interface:
Notary interface

Administrator interface:
Administrator interface

Administrator-user sort:
Admin user sort

Other information interface:
Other information main interface

The basic information is text information. The icon is the boot screen. The QR code is the image of the QR code that I was bored and converted the URL of an organization into. (Users can convert pictures into arrays according to their own needs, and then replace them here). Because the terminal uses a single character to represent a pixel, and in order to prevent the pattern from being out of shape, the image is very large. This is also one of the disadvantages of terminal display. Let's show the displayed QR code.
QR code

There are also some functions that you need to discover and improve by yourself.

Guess you like

Origin blog.csdn.net/Kshine2017/article/details/85280331